validating textbox in windows form applications

前端 未结 7 1766
北荒
北荒 2020-12-12 08:21

My scenario is:

Not allowing spaces at starting position of textbox after enter one or more characters text box allows spaces

Below not applicable to my sce

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 08:47

    You say option number one is not applicable. How about a version of option number one that uses the same event and similar code but inside a second IF statement. This keeps spaces from working unless there are other characters in the text box.

    if (textBox1.Text.Length == 0)
    {
     e.Handled = (e.KeyChar == (char)Keys.Space)) 
    }
    

提交回复
热议问题