问题描述
我阅读了此主题 http://technicalsol.blogspot.带有comboBox的com/2009/03/combobox-set-font-style.html ,但在toolstripComboBox中不存在事件draw_item我需要你的帮助.我正在用C#编写简单的写字板.
I read this topic http://technicalsol.blogspot.com/2009/03/combobox-set-font-style.html with comboBox but in toolstripComboBox not exist event draw_itemI need your help. I am writing simple wordpad by C#.
推荐答案
这是因为ToolStripComboBox派生自ToolStripControlHost,而不是ComboBox.您需要使用其Control属性进入组合框.像这样:
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.
这篇关于toolStripComboBox设置字体样式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!