想改一下winform的组合框的背景和下拉箭头,没找到相关的接口,决定自己写一个,不就是几个框框和箭头按钮么。。。
好的,先新建一个用户控件类
public partial class myCombox : UserControl
{
}
然后我们在界面上,使用三个控件,分别是
label ——> combox的显示框
button ——> combox的下拉按钮
listbox ——> combox的下拉菜单
好的 我的就是这个样子
然后写逻辑就行了,主要就是按下拉按钮显示下拉菜单,和下拉菜单选择显示在显示框中
主要是两个事件:listbox的SelectedIndexChanged事件
和button的click事件
private void LB_Combox_Select_SelectedIndexChanged(object sender, EventArgs e)
{
if (LB_Combox_Select.SelectedIndex == 0)
{
Label_Combox_Text.Text = xxxx;
selectIndex = 0;
}
else
{
Label_Combox_Text.Text = xxxx;
selectIndex = 1;
}
}
private void Btn_Combox_Dropdown_Click(object sender, EventArgs e)
{
if (isDropDownShow == false)
{
LB_Combox_Select.Show();
isDropDownShow = true;
}
else
{
LB_Combox_Select.Hide();
isDropDownShow = false;
}
}
需要更多的逻辑的请自行添加,还是很方便的