停止程序的流程,直到用户输入的文本(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).
现在我想是停止程序的执行,直到用户输入的密码和pressed OK按钮其他形式。
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.
但问题是每当我显示该对话框。其基本程序犯规停止执行,反正继续。
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.
推荐答案
使用 otherForm.ShowDialog()
来显示用户的其他形式的方法时:
Use otherForm.ShowDialog()
method when displaying other form to user:
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 方法展示的形式为模式对话框的。当这个方法被调用时,code以下它不被执行后的对话框关闭,直到。
Form.ShowDialog method shows the form as a modal dialog box. When this method is called, the code following it is not executed until after the dialog box is closed.
这篇关于停止程序的流程,直到用户输入的文本(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!