65.9K
CodeProject is changing. Read more.
Home

IP TextBox

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.34/5 (18 votes)

Sep 8, 2005

1 min read

viewsIcon

144941

downloadIcon

14882

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.