How can i change masked text box properties for IP address input. For example

private void Interneta_savienojums_Load(object sender, EventArgs e)
    {
        maskedTextBox1.Text = "   .   .   .   ";
        maskedTextBox1.PromptChar = ' ';
        maskedTextBox1.Mask = "009.009.009.900";
        maskedTextBox1.ResetOnSpace = false;
        maskedTextBox1.SkipLiterals = false;
    }

In form text box show ( . . . ), exactly what i want. when my input is 123.123.123.123 everything is okey,but when i in put 23 .1 .001.200 , , and return value 23 .1 .001.200 , but need, 23.1.1.200 . How can remove spaces , and return normal value ? Is this possible or not ?

Why dont you use a normal TextBox control instead of MaskeTextBox?

In IP case, it would be a better option.

Anyway, if you would like to use MaskeTextBox, and if you wanna remove spaces use Replace method of string class:

            string input = "23 .1 .001.200";
            if (input.Contains(" "))
                input = input.Replace(" ", "");

You can remove spaces exactly like Mitja Bonca said. And you don't have to care about removing zeros - you can try to parse your IP address like that (based on Mitja Bonca's code):

string input = "23 .1 .001.200";
if (input.Contains(" "))
    input = input.Replace(" ", "");
IPAddress ipAddress;
if (IPAddress.TryParse(input, out ipAddress))
{
    //IP address has been parsed correctly
}

THANKS !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.