简体   繁体   English

在用户输入文本之前停止程序流程(c#)

[英]Stopping the flow of program until the user has entered text(c#)

I have a program which displays a dialog box(which is a new form). 我有一个程序显示一个对话框(这是一个新的表单)。

Now what i want is to stop the execution of the program until user has entered password and pressed Ok Button on the other form. 现在我想要的是停止执行程序,直到用户输入密码并在另一个表单上按下Ok Button。

Problem is whenever i display the dialog box. 问题是每当我显示对话框时。 The underlying program doesnt stop execution and continues anyway. 底层程序不会停止执行并继续。

How can i stop the execution of program until user has entered username and password and submitted them to the main form. 如何在用户输入用户名和密码并将其提交到主表单之前,如何停止程序的执行。

Use otherForm.ShowDialog() method when displaying other form to user: 在向用户显示其他表单时使用otherForm.ShowDialog()方法:

using(var otherForm = new OtherForm())
{
    var result = otherForm.ShowDialog(); // main form stops here
    if (result == DialogResult.OK)
    {
        // user entered text and pressed OK button on other form
    }
}

Form.ShowDialog method shows the form as a modal dialog box . Form.ShowDialog方法将窗体显示为模式对话框 When this method is called, the code following it is not executed until after the dialog box is closed. 调用此方法时,直到关闭对话框后才会执行其后面的代码。

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

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