How to create a winform with buttons that will never attract keyboard focus

后端 未结 4 1194
死守一世寂寞
死守一世寂寞 2020-12-21 07:07

I have a few textboxes on my winform. I have a few buttons on it too. Now when I am typing on one such textbox and clicks a button, then the input focus is lost from the tex

4条回答
  •  不知归路
    2020-12-21 07:35

    Create custom Button class with Focusable property, set Focusable to false

    public class ButtonEx : Button
    {
        [DefaultValue(true)]
        public bool Focusable
        {
            get { return GetStyle(ControlStyles.Selectable); }
            set { SetStyle(ControlStyles.Selectable, value); }
        }
    }
    

提交回复
热议问题