DaveInIowa
Programmer
I'm wondering if anyone can explain this behavior. The example uses 2 controls on a form, comboBox1 & textBox1. Both of their Visible properties are true in the designer. When I step through the code I can see where the Visible property of each control changes to false after they are added to the form's Controls property.
Even though after the execution of the InitializeComponent() method their Visible property is false, they still will show on the form unless I set their property explicitly.
Even though after the execution of the InitializeComponent() method their Visible property is false, they still will show on the form unless I set their property explicitly.
Code:
public Form1()
{
// If you step through InitializeComponent(), you'll see that
// this.Controls.Add(this.textBox1) and
// this.Controls.Add(this.comboBox1)
// changes their .Visible property from true to false
InitializeComponent();
// The .Visible property is false but the combo box will still be displayed UNLESS...
bool cbxVisible = comboBox1.Visible;
// ...I set the .Visible property, then it will ACTUALLY hide the combo box
comboBox1.Visible = cbxVisible;
bool txtVisible = textBox1.Visible; // Is false but will still be displayed
textBox1.Text = $"ComboBox visible: {cbxVisible}, TextBox visible: {txtVisible}";
}