在某些情况下,如何在不打开第一个表单的情况下关闭第二个表单? [英] In some condition How can I close second form without open first form?

查看:33
本文介绍了在某些情况下,如何在不打开第一个表单的情况下关闭第二个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我无法解决.请帮助我.

I have a problem and I couldn't solve it.please help me.

我有两个 C# 窗体,主窗体和用户密码窗体.首先我使用主表单,如果用户使用用户名和密码,当用户输入正确的用户名和密码时,主表单调用userpassword表单,可以使用主表单但是当用户输入错误的用户名和密码时,她/他不能使用主窗体,现在用户想要关闭程序,但在此级别用户使用 closeBox 关闭程序,但程序打开主窗体.这对我来说是个问题,因为用户无法输入正确的用户名和密码,但现在她/他可以使用主窗体.

I have two windows form in C#,main form and userpassword form. at first I use main form, if user are using username and password,the main form calls userpassword form when user enters correct username and password, can use main form but when the user enter incorrect username and password, she /he can't use main form and now the user want to close the program but in this level user closes program with closeBox,but program opens main form.and it 's problem for me because user couldn't enter correct username and password but now she/he can use main form.

为了解决这个问题,我使用了 application.Exit();在 FormClosed 事件中,我的第一个问题解决了,但之后我又遇到了另一个问题.因为当我输入正确的用户名和密码时,当用户密码表单关闭时,所有应用程序都关闭了,因为我使用了 application.Exit();在 FormClosed 事件中.

to solve this problem I used application.Exit(); in FormClosed event,my frist problem solved but after that I have another problem.because when I entered correct username and password , when userpassword form closed, all application closed because I use application.Exit(); in FormClosed event.

现在你对我有什么建议?

now what do you suggest to me?

推荐答案

使用 if 语句检查他们是否输入了正确的用户名和密码,如果他们没有输入正确的用户名和密码,则只调用 Application.Exit()....

Use an if statement that checks if they entered the correct username and password, and only call Application.Exit() if they didn't....

这篇关于在某些情况下,如何在不打开第一个表单的情况下关闭第二个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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