我想禁用"确定"加载validateAdd表单时按钮,然后启用"确定"用户在文本框中输入一些文本时按钮。
这是我的禁用和启用按钮的代码。
Private Sub validateAdd_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If txtaddlname.Text = String.Empty AndAlso txtaddfname.Text = String.Empty AndAlso txtaddmid.Text = String.Empty Then
btnaddOk.Enabled = False
Else
btnaddOk.Enabled = True
End If
End Sub
答案 0 :(得分:1)
您应该将所有代码放在三个文本框的TextChanged
事件中:
Private Sub fields_TextChanged(sender As Object, e As EventArgs) Handles txtaddlname.TextChanged, txtaddfname.TextChanged, txtaddmid.TextChanged
If txtaddlname.Text = String.Empty AndAlso txtaddfname.Text = String.Empty AndAlso txtaddmid.Text = String.Empty Then
btnaddOk.Enabled = False
Else
btnaddOk.Enabled = True
End If
End Sub
由于Loaded
的{{1}}事件只发生过一次。希望它有所帮助:)