พอดีลองโค้ดนี้แล้วมันไม่รู้จัก มันฟ้องว่า
Error 1 'object' does not contain a definition for 'Attributes' and no extension method 'Attributes' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
ครับ
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
this.comboBox1.DrawItem += comboBox1_DrawItem;
this.comboBox1.Items.Add("One");
this.comboBox1.Items.Add("Two");
this.comboBox1.Items.Add("Three");
this.comboBox1.Items.Add("Four");
this.comboBox1.Items.Add("Five");
{
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
// Draw the background
e.DrawBackground();
// Get the item text
string text = ((ComboBox)sender).Items[e.Index].ToString();
// Determine the forecolor based on whether or not the item is selected
Brush brush;
// compare date with your list.
brush = (text == "Two") ? Brushes.Red : brush = Brushes.Black;
// Draw the text
e.Graphics.DrawString(text, ((Control)sender).Font, brush, e.Bounds.X, e.Bounds.Y);
}