关闭登录表单并打开主表单 [英] close the login form and open main form

查看:84
本文介绍了关闭登录表单并打开主表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i有一个表单作为输入ID和密码的登录表单。

如果用户输入正确的id / pass,我想关闭登录表单并打开主表单。

怎么做?

i写了这段代码,但两个表格都关闭了!!



hi i have a form as login form for enter ID and Password.
if user enter correct id/pass,i want to close the login form and open the main form.
how to do that?
i wrote this code but both forms closed!!

if(//check ID/pass in DB......)
{
this.close();
form2 frm=new form2();
frm.showDialog();
}

请帮助,最好的问候

推荐答案





试试这段代码:

Hi,

try this code:
if(//check ID/pass in DB......)
{
this.Hide();
form2 frm=new form2();
frm.ShowDialog();
this.Show();
}


问题出在登录表格的结束语中。

我的建议是从其他地方拨打登录表格(例如主要方法)如果登录成功,那么你应该拨打所需的表格。

以此代码为例:

problem is in closing statement of login form.
My advice is to call login form from another place (Main method for instance) and if login is successful only then you should call required form.
Take this code as example:
//Application's entry point
[STAThread]
Main(string[]args)
{
    LoginForm loginFrm = new LoginForm();
    //if login successful proceed
    if(loginFrm.ShowDialog() == DialogResult.OK)
    {
        AnotherForm frm = new AnotherForm();
        frm.Show();
    }
    //if not, sorry no form. 
}


if(//check ID/pass in DB......)
{
this.close();
form2 frm=new form2();
frm.Show();
}


这篇关于关闭登录表单并打开主表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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