我希望在表单启动时阻止键盘输入,但它不起作用,请检查我的代码:
Public Class Form2
Public Declare Function BlockInput Lib "User32" (ByVal fBlock As Integer) As Integer
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim name As String
name = "12345"
If (name = TextBox1.Text) Then
Me.Close()
End If
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Visible = True
TextBox1.Focus()
End Sub
Private Sub TextBox2_Click_1(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox2.MouseClick
BlockInput(1)
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
End Class`
答案 0 :(得分:0)
我使用" groupbox.enabled = False"为了阻止程序用户编辑我的表单上的组框内的任何内容。然后,您可以再次启用组框,只要满足某些条件即可。我在VB.net编程中使用的另一种方法是设置只读属性(我曾经自动填充系统日期以防止用户输入错误日期)我不知道是否要么那些方法对你有帮助吗?