如何在VB.Net中创建仅接受数字和句号的文本框
问题描述:
我需要帮助来创建一个文本框,该文本框在VB.Net中仅接受数字和句号.在vb6中这很容易,但是在VB.Net中,我真的很困惑.有人可以帮我吗,
谢谢.
I need help to create a text box that accepts only numbers and full stop in VB.Net. It was easy in vb6 but in VB.Net I am really confused. Can someone help me please,
Thank you.
答
Private Sub txt1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt1.KeyPress<br /> Try<br /> If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then e.Handled = True<br /> Catch ex As Exception<br /> MsgBox(ex.ToString)<br /> End Try<br /> End Sub