r/visualbasic • • Jul 09 '18

Making text-boxes appear and disappear while checkboxes are selected?

Interface

Hey, everyone. I was wondering if you guys could help me out or if you just have a solution. This is an interface for a school assignment. When the box/lawn/pavilion checkboxes are checked, a textbox becomes visible underneath. When the same checkbox is unchecked, the textbox's Visible property evaluate to false and disappears. The Visible property is set to false when the application is first run. You are allowed to have any number of the checkboxes checked at the same time as long as their accompanying textbox disappears when they are unchecked.

Does anyone have any ideas? I've been able to get everything else done but for whatever reason I can't figure this out. I've used both if...then statements and case statements but just can't crack it. If you need any other information feel free to message me. Thank you so much!

5 Upvotes

6 comments sorted by

View all comments

2

u/JakDrako Jul 12 '18 edited Jul 12 '18

You could also use (abuse?) WinForm's databinding functionality:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        CheckBox1.DataBindings.Add("Checked", Me.TextBox1, "Visible", True, DataSourceUpdateMode.OnPropertyChanged)
        TextBox1.DataBindings.Add("Visible", Me.CheckBox1, "Checked", True, DataSourceUpdateMode.OnPropertyChanged)
    End Sub
End Class

EDIT: Actually, you can use only the "TextBox1..." line, the other one is redundant