×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Adding Control to Form Changes Visible Property

Adding Control to Form Changes Visible Property

Adding Control to Form Changes Visible Property

(OP)
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.

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}";
        } 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close