gpt4 book ai didi

c# - 手动绘制项目时 ComboBox 更改样式

转载 作者:行者123 更新时间:2023-11-30 13:02:05 25 4
gpt4 key购买 nike

我在这里遇到一个奇怪的问题,我的组合框正在将其样式从 DropDownList 更改为 DropDown 并且仅在视觉上。检查我的组合框的 DropDownStyle 属性显示其设置为 DropDownList

基本上这就是我正在做的:

void InitComponents()
{
ddlInterval.DrawMode = DrawMode.OwnerDrawFixed;
ddlInterval.DrawItem += new DrawItemEventHandler(DrawIntervalItems);
List<IntervalItem> backupIntervalsList = new List<IntervalItem>();
IntervalsList.Add(new IntervalItem(5, GetIntervalString(5)));
IntervalsList.Add(new IntervalItem(15, GetIntervalString(15)));
IntervalsList.Add(new IntervalItem(30, GetIntervalString(30)));
IntervalsList.Add(new IntervalItem(60, GetIntervalString(60)));
IntervalsList.Add(new IntervalItem(120, GetIntervalString(120)));
IntervalsList.Add(new IntervalItem(240, GetIntervalString(240)));
IntervalsList.Add(new IntervalItem(480, GetIntervalString(480)));
IntervalsList.Add(new IntervalItem(720, GetIntervalString(720)));
IntervalsList.Add(new IntervalItem(1440, GetIntervalString(1440)));
ddlInterval.DataSource = IntervalsList;
ddlInterval.DisplayMember = "Name";
ddlInterval.ValueMember = "Value";
}

void DrawIntervalItems(object sender, DrawItemEventArgs e)
{
if(_bDisableItems)
{
switch (e.Index)
{
case 5:
case 7:
case 8:
{
string s = ddlInterval.GetItemText(ddlInterval.Items[e.Index]);
e.DrawBackground();
e.Graphics.DrawString(s, ddlInterval.Font, Brushes.Black, e.Bounds);
}
break;
default:
{

string s = ddlInterval.GetItemText(ddlInterval.Items[e.Index]);
e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
e.Graphics.DrawString(s, ddlInterval.Font, Brushes.LightSlateGray, e.Bounds);
}
break;
}
}
}

这是一张显示我的两个组合框之间差异的图像。请注意,两者都将其 DropDownStyle 设置为 DropDownList,但只有底部的项目是手动绘制的:

Difference between comboboxes

有没有办法解决这个问题?

最佳答案

试试这段代码:

 ddlInterval.DrawMode = DrawMode.Normal;

代替:

 ddlInterval.DrawMode = DrawMode.OwnerDrawFixed;

关于c# - 手动绘制项目时 ComboBox 更改样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16414693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com