在Windows应用程序中关闭启动表单 [英] Closing startup form in a windows application

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

问题描述

我在Windows应用程序中有2种表单-LogonForm和ProcessForm.登录表单被设置为项目的启动对象".成功登录后,我将获得以下代码,以将控件从LogonForm转移到ProcessForm并关闭LogonForm(仅).

//实例化ProcessForm并显示ProcessForm MyProcessForm = new ProcessForm(InputData);
MyProcessForm.Show();

//关闭登录表单
this.Close();.

此代码实际上关闭了整个应用程序,而没有显示ProcessForm.

现在,如果我将this.Close()更改为this.Hide(),则会打开ProcessForm,但是当我关闭ProcessForm时,我可以看到应用程序仍在运行,因为"LogonForm"仍在隐藏状态.

关闭ProcessForm时,必须关闭整个应用程序.您能帮我怎么做吗?预先感谢您的帮助

I have 2 forms in a windows application - LogonForm and ProcessForm. The Logon Form is setup as the "Startup Object" for the project. Upon successful logon, I have the below code to transfer the control from LogonForm to ProcessForm and close the LogonForm (only).

//Instantiate ProcessForm and Show ProcessForm
MyProcessForm = new ProcessForm(InputData);
MyProcessForm.Show();

//Close the Logon Form
this.Close();

This code actually closes the entire application without showing the ProcessForm.

Now, if I change this.Close() to this.Hide(), the ProcessForm opens, but when I close the ProcessForm, I can see the application still running as the "LogonForm" is still in the hidden state.

When I close the ProcessForm, I have to close the entire application. Can you please help me with how to do it? Thanks in advance for your help

推荐答案

您好,

是的,第一个表单是主表单,关闭它会结束应用程序.
如果您正在使用C#工作,请看一下program.cs中的Main();您会看到您的第一个表单将得到不同的处理,它将传递给Application.Run.您可以使program.cs适应于两个Application.Run语句,一个带有登录表单,另一个带有您的真实主表单.

OTOH Application.Exit()无论如何都应终止您的应用程序.

:)

Hi,

Yes the first form is the main form, closing it ends the app.
If you are working in C#, have a look at Main() in program.cs; you''ll see your first form is treated differently, it is passed to Application.Run
You could adapt program.cs to have two Application.Run statements, one with the logon form, the next with your real main form.

OTOH Application.Exit() should terminate your app no matter what.

:)


当主窗体关闭时,它将停止消息循环,您的应用程序将结束.您需要更改main方法并执行类似的操作,
When the main form closes, it will stop the message loop and your application will end. You need to change the main method and do something like,
int main()<br />{<br />     // show the login form here. <br />     if(loginValidated)<br />     {<br />         // starts the application message loop<br />         Application.Run(new ProcessForm());<br />         /* .... */<br />     }<br />}






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

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