c# 中,如何将combobox中某一项置灰

解决方案 »

  1.   


    ComboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
    在DrawItem事件中自己画 private void ComboBox1_DrawItem(object sender, 
            System.Windows.Forms.DrawItemEventArgs e)
        {
     
            System.Drawing.Color animalColor = new System.Drawing.Color();
            if(e.Index=0)
            {
                    float size = 0;
                    FontFamily family = null;                animalColor = System.Drawing.Color.Gray;
                    size = 30;
                    animalColor = System.Drawing.Color.Gray;
                    family = FontFamily.GenericSansSerif;
                   
                    e.DrawBackground();                System.Drawing.Font myFont=new Font(family, size, FontStyle.Bold);                Rectangle rectangle = new Rectangle(2, e.Bounds.Top+2, 
                    e.Bounds.Height, e.Bounds.Height-4);
                   e.Graphics.FillRectangle(new SolidBrush(animalColor), rectangle);                e.Graphics.DrawString(animals[e.Index], myFont, System.Drawing.Brushes.Black, new RectangleF(e.Bounds.X+rectangle.Width, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));        e.DrawFocusRectangle();        }
        }