winformstextboxmaskedtextbox

I want that the user can only type x.x.x.x in a Textbox


I want that the user can only type X.X.X.X in a Textbox (X is a number)

I tried a maskedTextbox and changed under properties the mask to:

//Mask: 9.9.9.9

//Previw: _,_,_,_

but when I got the value out of the maskedTextbox I get:

//Value: 1,1,1,1

is there a possibility that i can get:

//Value : 1.1.1.1

Solution

  • This is covered in the documentation for the Mask property:

    . Decimal placeholder. The actual display character used will be the decimal symbol appropriate to the format provider, as determined by the control's FormatProvider property.

    ...

    \ Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.

    So you shouldn't be using . if you always want a period regardless of regional settings: you should use \. in that case.