如何打开另一张表格时关闭一张表格 [英] How to make 1 form to close when another 1 opens

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

问题描述

我目前正在使用Visual C#开发应用程序,它由2种形式组成,第一种形式只是接受用户输入的介绍形式.用户键入输入并单击开始按钮后,应该关闭当前表单,然后打开第二个表单,但我只是无法正确编写代码.
请帮助提供示例代码..

i am currently developing an application using visual c# and it consists of 2 forms, the first form is just the introduction form that accepts user input. after the user has typed in their input and clicks the start button,the current form is supposed to close and the second one opens but i just cant get the coding right.
please help with sample codes..

推荐答案

如果我正确理解,请在您的Main方法(启动应用程序的地方)中,首先创建您的实例第一种形式,将其显示为对话框,然后运行第二种形式.

像这样的东西:
If I understood correctly, in your Main method (where you''re starting your application), first create an instance of your first form, show it as dialog and after that run the second form.

Something like:
static void Main() {
   Application.EnableVisualStyles();
   Application.SetCompatibleTextRenderingDefault(false);
   if (new IntroductionForm().ShowDialog() == DialogResult.OK) {
      Application.Run(new MainForm());
   }
...


使用 ^ ]会在用户单击您的按钮时关闭您的介绍表单.
use Form.Close[^] to close your introduction form when the user clicks your button.


这篇关于如何打开另一张表格时关闭一张表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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