I made this user control to mimic the IP textbox in the Windows TCP/IP settings. It's different than a masked box or just straight custom validation, in that it is actually 4 textboxes that look like 1 textbox.
If you check the TCP/IP settings in Windows, you will see that this is how their box behaves. It works pretty well. Please let me know any comments/suggestions.
Attached is the full source code, and a sample project showing it in action. Since I did not include any compiled code, you need to build the project before you view form1.
From your project just select "Add existing item" and find the IPTextBox.vb file from my project. Once you add it to your project, build your project and the control will appear in your toolbox.
Firstly Great stuff!! I tried to create a IP masked textbox in VB2005 using 099.099.099.099 but this didn't quite give me the result I was looking for.
Couple of suggestions for this but it could be what you mean by user controls.
1, When a . is pressed it moves to the next box or a backspace on the last char in a box moves you to the last box
2, Copy and paste function - ability to copy the content or paste content in
If you could point me in the right direction that would be much appreciated
Thanks
Last edited by Robbrad182; Dec 20th, 2006 at 04:41 AM.
Private Sub txtIP_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtIP1.KeyPress, txtIP2.KeyPress, txtIP3.KeyPress, txtIP4.KeyPress
Dim txtBox As TextBox = DirectCast(sender, TextBox)
'ONLY ALLOW CONTROL CHARS (LIKE BACKSPACE) AND NUMBERS TO BE ENTERED
Select Case Char.GetUnicodeCategory(e.KeyChar)
Case Globalization.UnicodeCategory.Control, Globalization.UnicodeCategory.DecimalDigitNumber
Since the user control was build to behave like the windows IP entry box, it is actually made up of 4 textboxes. So you can't copy/paste an entire IP. (you could, but you would have to write more code to look at a paste, see if its a full valid IP, and then fill in each of the 4 textboxes)
Why not make it so that you cannot enter 0 0 0 0 or 255 255 255 255 which an IP address cannot be. ¿
Actually in Windows when it's obtaining an ip address or you use 'IpConfig /Release' The system's IP is '0.0.0.0' and 255.255.255.255 is a valid ip, it's just not one you see
Currently using VS 2015 Enterprise on Win10 Enterprise x64.
I have added this sub as a new private sub, so every time you type Enter the current textbox transfers you to the next one.
vb Code:
Private Sub txtIP_KeyDown(ByVal sender As System.Object, ByVal e As KeyEventArgs) Handles txtIP1.KeyDown, txtIP2.KeyDown, txtIP3.KeyDown, txtIP4.KeyDown
Dim txtBox As TextBox = DirectCast(sender, TextBox)
Just stopping in to say i like the custom control!
I know this is an old thread, but i was wondering how can you change the default values on this, i would like to see all blanks instead of 255.255.255.255