How can I allow only 0 or 1 to be entered in a TextBox?

后端 未结 3 1312
鱼传尺愫
鱼传尺愫 2021-01-12 08:56

How can I limit the TextBox control to only allow the values 0 and 1?

Thanks. And I have one more question: How can I disable put text from clipboard in my textbox c

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 09:21

    If you do want to show the numbers rather than a check or something but only want to allow 0 or 1 you could use a NumericUpDown control and set min to 0 max to 1 and step to 1.

    If you do actually need a textbox I'd use Filip's answer but I'd set the MaxLength of it to 1 to avoid having to worry about 00, 11 or 01 or similar values.

提交回复
热议问题