Donot allow a space in a textBox

Satyapriyanayak
Posted by Satyapriyanayak under Windows Forms category on | Points: 40 | Views : 2159
In this Code Snippet we will know how to do not to allow a space in a textbox. 

Vb.net code

Public Class Form1

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = " " Then
e.Handled = True
End If
End Sub


End Class

C#.net code

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

Comments or Responses

Login to post response