ComboBox の最初の項目を赤に設定したいので、次のコードを使用してこのタスクを実行します。
private void cbTreeViewFolder_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if (e.Index >= 0)
{
string text;
Brush brush;
MyClass file = ((MyClass)((ComboBox)sender).Items[e.Index]);
if (e.Index == 0)
{
text = file.Path;
brush = Brushes.Red;
}
else
{
text = file.Nome;
brush = Brushes.Black;
}
e.Graphics.DrawString(text, ((Control)sender).Font, brush, e.Bounds.X, e.Bounds.Y);
}
}
ComboBox をクリアするまで機能します。その場合、それを管理する方法がわからず、すべてのアイテムが ComboBox に残るためです。誰でも問題の解決策を知っていますか?