Support Forums
[Source] Allowed Characters in Textbox / Richtextbox - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [Source] Allowed Characters in Textbox / Richtextbox (/showthread.php?tid=18806)



[Source] Allowed Characters in Textbox / Richtextbox - euverve - 05-15-2011

The gui is derive from this forum. hehehe Yeye

[Image: oDCQl.png]

I just used simple codes and used in keypress event.
Full Codes:
Code:
Public Class Form1

    Private Sub RichTextBox1_KeyPress(ByVal sender As Object, _
                                      ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                                      Handles RichTextBox1.KeyPress

        If (e.KeyChar < "a" OrElse e.KeyChar > "z") AndAlso (e.KeyChar < "A" OrElse e.KeyChar > "Z") Then
            e.Handled = True
        End If
    End Sub

    Private Sub RichTextBox2_KeyPress(ByVal sender As Object, _
                                      ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                                      Handles RichTextBox2.KeyPress

        If e.KeyChar < "0" Or e.KeyChar > "9" Then
            e.Handled = True
        End If
    End Sub
End Class

Edit: Ooops I have a grammar error in the description.


RE: [Source] Allowed Characters in Textbox / Richtextbox - thanasis2028 - 05-16-2011

You also need to allow keys like backspace to be pressed. Don't forget that...Nice gui anyway Smile


RE: [Source] Allowed Characters in Textbox / Richtextbox - euverve - 05-17-2011

(05-16-2011, 05:26 AM)thanasis2028 Wrote: You also need to allow keys like backspace to be pressed. Don't forget that...Nice gui anyway Smile

Tested in Windows 7, backspace is working fine.