toolStripComboBox set font style?

三世轮回 提交于 2019-12-25 07:47:59

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5155049/toolstripcombobox-set-font-style

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!