1

I read this topic http://technicalsol.blogspot.com/2009/03/combobox-set-font-style.html with comboBox but in toolstripComboBox not exist event draw_item I need your help. I am writing simple wordpad by C#.

giaosudau
  • 2,211
  • 6
  • 33
  • 64
  • there is DrawItem http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.drawitem.aspx , if you are using WinForms – Stecya Mar 01 '11 at 13:23

1 Answers1

6

This is because ToolStripComboBox derives from ToolStripControlHost, not ComboBox. You need to use its Control property to get to the combo box. Like this:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        ComboBox box = (ComboBox)toolStripComboBox1.Control;
        box.DrawMode = DrawMode.OwnerDrawVariable;
        box.MeasureItem += new MeasureItemEventHandler(box_MeasureItem);
        box.DrawItem += new DrawItemEventHandler(box_DrawItem);
    }

    void box_DrawItem(object sender, DrawItemEventArgs e) {
        // etc..
    }

    void box_MeasureItem(object sender, MeasureItemEventArgs e) {
        // etc..

    }
}

Fill in the event handlers with the code you need to measure and draw the font names in their own font style.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536