C# UserControl IPTextBox

I am looking for a TextBox control, which can validate and filter out IP Address. After a bit research, I come with this https://social.msdn.microsoft.com/Forums/vstudio/en-US/4c2aefae-ca6a-4e71-8564-fe73da7107f1/maskedtextbox-formatting-for-an-ip-address?forum=csharpgeneral. It’s easy to implement and simple to use. Just like normal TextBox.

iptextbox

using System.Windows.Forms;
class IPTextBox : TextBox
{
    public IPTextBox() : base()
    {
        SetStyle(ControlStyles.ResizeRedraw, true);
    }

    protected override CreateParams CreateParams
    {
        get
        {
            var cp = base.CreateParams;
            cp.ClassName = "SysIPAddress32";
            return cp;
        }
    }
}

Another complete solution can be found http://www.sanity-free.org/127/an_ipaddress_control_the_win32_sysipaddress32_control_in_csharp.html

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.