Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 弹出式输入框_C#_Winforms_Visual Studio 2010 - Fatal编程技术网

C# 弹出式输入框

C# 弹出式输入框,c#,winforms,visual-studio-2010,C#,Winforms,Visual Studio 2010,我正在尝试弹出一个输入框,要求用户输入类似于messagebox.show的密码。但我希望用户能够在框中键入内容,以便使用返回数据进行验证 系统将检查用户是否已通过身份验证。如果未通过身份验证,系统将通过弹出窗口请求身份验证。假设您使用WinForms,您需要做的是创建一个新表单,添加一个文本框和按钮,然后在未经身份验证的情况下调用它 public partial class Form1 { public void Main() { bool authenticated

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


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

假设您使用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;
}
// ...
}

我不得不假设您使用的是Winforms,但这段代码也可以转换为WPF或web。您需要使用父窗体中的
DisplayDialog()
,以显示作为弹出窗口的辅助窗体。这将以对话框的形式显示新表单。最重要的是,当它关闭时,它总是向父窗体发回一个
对话框result
(解释和),您可以使用它来确定用户是否经过身份验证。
这篇文章解释了如何做一些非常类似于我所想的事情

Web、WinForm、WPF?平台是什么?到目前为止您已经尝试了什么?类似的事情可以通过简单的谷歌搜索来实现。这里是一个链接,您可以作为初学者使用。。在下面的
C#winforms上进行谷歌搜索如何创建自定义登录表单
非常感谢CC Inc.非常有用!