ปกติถ้า textbox อยู่ใน From ปกติก็จะใช้ Code (VB.NET)
Private Sub TxtNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtNum.KeyPress, TxtPCode.KeyPress, TxtTel.KeyPress, TxtNum1.KeyPress, TxtPCode1.KeyPress, TxtTels.KeyPress, TxttelIn.KeyPress, TxtCardNum.KeyPress
Select Case Asc(e.KeyChar)
Case 48 To 57, 8, 45
Case Else
e.Handled = MessageBox.Show("กรุณาระบุตัวเลข", "การแจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Select
End Sub
Private Sub TxtNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtNum.KeyPress, TxtPCode.KeyPress, TxtTel.KeyPress, TxtNum1.KeyPress, TxtPCode1.KeyPress, TxtTels.KeyPress, TxttelIn.KeyPress, TxtCardNum.KeyPress
Dim txt As TextBox = CType(sender, TextBox)
Select Case Asc(e.KeyChar)
Case 48 To 57, 8, 45
Case Else
e.Handled = MessageBox.Show("กรุณาระบุตัวเลข", "การแจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Select
End Sub