Upper Case or Alphanumeric Data Entry from a textbox (KeyPress, EventHandler, IsLetter(), ToUpper()


This is an example to modify input from a textbox "on the fly", converting all lowercase letters to uppercase. Other modifications may easily be implemented.
    ' Forcing upper case on textbox input
    ' P. C. 2004-01-02
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        ' store character typed
        Dim ch As Char = e.KeyChar
        If ch.IsLetter(ch) Then  ' conversion if applicable
            TextBox1.SelectedText = ch.ToUpper(ch)
            ' Kill the entered character
            e.Handled = True
        End If
    End Sub

    ' Forcing Alphanumeric data entry on textbox input
    ' P.C. 2004-09-12
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
      ' store character typed
      Dim ch As Char = e.KeyChar
      If Not ch.IsLetter(ch) And Not ch.IsNumber(ch) Then
         ' Kill the entered character
         e.Handled = True
    End If
  End Sub