One of the ways that I often use when developing applications is to use the main form as a container for views (a view), which contains a panel for adding views.
What can you do:
- Define two user controls: one for the menu, one for the logic of the game. The menu view should display one event for each menu item to which the main form can be attached.
- At startup, show the menu control. When an event for "Play" is triggered, the main form should switch to game mode.
The following pseudo code will help you switch views:
private void SwitchView(Panel container, UserControl newView) { if (container.Controls.Count > 0) { UserControl oldView = container.Controls[0] as UserControl; container.Controls.Remove(0); oldView.Dispose(); } if (newView != null) { newView.Dock = Dock.Fill;
Please note that this code cannot be compiled properly, I am writing this from my head. But it will give you a general idea of ββthis.
source share