Windows Forms design question


I am currently involved in my first WinForms project with C#. We are going to implement the GUI for a machine that consists of several menus. Below, you see the main menu that is the class currently all the forms are derived from. All the menus have the same "border", where I mean with border the button menu below, the status information to the left, the controls to the right and the header information.

As I have indicated above, currently, there exists a MainForm class that is used to derive the other forms for each submenu. Each of these forms repeat the "bordered" information.

This was the way my customer asked me to do it, but I doubt that it is really necessary to create different forms, as it may suffice to fill-in the central part according to the menu button pressed.

Is the design of my application the right way to solve the problem, or should I leave the derived forms, using only one MainForm that has a varying central part?

Thank you for your suggestions!
Ahmet Ekrem SABANSenior IT consultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


>Below, you see the main menu

where can we see it?
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
The MainForm display
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
I not only forgot to add the image of the display, but that the state of each form has to be retained all over the application life time. That is, if one is in menu three and returns to menu one, he finds everything as (s)he left it.
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Mike TomlinsonMiddle School Assistant TeacherCommented:
"... it may suffice to fill-in the central part according to the menu button pressed."

You can design the central part using UserControls or regular Forms (displayed with no Border).  Then just swap out what is displayed in the middle.

*To embed a Form like a control in another Form, set its TopLevel() property to False at run-time via code.
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
But if I used regular forms for the central part, how can I merge the MainForm with the parts for the different menus? As far as I understood, this will be a borderless form that is placed exactly at the right position. But if one touches it and moves to another direction, the central part will be shifted.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Since it's borderless, the user won't be able to move it around.  Additionally, you can set its Dock() property to Fill which would make it fill that entire area even when the main form is resized and/or moved.
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Currently, I am writing the functional description and I am involved in other tasks. So, I am sorry that you have still to wait for the test...
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Hello, Idle_Mind. Now, time has come to try this workaround...

Can you tell me how to create out of an existing Form a "regular form"?
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
OK, I created the ValuesForm as an example, no more deriving it from BaseForm, but simply from Form. To get both the surrounding and the ValuesForm, I added a BaseForm object as a field. In my constructor of ValuesForm, I wrote

        private ValuesForm()
            m_BaseForm.Visible = true;
            Location = new Point(220, 34);
            m_BaseForm.Dock = DockStyle.Bottom;
            FormBorderStyle = FormBorderStyle.None;

Open in new window

Not that this Form has a private constructor, as it is currently a singleton...

But the result is the BaseForm and the ValuesForm separated. By chance, they are overlaying, but when I click the BaseForm, the ValuesForm vanishes behind it. (ValuesForm cannot be clicked as BaseForm or moved by the mouse.) How can I use the Dock method so that the ValuesForm docks at the Location I need?
Mike TomlinsonMiddle School Assistant TeacherCommented:
When you create your instance of ValuesForm, set the TopLevel() property to false and add it to a container:

    // ... in BaseForm ...
    ValuesForm vf = new ValuesForm();
    vf.TopLevel = false;
    this.Panel1.Controls.Add(vf); // <-- add "vf" to some container on BaseForm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Congratulations, Idle_Mind! Only one line is missing!
            m_ValuesForm = ValuesForm.GetInstance();

            m_ValuesForm.FormBorderStyle = FormBorderStyle.None;
            m_ValuesForm.TopLevel = false;

Open in new window

Thank you very much, sir!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Theory

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.