C#组合框颜色
回答
可以通过调用组合框的DRAWITEM实现你的目标,更多信息参见下面的方法。
private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
// Override this function to draw items in the Color comboBox
// Get the Graphics Object (aka. CDC or Device Context Object)
// passed via the DrawItemEventArgs parameter
Graphics g = e.Graphics ;
// Get the bounding rectangle of the item currently being painted
Rectangle r = e.Bounds ;
if (e.Index >= 0)
{
Rectangle rd = r;
r.X = r.Right ;
// Get the brush object, at the specifid index in the colorArray
SolidBrush b = (SolidBrush)colorArray[e.Index];
// Fill a portion of the rectangle with the selected brush
g.FillRectangle(b, rd);
// Draw the rectangle
e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 2), r);
if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
{
// if the item is not selected draw it with a different color
e.Graphics.FillRectangle(new SolidBrush(Color.White) , r);
e.DrawFocusRectangle();
}
else
{
// if the item is selected draw it with a different color
e.Graphics.FillRectangle(new SolidBrush(Color.LightBlue) , r);
e.DrawFocusRectangle();
}
}
}
我尝试使用DRAWITEM但它不是引发 – kusanagi 2011-03-06 10:42:05
@kusanagi:设置'ComboBox.DrawMode = OwnerDrawFixed或OwnerDrawVariable' – digEmAll 2011-03-06 10:45:37
@kusanagi:在DrawItem中,您必须为comboBox的每个项目绘制字符串,顺便说一下,您是否尝试过使用上述方法发送给您的?对不起,我忘了说, 请设置comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed – SharpUrBrain 2011-03-06 10:56:34
- 1. WPF组合框的颜色
- 2. 更改组合框边框颜色
- 3. 颜色组合
- 4. WPF组合框颜色绑定问题
- 5. 颜色选择器组合框
- 6. 将颜色载入组合框
- 7. WPF:多个前景颜色组合框
- 8. 组合框鼠标移过颜色
- 9. 颜色编码组合框的样式
- 10. LWUIT组合框文本颜色问题
- 11. WPF组合框禁用背景颜色
- 12. Telerik的组合框 - 改变颜色
- 13. jqwidgets组合框的颜色问题
- 14. WPF xaml绑定组合框背景颜色为SelectedItem的颜色
- 15. 组合框项目更改字体颜色C#WinForms
- 16. 将WPF组合框选定的项目颜色设置为组合框的颜色项目
- 17. 颜色框闭合确认
- 18. 边框颜色混合
- 19. 字体颜色的组合
- 20. Web 2.0颜色组合
- 21. 设置颜色SWT组合
- 22. 多少颜色组合
- 23. 改变组合框的背景色,根本不改变颜色
- 24. C++复选框颜色
- 25. 文本框和组合框不显示主题背景颜色
- 26. 更改WPF组合框的边框颜色
- 27. 如何在WPF中点击组合框(组合框打开)时更改组合框背景颜色?
- 28. 使用组合框中的系统颜色更改文本颜色
- 29. 从一种颜色生成颜色组合
- 30. C#WPF - 突出显示文本颜色问题的组合框突出显示
而且相关:http://stackoverflow.com/questions/91747/background-color-of-a-listbox-item-winforms/3709452 – 2011-03-06 10:53:49