简体   繁体   English

打开一个Win窗体,但在另一个窗体打开时将其停用

[英]Open a Win Form but keep it deactivated while another Form opens

I have a simple WinForm app. 我有一个简单的WinForm应用程序。 For a user to use the app, however, they must login. 但是,要使用户使用该应用程序,他们必须登录。 What I'm trying to do is: 我想做的是:

1) open the main form, 1)打开主窗体,

2) deactivate it, 2)停用它,

3) show the login form, 3)显示登录表单,

4) reactivate the main form once the login form is exited and authentication has completed successfully. 4)一旦退出登录表单并成功完成身份验证,请重新激活主表单。

I'm looking for some skeleton code just for handling the Win Forms behavior. 我正在寻找一些骨架代码,仅用于处理Win Forms行为。

在“ Shown”表单事件中,使用ShowDialog()使它成为应用程序的模式。

Here's a rough outline 这是一个粗略的轮廓

protected void MainForm_Activated(object sender, EventArgs e)
{
    LoginForm loginForm = new LoginForm();

    if (loginForm.ShowDialog() == DialogResult.OK)
    {
         // proceed with normal flow
    }
    else 
    {
         // let user retry logging in or exit application.
    }
}

and in LoginForm, set this.DialogResult = DialogResult.OK if login was successful; 如果登录成功,则在LoginForm中设置this.DialogResult = DialogResult.OK otherwise use this.DialogResult = DialogResult.Cancel 否则使用this.DialogResult = DialogResult.Cancel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM