Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,921 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a button connected to textboxes. How do I disable the button if textboxes are empty? I've tried a few things, cannot seem to get it to function. Thanks.
For instance, handle the TextChanged event of textboxes. (The handlers can be added by double-clicking the textboxes). Also handle the Load event of the form.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
UpdateButton()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
UpdateButton()
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
UpdateButton()
End Sub
Sub UpdateButton()
Button1.Enabled = Not String.IsNullOrWhiteSpace(TextBox1.Text) AndAlso Not String.IsNullOrWhiteSpace(TextBox2.Text)
End Sub
It is possible to use a unique TextChanged handler for textboxes.