如何更改组合框控件中的下拉按钮? [英] How to change drop down button in combobox control?
问题描述
如何更改 ComboBox
控件(C#,Windows窗体)中的下拉按钮?我有一个自定义按钮,我想在 ComboBox
中使用它,而不是默认的下拉按钮。
我认为Hans Passant的解决方案就是......
从这里开始:
您可以创建一个UserControl,将一个
组合框和一个按钮拖到它上面,使
按钮位于组合框的
箭头按钮上,以使箭头按钮
不可见,处理Button的Paint
事件以在其上绘制箭头,这可以通过调用
ComboBoxRenderer.DrawDropDownButton()
方法完成(注意:此方法具有
限制,它需要在操作系统上启用
的视觉样式)或绘制一个n
图标就可以了,或者在它上面画一个小
的三角形。
然后处理按钮的Click事件以显示ComboBox的
DropDown,这可以通过
来完成。
private void button1_Click(object sender,EventArgs e)
{
this.comboBox1.DroppedDown = true;
}
How to change dropdown button in a ComboBox
control (C#, Windows Forms)? I have a custom button, and I want to use it in the ComboBox
instead of the default dropdown button.
I think Hans Passant solution is the way...
From here:
You can create a UserControl, drag a ComboBox and a Button onto it, make the Button right over the ComboBox's arrow button to make the arrow button invisible, handle the Button's Paint event to draw an arrow on it, this can be done by calling ComboBoxRenderer.DrawDropDownButton() method (Notice: this method has a limit, it needs the visual style being enabled on the OS) or by drawing an icon on it, or just drawing a small triangle on it. Then handle the Click event of the button to show the ComboBox's DropDown, this can be done by something like this
private void button1_Click(object sender, EventArgs e)
{
this.comboBox1.DroppedDown = true;
}
这篇关于如何更改组合框控件中的下拉按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!