Editbox portion of ComboBox gets selected automatically

后端 未结 7 1256
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 02:49

I have a small problem that has been annoying me for some hours.

In my WinForms (.NET 3.5) application I create some ComboBoxes (DropDownStyle = DropDown) in a Table

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 03:23

    Wow. Thank you guys!

    Apparently this bug has persisted many years. I'm building a UserControl with .Net 4 (Visual Studio 2010). Here's is my slightlty modified version of bsneeze's code.

    Cheers

    using System.Windows.Forms;
    using System.Linq;
    
    public MyUserControlCtor()
    {
        InitializeComponent();
    
        foreach( Control ctrl in Controls)
        {
            ComboBox cb = ctrl as ComboBox;
            if (cb != null)
            {
                cb.Resize += (sender, e) =>
                {
                    if (!cb.Focused)
                        this.FCHZ_ComboBox.SelectionLength = 0;
                };
            }
        } 
    }
    

提交回复
热议问题