5

My friend and I are trying to work on a text game using Visual Studios Community. As of now, we have started our project in windows form. One thing we are stuck on is being able to design multiple screens but using only one window. As of right now, the way we have it designed is after you click "Start Game" on the first window, it pops open a second window to the character select screen. Once you select a character, it opens a third window.

What we would rather do is be able to design the GUI to display a basic opening splash screen and clicking on "Start Game" would bring up a new "screen" but in the same window. The new screen should have it's own unique GUI from the initial splash screen. Also part of the game, we are going to want to put a pause menu with options. When the user clicks on the pause button, that should bring up a new "screen", again with it's own unique GUI from the main screen you would see during the game.

Is it possible to create multiple GUIs but only using one window in window form? If not, how could we make something like that happen?

Thanks in advance!

R1zzo23
  • 57
  • 1
  • 7
  • 1
    Have you tried User Controls instead of forms? – Nadia Chibrikova Jan 12 '15 at 12:31
  • Terminology: Window == Form. The first question is: Shall they be open in parallel and moveable side by side?? If so you need several Forms. If not you have other options.. - You could look into a Tab with several TabPages for example. – TaW Jan 12 '15 at 12:34
  • What you are asking is calle "MDI", Multiple Document Interface. You'll find numerous articles about this as it was a popular UI a decade ago, supported by WinForms directly. It stopped being popular though because it creates a lot of clutter and confusion – Panagiotis Kanavos Jan 12 '15 at 12:36
  • There are plenty of options.. you could use tabpages, MDI, usercontrols... it depends on how you want to design your application – Jcl Jan 12 '15 at 12:37
  • Is the flow through these screens linear? Can the user go backwards through them, or in only one direction? – DonBoitnott Jan 12 '15 at 12:37
  • @PanagiotisKanavos I would not be so quick to say that. MDI is only useful if you want multiple forms open _at the same time_. I would argue that it seems OP wants nothing of the sort. – DonBoitnott Jan 12 '15 at 12:38
  • I think you are right. The question needs a lot of cleaning up, specifying the actual problem to solve. The code only confuses at this point. If anything, this is a design question that should contain only minimal references to WinForms – Panagiotis Kanavos Jan 12 '15 at 12:41

2 Answers2

5

You have to use UserControl in this case. A UserControl can be set up as a whole form, then you simply swap the UserControls that you have created.

In visual studio create a UserControl item, put your user interface in them, basically very similar to designing a normal Form you just put buttons, labels and other stuff on it and wire up events and logics and you are ready to go.

You propably need to implement a global logic or business model to handle or pass the events of each usercontrol you are creating to have a unified model accross your application.

Here is a good tutorial on using UserControl

You can also apply transition animations while swapping between different controls, anyway if you google these stuff up you will find plenty of useful data.

Dumbo
  • 13,555
  • 54
  • 184
  • 288
  • I would also add that after you implement each UserControl for each view of your application, in the Main Form, the one loaded at startup you can add a split panel or a dock panel to lock each user control in a specific section of the screen. – Raffaeu Jan 12 '15 at 13:16
0

You can create a wizard like control which can have a custom TabControl. Each tab page can then have different controls you would like to place. You can also create user controls and add them to tab pages which would make it a bit easy to maintain.

Customizing a tab page:

public class CustomWizard : TabControl
{
    protected override void WndProc(ref Message m)
    {
        // Second condition is to keep tab pages visible in design mode
        if (m.Msg == 0x1328 && !DesignMode)
        {
            m.Result = (IntPtr)1;
        }
        else
        {
            base.WndProc(ref m);
        }
    }

    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.Control && e.KeyCode == Keys.Tab)
            return;

        base.OnKeyDown(e);
    }

    private void InitializeComponent()
    {
        this.SuspendLayout();
        this.ResumeLayout(false);

    }
}

You can then use this tab in your form and have next and back buttons. Handle the click event of these buttons to move back and forth.

danish
  • 5,550
  • 2
  • 25
  • 28