Search code examples
c#.nettoolstrip

toolStripComboBox set font style?


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#.


Solution

  • 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.