How to make a CheckBox unselectable?

后端 未结 10 2224
慢半拍i
慢半拍i 2021-01-07 16:34

I was wondering how you make a CheckBox unselectable in c#? I thought it would be something like SetSelectable (false) or something but I can\'t seem to see th

10条回答
  •  無奈伤痛
    2021-01-07 16:46

    You can create one by using following code

    public class ReadOnlyCheckBox : System.Windows.Forms.CheckBox
    {
            private bool readOnly;
    
            protected override void OnClick(EventArgs e)
            {
                    // pass the event up only if its not readlonly
                    if (!ReadOnly) base.OnClick(e);
            }
    
            public bool ReadOnly
            {
                    get { return readOnly; }
                    set { readOnly = value; }
            }
    }
    

    or also you can handle the checked change event and always set it back to value you want

提交回复
热议问题