Tip 1
I recommend that you use the NumericUpDown
component. Include four of them in your form and seven properties% with% to 0 and% with% to 255.
The advantage of using this type of component is that you have control over the numbers you are going to receive, plus you are sure to only receive numbers.
Tip 2
Use the minimum
component. Change the property maximum
to '999,999,999,999' and the property MaskedTextBox
to mask
.
To check the value you enter, use the function:
public static int verificaValor(string ip, int parte)
{
//ip é o texto com o ip
//parte é qual das quatro partes você quer verificar
if (parte == 1)
return int.Parse(ip.Substring(0, 3));
if (parte == 2)
return int.Parse(ip.Substring(4, 3));
if (parte == 3)
return int.Parse(ip.Substring(8, 3));
if (parte == 4)
return int.Parse(ip.Substring(12, 3));
}
This function will return the value of one of the 4 parts of ip, eg:
If the ip is SkipLiterals
and you use false
, the value 100 will be returned.
So you can check the value using an if:
if (verificaValor(textBoxIp.text, 3) > 255)
//mensagem de erro
Even so, I suggest the first way to do it, because it prevents the user from entering values above what you want.