-1

我正在尝试弹出一个输入框,要求用户输入类似于messagebox.show. 但我希望用户能够在框中输入内容,以便我可以使用返回数据进行验证。

系统将检查用户是否已通过身份验证,否则将通过弹出窗口请求身份验证。

4

2 回答 2

1

假设您在 WinForms 中,您需要做的是创建一个新表单,为其添加一个文本框和按钮,然后在未通过身份验证时调用它。

public partial class Form1
{
    public void Main()
    {
    bool authenticated = ...

    if(!authenticated)
    {
       Your_Form newForm = new Your_Form();
       newForm.Show(this);
       string password = newForm.Password;
       if(password != "")
           ...
    }
    }
    }

public class Your_Form
{
public TextBox textBox1 = new TextBox();
// ...
public string Password = "";

private void button1_Click(object sender, EventArgs e)
{
   this.Password = textBox1.Text;
}
// ...
}
于 2013-01-13T21:45:57.597 回答
0

我将不得不假设您使用的是 Winforms,但此代码也可以转换为 WPF 或 web。您需要DisplayDialog()从您的父表单中使用,以显示您的辅助表单,即弹出窗口。这会将您的新表单显示为对话框。最重要的是,当它关闭时,它总是向父表单发送回一个DialogResult在此处此处解释),您可以使用它来确定用户是否已通过身份验证。 这篇文章解释了如何做一些与我认为你想要的非常相似的事情

于 2013-01-13T21:49:14.560 回答