Cancel Key press event

后端 未结 7 2075
别那么骄傲
别那么骄傲 2021-01-05 07:37

How can I return the key?, mean if I want to allow only integer values in the textbox, how can I don\'t allow user to not enter non-integers, regarding, KeyPress

7条回答
  •  甜味超标
    2021-01-05 08:30

    You may use keypress event as below. use e.Handled to true to cancel user input

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar)) e.Handled = true;
        }
    

提交回复
热议问题