关闭Windows表单 [英] Close a windows form

查看:103
本文介绍了关闭Windows表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在用C#创建一个项目.
按下一步"按钮后,我有一个欢迎屏幕,新的Windows窗体打开.我似乎不知道我们如何自动关闭仍在后台运行的其他Windows窗体.

我尝试了在该论坛上阅读的一些内容,但大多数情况下,我的所有Windows窗体都开始关闭...

Hello,

I''m making a project in C#.
I have a welcome screen, after pushing "next" button a new Windows-form opens. I dont seem to figure our how to automaticly close the other Windows-form that is still running in the background.

I tried some things that I''ve read on this forum but most of the time all my Windows-forms start closing...

推荐答案

只需修改program.cs在项目中,要关闭的表单是"Form1",因此只需调用this.Close()即可关闭Form1并自动启动Form2.还有另一种方法:您可以隐藏第一个表单并显示第二个表单.
Simply modify program.cs of your project, the form which you want to close is "Form1" so simply call this.Close() which closes Form1 and start Form2 automatically. There is another way as well: you can hide the first form and display second form.
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());// Form with next button
    Application.Run(new Form2());// Form to be opened when next button clicked
}


我的猜测是,您的欢迎"屏幕是程序的主窗体,这意味着您执行以下操作:

My guess is that your Welcome screen is your program''s Main form, which means when you do:

this.Close();



程序停止执行,因此关闭所有表格.
这是一个疯狂的猜测,请尝试将代码发布在您的欢迎屏幕出现的位置以及尝试关闭它时的操作.



the program stops executing, therefore closing all forms.
It''s a wild guess, try posting the code where you make your welcome screen appear and what you do when you try closing it.


这篇关于关闭Windows表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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