erikduvet
erikduvet

Reputation: 321

Hide part of panel C#

I have a question regarding an issue I'm facing in my C# implementation. I want to "hide" a part of my Panel and if the User checks a checkbox (or something like that) this hidden part of the Panel should be shown.

What I want is something like what is used in Windows for this sort of thing. Like when you are at "My computer" you can see multiple choices in the left hand panel, and a small "triangle" indicate that there is more to be shown.

What I'm having is like 10-15 textboxes to be shown if the User checks the checkbox. My first thought was to ha a static size of my panel and just hide the textboxes, but since this would look rather stupid with that much blank space under i dissmissed this.

I than thought about reducing the size but is this the most effective way or is there a smarter way of doing something like this?

Thanks all!

Upvotes: 2

Views: 1456

Answers (2)

Lyuben Todorov
Lyuben Todorov

Reputation: 14153

You need something like

if (checkBox1.Checked == true)
{
    panel1.Visible = true;
}

place this code inside the method created when the checkbox is clicked.

Upvotes: 0

Eric Andres
Eric Andres

Reputation: 3417

You probably want to have a nested panel that contains the controls you want to hide. When the condition arises that you want to hide/show them, just alter the visibility of the nested panel. Depending on how your form is laid out, you might have to manually changed the size of the outer panel when you do this as well.

Upvotes: 3

Related Questions