0

I'm using visual studio 2010 and I have a winforms application.

When I start the application I show the user the 'MainMenu' which have:

1) New Game button

2) Options

each button click create a new form... what I want to do when the user clicks on the options button is to change the MainWindow content to be the Options window content.. and when he accepts the changes on the options window -> return to the mainMenu view.. is it possible to do?

Elior
  • 3,178
  • 6
  • 37
  • 67
  • 1
    See these posts: http://stackoverflow.com/questions/297526/what-is-the-best-way-to-clear-all-controls-on-a-form-c http://stackoverflow.com/questions/13584902/change-content-in-a-windows-form – marsze Feb 19 '13 at 11:52
  • 1
    You'll probably need to dynamically create your controls and the layout. Predefine your forms, if necessary. There are some obstacles in creating new forms out of the box, though! – bash.d Feb 19 '13 at 11:53

4 Answers4

4

You could either use Panels and switch them round:

panelMain.Visible = false;
panelOptions.Visible = true;

Or you could have a numerous forms, and show and hide them:

frmOptions.Show();
frmMain.Hide();
Adam K Dean
  • 7,387
  • 10
  • 47
  • 68
2

Create multiple Panels and hide and show these on Button click.

Button_Click(object sender, EventArgs e)
{
  PanelNewGame.Visible = true;
  PanelOptions.Visible = false;
  PanelMain.Visible = false;
}

Depending on the button you click handle them differently

Jordy van Eijk
  • 2,718
  • 2
  • 19
  • 37
2

One way you could do it is to use invisible labels and text fields for example, and when the user clicks the Options button then everything becomes clear.

Farkiba
  • 366
  • 1
  • 5
  • 17
0

I would advise that you take a look at the Tab Control class. This control allows you to switch between different blocks of content programmatically using the command

tabControl.SelectTab(i)

where i is the index of the tab.

Martin McGirk
  • 411
  • 4
  • 13
  • yeah i know, but i don't want to use Tabs – Elior Feb 19 '13 at 11:59
  • @Elior you can make a custom usercontrol that behaves like a TabControl without the visuals.. Or your own visuals this does what you want and is wel tested by MS :P – Jordy van Eijk Feb 19 '13 at 12:02
  • Fair enough. Are you aware though that you can use the trick detailed in [this stack overflow answer](http://stackoverflow.com/a/6954785/837194) to hide the actual tab headers, thus giving the flexibility of tabs without the UI ugliness? – Martin McGirk Feb 19 '13 at 12:02