[TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - 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: [TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) (/showthread.php?tid=12438) |
[TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - Resistance - 10-03-2010 Hello guys, today I will be showing you a tutorial on how to restrict textbox input, which is very useful for many things such as numeric only textboxes, textboxes for your email with the @ sign, much much more. You may not know now, but when you need it for future reference your going to be saying "Thank L3g1tWa5te!" in your head... LOL... Now for the code and procedure. Steps: 1) Enter the following code on the top of the form. Code: Public Class Form1 2) Now for TextBox1_TextChanged event code: Code: Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Your done. Now your textbox allows every kind of character thats not in the string "charactersDisallowed", as you can tell numbers are the only type of input allowed. Now to make it so the textbox can only have certain characters, so the only characters that are allowed are in the string. 1) Now the same thing as before, enter the following code on the top/beginning of the form. Code: Public Class Form1 2) Now for TextBox2_TextChanged event code: Code: Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged Thats it. Now the TextBox only allows the characters in the string, everything else is blocked for the text boxes' input. RE: [TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - AceInfinity - 10-03-2010 From a quick glance this tutorial looks great. Good quality share Another thing to note which is to do with textbox characters is that you can set a text box to an option of hiding the characters if you want a login page or just something where you want to hide the input as you type it in. The option can be found in the property list for the textbox itself. RE: [TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - Resistance - 10-03-2010 (10-03-2010, 09:59 PM)Infinity Wrote: From a quick glance this tutorial looks great. Good quality share Ahhh yes! That would be set into the PasswordChar = "*" or that bullet point thing character. RE: [TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - Fragma - 10-05-2010 Good tutorial. Thanks very much for sharing. RE: [TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - Sιℓνєя - 10-05-2010 Thanks a lot what a awesome tut :O, keep up good work man. RE: [TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - Kink - 10-16-2010 Nice tutorial, thanks for sharing. RE: [TuToRiAl] Restricting TextBox Input (Numeric Only TextBox, etc...) - KoBE - 11-10-2010 Not trying to discredit you, Im just sharing some knowledge. A better way to do something like this (instead of looping through the text each time) would be this. not allowed Code: Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress allowed Code: Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress |