如何关闭Form1并打开窗体2 [英] How to close Form1 and open Form2

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

问题描述

在Form1上,当进度条完成,然后在timer_tick事件'else部分下面的代码是我写的:

In Form1 when progressbar is completed then in timer_tick events' else part the following code is written by me:

frmLogin login = new frmLogin();
login.Show();
timer1.Enabled = false;
this.Hide();



因此​​,任何解决方案,以关闭 Form1中代替隐藏 Form1中

推荐答案

您有一些所谓的<的HREF =htt​​p://msdn.microsoft.com/en-us/library/system.windows.forms.applicationcontext%28v=vs.110%29.aspx相对=nofollow> 的ApplicationContext

You have something called the ApplicationContext for that.

使用这样的:

ApplicationContext applicationContext = new ApplicationContext();

FormX formX = new FormX(applicationContext);
applicationContext.MainForm = formX;

Application.Run(applicationContext);

在结束 Form1中,拱手的MainForm

FormY formY = new FormY(applicationContext);
applicationContext.MainForm = formY;



另一种方法是使静态的ApplicationContext 。这不会要求各地传递给它。

Another option is to make a static ApplicationContext. That wouldn't require passing it around.

这篇关于如何关闭Form1并打开窗体2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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