想改一下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;
}
}
需要更多的邏輯的請自行添加,還是很方便的