Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
This is question about changing application GUI during a runtime.

There are two windows form applications with same controls, same program code and only one difference, controls are arranged differently. GUI is different.

If program code is examined , there is only difference in between two MainForm.Designer.cs classes.

I am interested how to use only one application, that will load selected MainForm.Designer.cs class, on the runtime, and use it to change application GUI.

Is such thing possible ?


All the best,
Željko Peric

What I have tried:

Since that I do not know how, I have tried nothing.
Posted
Updated 11-Feb-19 6:44am
Comments
Maciej Los 11-Feb-19 12:06pm    
I'm not sure i understand you well, but this sounds like you want to call different form depending on parameter. Am i right?
Perić Željko 11-Feb-19 12:19pm    
I want to start program, and on selected option from program user, to rearrange all controls used in program. Is this possible by loading and invoking MainForm.designer.cs class that is used for different program.
Maciej Los 11-Feb-19 12:39pm    
Ok, we are closer to resolve your issue... So, you want to allow a user to change view.
Have you ever heard about Model-View-Presenter pattern?

The "startup form" is created by a line in program.cs:
C#
static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
        {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new frmMain());  // <<-- This sets the startup app
        }
    }
So it wouldn't be difficult to just change the Form there and Run the app - that could be on a command line switch, or whatever.

The other approach is to actually change which controls you create / execute which is technically possible - they are built in your Form.designer.cs file so it wouldn't be difficult to get that to select "set A" or "set B" - but that's actually a PITA because it would make future development of the two "forms" seriously complicated.

The way I'd do it is simpler: convert each Form into a UserControl and select which control you want to display at run time, making it fill the form area.
 
Share this answer
 
Comments
Perić Željko 11-Feb-19 12:30pm    
Thanks for answer.
OriginalGriff 11-Feb-19 12:36pm    
You're welcome!
Maciej Los 11-Feb-19 12:50pm    
5ed!
Perić Željko 11-Feb-19 15:50pm    
I have managed to create .dll file that contains MainForm.Designer.cs class with small changes in code. Now I can use it as any .dll, and call InitializeComponent() method from .dll to create rearanged GUI for user.
In addition to OriginalGriff's excellent answer, I would also like to mention skinning.
Although Winforms are notoriously difficult to skin, you can use the free Krypton Toolkit: GitHub - ComponentFactory/Krypton: Krypton WinForms components for .NET[^]

For a simple Winforms Skinning example see: A New Skin for Ye Olde GroupBox[^]

Of course when using WPF there are more possibilities for skinning.
 
Share this answer
 
v3
Comments
Maciej Los 11-Feb-19 12:51pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900