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. WPF組合框禁用背景顏色
- 4. Telerik的組合框 - 改變顏色
- 5. WPF組合框顏色綁定問題
- 6. LWUIT組合框文本顏色問題
- 7. 顏色選擇器組合框
- 8. WPF xaml綁定組合框背景顏色爲SelectedItem的顏色
- 9. 顏色框閉合確認
- 10. 設置顏色SWT組合
- 11. 多少顏色組合
- 12. Web 2.0顏色組合
- 13. C++複選框顏色
- 14. 更改WPF組合框的邊框顏色
- 15. 如何在WPF中點擊組合框(組合框打開)時更改組合框背景顏色?
- 16. 使用組合框中的系統顏色更改文本顏色
- 17. C#WPF - 突出顯示文本顏色問題的組合框突出顯示
- 18. C#WPF如何修改組合框的選定項目的顏色?
- 19. 如何更改WPF組合框中選定文本的顏色?
- 20. 在WP8.1中顯示組合框的PlaceholderText顏色
- 21. 爲組合框中的列表項懸停的字體顏色
- 22. 如何更改組合框的背景顏色
- 23. 將django組合框選項設置爲顏色?
- 24. WPF設置組合框的顏色向下箭頭按鈕
- 25. 每個選定項目的JavaFX組合框背景顏色
- 26. 組合框選定的值預先指定顏色XAML WPF
- 27. 在.NET Windows應用程序的組合框中添加顏色
- 28. QCombobox編輯部分組合框的背景顏色
- 29. Flex下拉式組合框所選背景顏色?
- 30. 更改MFC中組合框的項目背景顏色?
而且相關:http://stackoverflow.com/questions/91747/background-color-of-a-listbox-item-winforms/3709452 – 2011-03-06 10:53:49