Option Strict Off Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load For Each txt In Me.Controls.OfType(Of TextBox)() AddHandler txt.Leave, AddressOf TextBoxes_Leave Next End Sub Private Sub TextBoxes_Leave(sender As TextBox, e As EventArgs) Dim d As Decimal If Decimal.TryParse(sender.Text, d) AndAlso d > 0.0d Then sender.ResetBackColor() Else 'MsgBox("非数値、または 0 以下の値が入っています。") sender.BackColor = Color.Red MsgBox("0 よりも大きい数値を入力してください。") End If End Sub End Class