How to make combo box auto expand on mouse hover a

2019-06-08 11:26发布

This question already has an answer here:

I have a windows form. In that windows form i have a combo box. I have predefined items in the combo box as Add, Remove and Delete. I want to make the combo box auto expand on mouse hover. How can I do that? I noticed that auto expand code should be given in the mouse hover event of combo box. like this

     private void comboBox1_MouseHover(object sender, EventArgs e)
    {

    }  

but I don't know how to expand the combo box. Can anyone tell me how to do that?

Ok I got it done the expanding part

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

    }

but I want to close the combo box when I leave the mouse pointer from the combo box.. How to do that?

2条回答
forever°为你锁心
2楼-- · 2019-06-08 11:57

Use the DroppedDown Property and make it true,

 private void comboBox1_MouseHover(object sender, EventArgs e)
    {
      var box = sender as ComboBox ;
       box.DroppedDown = true;
    }  
查看更多
再贱就再见
3楼-- · 2019-06-08 11:57

comboBox1.DroppedDown = true;

This has already been answered here Open ComboBox DropDown programmatically [duplicate]

which was actually a duplicate of Winforms: how to open combobox properly?

查看更多
登录 后发表回答