C# 窗口形式的多个 GUI 与一个窗口 [英] C# Multiple GUIs With One Window in Window Form

查看:26
本文介绍了C# 窗口形式的多个 GUI 与一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的朋友正在尝试使用 Visual Studios 社区开发文本游戏.截至目前,我们已经以 Windows 形式启动了我们的项目.我们坚持的一件事是能够设计多个屏幕但只使用一个窗口.截至目前,我们设计的方式是在您单击第一个窗口上的开始游戏"后,它会弹出第二个窗口到角色选择屏幕.选择一个字符后,它会打开第三个窗口.

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.

我们更愿意做的是能够设计 GUI 以显示基本的初始启动画面,然后单击开始游戏"会在同一窗口中显示一个新的屏幕".新屏幕应该从初始启动屏幕拥有自己独特的 GUI.作为游戏的一部分,我们将要放置一个带有选项的暂停菜单.当用户点击暂停按钮时,应该会出现一个新的屏幕",同样具有您在游戏过程中会看到的主屏幕上的独特 GUI.

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.

是否可以创建多个 GUI 但只使用一个窗口形式的窗口?如果没有,我们怎么能让这样的事情发生?

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?

提前致谢!

推荐答案

在这种情况下,您必须使用 UserControl.可以将 UserControl 设置为一个完整的表单,然后您只需交换您创建的 UserControl 即可.

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.

在 Visual Studio 中创建一个 UserControl 项,将您的用户界面放入其中,基本上与设计一个普通的 Form 非常相似,您只需将按钮、标签和其他东西放在上面它并连接事件和逻辑,您就可以开始了.

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.

这里是关于使用UserControl的很好的教程

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.

这篇关于C# 窗口形式的多个 GUI 与一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆