如何在C Sharp中隐藏主要表格 [英] How to hide main form in c sharp

查看:84
本文介绍了如何在C Sharp中隐藏主要表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个员工出勤项目,但是我想设置一个密码和用户名.

如何防止主程序表单在登录前出现?

登录后如何隐藏登录表单?

I made a Staff Attendance Project, but I want to set a password and user name.

How do I prevent main program form appearing before login?

And after login how to hide the login form?

推荐答案

最简单的方法是处理主表单的Form.Load事件. 添加:
The simplest way is to handle the Form.Load event of your main form.
Add:
formLogin fl = new FormLogin();
do
   {
   if (fl.ShowDialog() == DialogResult.Cancel)
      {
      Close();
      return;
      }
   } while (!LoginOK(fl.Username, fl.Password));

这将在用户登录时暂停加载主表单,并在取消表单时将其关闭.

假定您的登录表单具有适当的属性,并且您编写了LoginOK方法来检查用户详细信息.

That will suspend loading the main form while the user logs in, and close the form if they cancel it.

It assumes your login form has appropriate properties, and you write a LoginOK methods to check the user details.


这个问题经常被问到变得无聊.

如果您在询问之前搜索过该论坛,则可能会找到登录表单 [
This question is asked so often that it is getting boring.

If you had searched this forum before asking you might have found Login form [^] question and it''s answers and wouldn''t have needaed to ask.


关于
About 350 000 answers[^] - seems like somebody got this one fixed long ago :)

Best regards
Espen Harlinn


这篇关于如何在C Sharp中隐藏主要表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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