所以,我对学校进行了一次小测试,我需要在两个文本框的内容为空的情况下禁用三个单选按钮,这些按钮位于面板中,可能代码最少。只要两个文本框都填满,我就会启用面板。
以下解决方案显然适用于单个文本框,但两个会发生什么? 我知道我可以覆盖每个按钮KeyPress并同时检查两个文本框。但我想要开玩笑。问题是我认为我无法像这样解决这个问题。
或者是吗?
Public Class Form1
Public Sub vacios(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
Panel1.Enabled = (sender.Text <> "")
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler txtNombre.KeyPress, AddressOf vacios
AddHandler txtApellido.KeyPress, AddressOf vacios
End Sub
End Class
Public Class Form1
Private Sub txtNombre_TextChanged(sender As Object, e As EventArgs) Handles txtNombre.TextChanged
Panel1.Enabled = (txtNombre.Text <> "" And txtApellido.Text <> "")
End Sub
Private Sub txtApellido_TextChanged(sender As Object, e As EventArgs) Handles txtApellido.TextChanged
Panel1.Enabled = (txtNombre.Text <> "" And txtApellido.Text <> "")
End Sub
End Class
答案 0 :(得分:1)
这里是我在这种情况下要做的一个例子
Public Class Form1
Private Sub panel1TextBoxes_TextChanged(sender As Object, e As EventArgs) Handles txtApellido.TextChanged,txtNombre.TextChanged
Panel1.Enabled = (txtNombre.Text <> String.Empty And txtApellido.Text <> String.Empty)
End Sub
End Class