简体   繁体   English

如何更改组合框控件中的下拉按钮?

[英]How to change drop down button in combobox control?

How to change dropdown button in a ComboBox control (C#, Windows Forms)? 如何更改ComboBox控件(C#,Windows窗体)中的下拉按钮? I have a custom button, and I want to use it in the ComboBox instead of the default dropdown button. 我有一个自定义按钮,我想在ComboBox使用它而不是默认的下拉按钮。

I think Hans Passant solution is the way... 我认为Hans Passant解决方案是...

From here: 从这里:

http://social.msdn.microsoft.com/forums/en-US/winformsdesigner/thread/5d65f987-834c-465f-a944-622831d4cfb0 http://social.msdn.microsoft.com/forums/en-US/winformsdesigner/thread/5d65f987-834c-465f-a944-622831d4cfb0

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. 您可以创建一个UserControl,将一个ComboBox和一个Button拖到其上,使Button恰好位于ComboBox的箭头按钮上方,以使箭头按钮不可见,处理Button的Paint事件以在其上绘制箭头,这可以通过调用ComboBoxRenderer来完成。 .DrawDropDownButton()方法(注意:此方法有一个限制,它需要在OS上启用视觉样式)或在其上绘制图标,或仅在其上绘制一个小三角形。 Then handle the Click event of the button to show the ComboBox's DropDown, this can be done by something like this 然后处理按钮的Click事件以显示ComboBox的DropDown,这可以通过以下方式完成

    private void button1_Click(object sender, EventArgs e)
    {
        this.comboBox1.DroppedDown = true;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM