| 分類:[VB.NET]
「最もシンプルに」の定義があいまいですね。 私のシンプルのイメージは、同じ処理を同一イベントにまとめる感じです。 具体的には、下記のような感じです。 (ごめんなさい。動作確認してません。) 「if文を使って」を無視してしまっていますが・・・。
'フォームロードイベント Private Sub MainForm_Load( _ ByVal sender As Object, _ ByVal e As System.EventArgs _ ) Handles Me.Load
'イベント ハンドラの関連付け AddHandler txt1.Validated, AddressOf Text_Validated AddHandler txt2.Validated, AddressOf Text_Validated ・ ・ ・ AddHandler txt5.Validated, AddressOf Text_Validated
End Sub
'テキストボックスの検証終了時イベント Private Sub Text_Validated( _ ByVal sender As Object, _ ByVal e As System.EventArgs _ ) Dim txt As TextBox = DirectCast(sender, TextBox)
If txt.Text <> StrConv(txt, VbStrConv.Narrow) Then MessageBox.Show("検索項目に半角で入力して下さい。", "エラー") 'その他の処理 End If
End Sub
|