|
Project Information
Members
Featured
Downloads
|
Latest Revision: 44 (28-Jun-08)
IntroductionWhy didn't Microsoft include an IP address control in the stock toolbox for Visual Studio .NET? I needed something similar to the MFC CIPAddressCtrl class in a C# application recently, and was forced to roll my own. I tried to mimic the behavior of CIPAddressCtrl using C#, and hopefully I've succeeded. If you need a C# IPv6 address control or a C# MAC address control, take a look at this project. BackgroundIPAddressControl is a ContainerControl that aggregates four specialized TextBox controls of type FieldCtrl and three specialized Controls of type DotCtrl.
The FieldCtrls do some validation and keyboard filtering in addition to standard TextBox behavior. The DotCtrls do nothing but draw a dot. Using The CodeOnce the library containing IPAddressControl (IPAddressControlLib.dll) is built, add the control to the Toolbox in Visual Studio. From the Toolbox, just drag the control onto a form and you're ready to go. The interface to IPAddressControl is very simple. Public Instance Properties
Public Instance Methods
The above properties and methods are in addition to the stock properties and methods of UserControl. Stock properties such as Text, Enabled, and Font, as well as stock methods such as ToString() work as expected. Client code can register a handler for the public event, FieldChangedEvent, to be notified when any text in the fields of the control changes. Note that Text and ToString() may not return the same value. If there are any empty fields in the control, Text will return a value that will reflect the empty fields. ToString() will fill in any empty field with that field's RangeLower value. Also, if you are using the control to create an IPAddress, you can easily do so using this control's GetAddressBytes() method: IPAddress ipAddress = new IPAddress( ipAddressControl.GetAddressBytes() ); |