• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C# Windows Form/Control Question

jEnus

Senior member
Playing around in C# and I can't figure something out for the life of me, nor do I know what exactly what to search for.

How do you change the layout of the form when you click on a button. So, for example, I enter some information in a text box and click on a button to continue. After which, a new set of controls is displayed while the previous controls are removed. And so on and so on, as I keep clicking a 'continue' button.

I hope I made sense!

Edit: Doing some more thinking, there are two ways I see how to do this. First way, when I click continue, have it set the Visible value of the current controls to false. Or, second, there is a Container that is used for this that I don't know about.
 
Last edited:
Depends. You can either simply have controls that are always there, and turn visibility of the off and on, or you can create the controls in code, add them to the form and position them.

In all honesty, I'd create a number of panels with the relevant controls for each step on them, and toggle their visibility.
 
if button.clicked == true {
button2.visible = false
button3.visible = true;

}
or groupbox if you want to group things together
or something similar
 
One way I have done it in the past is to put each "screen" or set of controls on a different tab of a tabcontrol, then just move the selectedTab to the next tab when they click next. You will need to hide the tabs of the control by moving the control up on the form till they no longer show up.
 
Yeah that is what I first thought to do. I'm curious to know if it is the wrong approach though.

Turning visibility on and off is very fast, whereas it takes more time to create and initialize a new control hierarchy, wire up the events, etc.

If you have a relatively small, fixed number of forms, then it's faster to create them all at startup and just toggle the visibility. If it's a very large number, or the content is defined by state changes as you go, then you might have to build them as you need them.
 
Just curious - is there an advantage to this approach rather than just loading a new form with the new questions on it?

Well, if you do it this way, and the user resizes or moves the form, then that will keep without any special code when you move to the next step. If you do multiple forms, it will either move and resize back on each change, or you'll have to put in extra code to prevent it.
 
Back
Top