How to make a CheckBox unselectable?

后端 未结 10 2164
慢半拍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:44

    You can set the Enabled property to false:

    checkBox1.Enabled = false;
    
    0 讨论(0)
  • 2021-01-07 16:46

    In response to some comments about grayed out label: Set the Text of the CheckBox to the empty string, Enableto false and use a Label for the text.

    Drawback: No mnemonic support out of the box.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-07 16:51

    Leverage a simple Label using a glyph like this for its Text: ✔ checkBox1.

    0 讨论(0)
  • 2021-01-07 16:58

    AutoCheck doesn't exist in UWP but I think you can use IsTapEnabled = false.

    0 讨论(0)
  • 2021-01-07 17:00

    You can set the Enabled property to false

    0 讨论(0)
提交回复
热议问题