how can do bold some items of comboBox
-
Dear programmers is there any way that some item of combobox can be bold and remaining will be regular. if it is then plz tell me how.. thanks in advance.
sikandar
-
Dear programmers is there any way that some item of combobox can be bold and remaining will be regular. if it is then plz tell me how.. thanks in advance.
sikandar
You need to make it owner drawn and render the text yourself.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
You need to make it owner drawn and render the text yourself.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
thanks for response i don know how can i render the text can u plz give descpriction thanks
sikandar
-
thanks for response i don know how can i render the text can u plz give descpriction thanks
sikandar
Its quite easy to make an Owner Drawn control. Basically, you are telling a control that you will write the code to draw each item in a control. In the case of a combo box, each item is an item in the drop-down portion. To do it, follow these steps 1) Drag a combo box to your form 2) In the properties window change its
DrawMode
property to OwnerDrawnFixed 3) Change to the events and double click theDrawItem
event 4) Switch to code view and you should have thisprivate void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { }
5) Write your code in there, for example I used the following code to alternate bold and nomal itemsprivate void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if((e.Index%2)==0) { e.Graphics.DrawString(this.comboBox1.Items[e.Index].ToString(),e.Font,Brushes.Black,e.Bounds,StringFormat.GenericDefault); } else { Font boldFont = new Font(e.Font,FontStyle.Bold); e.Graphics.DrawString(this.comboBox1.Items[e.Index].ToString(),boldFont,Brushes.Black,e.Bounds,StringFormat.GenericDefault); } }