I am developing an application in Windows Form C#, it begins with an explanatory window, language selection and a start button when the desired language is selected, I want that when I press the start button, all the elements disappear and begin the application process, I had thought of creating a new form, but this opens a new window and I don't want that, I want everything to happen on a window. Apart from making all the previous controls invisible, is there any way to achieve this? Or maybe a way to make all the controls invisible without going one by one?
Asked
Active
Viewed 76 times
-1
-
Hello, would be nice if you would put your code here, but i think i may help you. – Bartosz Olchowik Jan 11 '22 at 13:54
-
instead of creating Forms, you could create UserControls, Add the "explanatory window" UserControl first. Remove it and add the next UserControl. – Jeroen van Langen Jan 11 '22 at 13:54
-
@BartoszOlchowik I can add code but I don't know exactly what, the start button had a `new form` to the next process but as I said, I don't want another window so I deleted that code. – Jan 11 '22 at 13:56
-
@JeroenvanLangen I don't know exactly what a user control is, can you explain it more in depth? – Jan 11 '22 at 13:58
-
Can you explain why you don't want to close the "explanatory" form and open a new form for the application? It's a pretty standard thing to do. – HardCode Jan 11 '22 at 13:59
-
1@EndikaBustamanteAlvarez Just do a search on YT _"C# Tutorial - How to Create and use User Control"_ – Jeroen van Langen Jan 11 '22 at 14:00
-
@HardCode It is cleaner for me to do the process in a linear way instead of opening windows – Jan 11 '22 at 14:06
-
@JeroenvanLangen I will take a look at that video, you can make an answer about that and if what is shown in the video solves the problem I will mark the answer as a solution. – Jan 11 '22 at 14:08
-
https://stackoverflow.com/questions/2340566/creating-wizards-for-windows-forms-in-c-sharp is a nice alternative if you have multiple steps – Martheen Jan 11 '22 at 14:20
-
@JeroenvanLangen This is exactly what I was looking for, please put it as an answer to be able to mark it as a solution. – Jan 11 '22 at 14:44
-
@EndikaBustamanteAlvarez A link to a video is not a good answer. A good answer might be what you made of it and explain how you did it. _(It is of course completely free of obligation whether you want to put time into it)_ – Jeroen van Langen Jan 11 '22 at 15:45
2 Answers
1
You could put multiple controls in a panel for example and hide/show entire panel. If you dont want to do that, you could always do it in a loop for example:
foreach ( var control in this.Controls)
{
control.Visible=false;
}
Ofcourse you could also add controls dynamically, but that might be hard for a beginner.
You could also make use of MDI forms, but that might be also not worth it.

Bartosz Olchowik
- 1,129
- 8
- 22
-
1This would be difficult to maintain the software. Also all code is in the same file. It will be Spaghetti. – Jeroen van Langen Jan 11 '22 at 13:57
-
What would be difficult to maintain? Those 4 lines of code or? – Bartosz Olchowik Jan 11 '22 at 14:05
-
1No, many button_click handlers/UI update/business code which will be in the same code-behind file. – Jeroen van Langen Jan 11 '22 at 15:43
1
SOLVED
Solved using user controls, user controls allow me to design the application interface in the same way as a form and I can add and remove that control from the form as many times as I want, making it possible to display numerous interfaces in a single Windows Forms window.
This solution was suggested by Jeroen van Langen in the comments of my question and it was exactly what I was looking for.