Click here to Skip to main content
11,631,992 members (69,248 online)
Click here to Skip to main content

IP TextBox

, 8 Sep 2005 99.3K 9.8K 46
Rate this:
Please Sign up or sign in to vote.
An IP textbox control that mimics ip boxes in windows network settings

Introduction

This simple IP address textbox replaces the lack of an IP box in Windows Forms control. Using the DLL you can just add the control to your toolbox and its use is very similar to a regular TextBox control.

Background (optional)

While writing an application for some end-users, i had the need for a textbox that only took an ip address and performed some validation to make sure the text entered was actually an IP. Since there was nothing readily availible that did what I wanted, I wrote a control that can easily be added to any .NET Windows Form.

Using the code

Using this control is very easy. Just right-click somewhere in your toolbox, then click "Add/Remove Items...". Now browse to the DLL, click OK and the control should now be in your toolbox. The control inherits the standard TextBox in Windows.Forms and overrides the Text property so that you can programmatically set or get the Text value as a string; I also added a method IsValid() which returns true if the Text property falls in the parameters of an actual IP address and false otherwise;

Points of Interest

The control is actually 4 TextBoxs and 3 Labels with "." placed at the appropriate locations. Most validation is done on KeyPress and currently a MessageBox pops up to alert the user of Invalid inputs such as numbers less than 0 or greater than 255.

History

No history yet, but thinking of being able to turn off the MessageBox warnings. There also is no validation when setting the Text programmatically and an unhandled exception is thrown.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

mawnkay
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 2 Pin
i0018-Jan-12 12:47
memberi0018-Jan-12 12:47 
GeneralMy vote of 5 Pin
DonaldKnuth29-Oct-11 22:45
memberDonaldKnuth29-Oct-11 22:45 
GeneralNeed Pin
Hardikasd25-Feb-10 1:23
memberHardikasd25-Feb-10 1:23 
GeneralNice Pin
Member 33287121-Dec-09 0:59
memberMember 33287121-Dec-09 0:59 
GeneralNew code update Pin
sysx19-Nov-09 7:33
membersysx19-Nov-09 7:33 
QuestionRegarding IP textbox Pin
rajionline20-Sep-07 17:55
memberrajionline20-Sep-07 17:55 
GeneralCheck IP Textbox if it's filled with a ip address Pin
Luneto_HA20-Mar-07 3:38
memberLuneto_HA20-Mar-07 3:38 
GeneralRe: Check IP Textbox if it's filled with a ip address Pin
avramik14-Jun-10 20:20
memberavramik14-Jun-10 20:20 
GeneralDataBinding Pin
joelthegeek1-Dec-05 5:31
memberjoelthegeek1-Dec-05 5:31 
GeneralMovement needs to be a little better Pin
luniv04048-Nov-05 9:26
memberluniv04048-Nov-05 9:26 
GeneralRe: Movement needs to be a little better Pin
joelthegeek1-Dec-05 3:32
memberjoelthegeek1-Dec-05 3:32 
GeneralNice Control ! A little question :doh: Pin
FredyAlfredo20-Sep-05 2:25
memberFredyAlfredo20-Sep-05 2:25 
GeneralRe: Nice Control ! A little question :doh: Pin
mawnkay27-Sep-05 4:16
membermawnkay27-Sep-05 4:16 
AnswerRe: Nice Control ! A little question :doh: Pin
mawnkay4-Oct-05 4:44
membermawnkay4-Oct-05 4:44 
GeneralLittle changes Pin
MansonP15-Sep-05 2:48
memberMansonP15-Sep-05 2:48 
I want to say you did a gr8 job with this control. I only modified 2 little things before including it in my custom control library.

You need to add this to allow navigation between the textboxes with the arrow keys on the keyboard


private void Box1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
this.Box2.Focus();
}

private void Box2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
this.Box3.Focus();
if (e.KeyCode == Keys.Left)
this.Box1.Focus();
}

private void Box3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
this.Box4.Focus();
if (e.KeyCode == Keys.Left)
this.Box2.Focus();
}

private void Box4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
this.Box3.Focus();
}


And I added the Browsable attribute to the Text property to make it available on the property grid


[Browsable(true)]
public override string Text

GeneralRe: Little changes Pin
mawnkay27-Sep-05 4:21
membermawnkay27-Sep-05 4:21 
GeneralRe: Little changes Pin
pinquotriot19-Mar-09 12:27
memberpinquotriot19-Mar-09 12:27 
General2 comments: Pin
<span style='color:#6699cc; '>MadHatter ¢</span>8-Sep-05 9:33
memberMadHatter ¢8-Sep-05 9:33 
GeneralRe: 2 comments: Pin
malharone8-Sep-05 15:23
membermalharone8-Sep-05 15:23 
GeneralRe: 2 comments: Pin
<span style='color:#6699cc; '>MadHatter ¢</span>8-Sep-05 17:25
memberMadHatter ¢8-Sep-05 17:25 
GeneralRe: 2 comments: Pin
mawnkay9-Sep-05 4:41
membermawnkay9-Sep-05 4:41 
GeneralRe: 2 comments: Pin
<span style='color:#6699cc; '>MadHatter ¢</span>9-Sep-05 7:33
memberMadHatter ¢9-Sep-05 7:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150728.1 | Last Updated 8 Sep 2005
Article Copyright 2005 by mawnkay
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid