C# Windows Form/Control Question

jEnus

Senior member
Jun 22, 2004
867
0
76
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:

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
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.
 

lyssword

Diamond Member
Dec 15, 2005
5,630
25
91
if button.clicked == true {
button2.visible = false
button3.visible = true;

}
or groupbox if you want to group things together
or something similar
 

lyssword

Diamond Member
Dec 15, 2005
5,630
25
91
If you want to only remove/replace 1 item at a time/click you will obviously need a loop.
 

KB

Diamond Member
Nov 8, 1999
5,402
386
126
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.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
Just curious - is there an advantage to this approach rather than just loading a new form with the new questions on it?
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
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.
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
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.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |