且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更改组合框的背景颜色(不仅限于下拉列表部分)

更新时间:2023-10-19 23:04:10

This should get you started.

Change the combobox DrawMode property to OwnerDrawFixed, and handle the DrawItem event:

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    int index = e.Index >= 0 ? e.Index : 0;
    var brush = Brushes.Black;
    e.DrawBackground();
    e.Graphics.DrawString(comboBox1.Items[index].ToString(), e.Font, brush, e.Bounds, StringFormat.GenericDefault);
    e.DrawFocusRectangle();
}

The background color will be right but the style of the box will be flat, not the usual 3D style.

相关阅读

推荐文章