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;
}