掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
[VB2010]MaskedTextBoxの入力チェック方法 (ID:143422)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
TextMaskFormat プロパティを ExcludePromptAndLiterals にしておけば、 単純に「If MaskedTextBox1.Text = "" Then」と書けますよ。 Public Class Form1 #Region "コントロール名や位置の構成を伝えるため、デザイナ画面でコントロールを貼るかわりに、コードでコントロールを生成しています" Private maskedTextBoxes As New List(Of MaskedTextBox)() Private button1, button2 As Button Public Sub New() InitializeComponent() Font = New Font("MS Gothic", 12) button1 = New Button() With { .Name = "button1", .Text = "確認", .Bounds = New Rectangle(50, 250, 120, 30) } button2 = New Button() With { .Name = "button2", .Text = "クリア", .Bounds = New Rectangle(200, 250, 120, 30) } Controls.AddRange({button1, button2}) For n = 0 To 3 maskedTextBoxes.Add(New MaskedTextBox() With { .Name = "maskedTextBox" & CStr(n + 1), .Location = New Point(50, 50 * n + 30), .Mask = "A-AAA-AAAA", .Text = "1-234-5678", .TextMaskFormat = n }) Next Controls.AddRange(maskedTextBoxes.ToArray()) AddHandler button1.Click, Sub(sender, e) Dim s As String = "" maskedTextBoxes.ForEach( Sub(t) s &= String.Format("{0}, ""{1}"", {2}" & vbNewLine, t.Name, t.Text, t.TextMaskFormat) End Sub ) MsgBox(s, vbInformation) End Sub AddHandler button2.Click, Sub(sender, e) maskedTextBoxes.ForEach(Sub(t) t.Clear()) End Sub #End Region End Class
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.