Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

Windows Forms design question

Hello!

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.

Question
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!
0
Ahmet Ekrem SABAN
Asked:
Ahmet Ekrem SABAN
  • 7
  • 3
1 Solution
 
for_yanCommented:

>Below, you see the main menu

where can we see it?
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
The MainForm display
0
 
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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.
0
 
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.
0
 
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.
0
 
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...
0
 
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"?
0
 
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?
0
 
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
    vf.Show();
0
 
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;
            panelForm.Controls.Add(m_ValuesForm);
            m_ValuesForm.Show();

Open in new window


Thank you very much, sir!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now