如何更改组合框控件中的下拉按钮? [英] How to change drop down button in combobox control?

查看:172
本文介绍了如何更改组合框控件中的下拉按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 ComboBox 控件(C#,Windows窗体)中的下拉按钮?我有一个自定义按钮,我想在 ComboBox 中使用它,而不是默认的下拉按钮。

解决方案

我认为Hans Passant的解决方案就是......



从这里开始:

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


您可以创建一个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:

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. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆