Nevertheless this can be done in other parts in the code, namely the Parse function which I will cover later in this tutorial. Here it becomes apparent, that Masked Text Boxes are primarily made for strings of a fixed length. Though it is possible to use the mask symbol “9″ to denote an optional digit we will run into troubles when formatting a string with a minus sign at the first location (where we used the mask symbol “#”).
Therefore I decided to force the user to fill in the whole string using leading zeroes if applicable.
Design via rightclicking on “References” and choosing “Add Reference …” in the Solution Explorer. As a longitudes degree can either be positive or negative this place should always only hold the signature ( ,-) of the degree.
We can not provide errorchecking in the mask and there is no explicit mask symbol only denoting plus and minus.
The property for example deserves an explanation as its value will determine how we have to implement other parts of the code. The prompt character () is the character which represents absence of user input in the string.
It determines weather the prompt character and/or literals are included in the formatted string. If it is included it will appear as part of the Masked Text Box.
, and its use is very well documented, I found it slightly more difficult to implement it using a custom type.
Since most of the information I was able to find on the web was either discussing the former or problems implementing the latter, I decided to give it a go and share my findings.The following vbprvb code shows a mask: Masked Text Box1.Mask = "99/99/9999"This mask can demand that the user enter eight digits, but cannot verify that the user enters month, date, and year values in the correct range; "12/20/2003" and "70/90/0000" are equally valid as far as the mask is concerned. Validating Type to verify whether the data entered by the user falls within the correct range—in the previously mentioned case, by assigning it an instance of the Date Time type.Add a new class to the project (right click your project, choose “add new …”, select “Class” and call it “Longitude.cs”.After a few minor customizations to the autogenerated code of “Longitude.cs” it should look like this: Now we implement the fields and properties.Those three ’0′s tell the mask to accept three (required) digital numbers.