2012/02/20

MaskedTextBox からの文字列の取得の仕方を変更する

MaskedTextBox のTextMaskFormatプロパティを変更することで、どのように文字列を取得するかを 変更できる。

たとえば、MaskedTextBoxA に"____年__月__日" というマスクを設定して、テキストボックスに"2012年02月20日"と入力された場合

フォーマット文字列を除いて取得:

MaskedTextBoxA.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
strInput = MaskedTextBoxA.text
strInput:"20120220"



フォーマット文字列を含めて取得:

MaskedTextBoxA.TextMaskFormat = MaskFormat.MaskFormat.IncludeLiterals strInput = MaskedTextBoxA.text
strInput:"2012年02月20日"


となる。