Click here to Skip to main content
13,143,459 members (33,879 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 18 Aug 2008

Textbox Which Holds an IP Address - Take 2

, 18 Aug 2008
Rate this:
Please Sign up or sign in to vote.
This control mimics the standard IP address textbox you see in Windows. It has four sections, separated by a period, each of which contains numbers which are >= 0 and <= 255.


This is a control which represents a single IP address. It uses .NET 3.0, and is built with the Visual Studio 2008 IDE (if you want to open the .sln file).


Nothing too amazing, I just got sick of users always messing up when entering an IP address. I didn't see anything out there using the Masktextbox control that comes with .NET, so I thought I'd throw something together to help 'em out. I had attempted this before, and more people were interested than I thought would be. Hopefully, this (second) version is a little more stable...

Using the Code

This is extremely simple. Get and set the text as you normally would (pass it "" and you'll get the same thing back, even if it is displayed differently). Do this via the IP and Text properties. Otherwise, use it as you would normally use a control.

To add this to your project, either copy the source, or add a reference to the DLL. The namespace is SEG.Controls. If you're into it, you can add it to your toolbox in Visual Studio and just drag/drop it onto your form.

You can change the min/max for each octet by changing the OctetValueMIN and OctetValueMAX values. The only reason I can think of that you'd want to change this is if you are trying to get a mask vs. an IP...

Listen for the IP address changes via the IPAddressChanged event.

private void OnTextChanged(object sender, EventArgs e)
    TextBox tb = (sender as TextBox);

    if (sender is SEG.Controls.IPAddressControl)
        _config.Mail.SMTPServer = ipac.Text;

Also, if you right click, you get the option to resolve a hostname. This is useful since most users don't understand the concept of IP address, but do know computer names.

Points of Interest

Might be nice to put in an enum to mod the min/max internally (enum { Mask, IP, Custom}); might prevent invalid address entry and keep things tighter. Haven't tested this much, let me know of any bugs you find...


Replacement for my original post which was more of an experimental control. However, people actually seemed to use it as is, hence the upgrade...


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Questionhow to check this control for blank values Pin
moin khan 1233-Apr-13 0:29
membermoin khan 1233-Apr-13 0:29 
GeneralMade simple change Pin
Chuck G4-May-10 13:42
memberChuck G4-May-10 13:42 
GeneralRe: Made simple change Pin
Chuck G4-May-10 17:59
memberChuck G4-May-10 17:59 
GeneralIt's ok! Pin
Morlack_x21-Oct-09 23:54
memberMorlack_x21-Oct-09 23:54 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 18 Aug 2008
Article Copyright 2008 by jkatebin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid