设置表单的密码

时间:2013-11-09 22:52:48

标签: c# passwords

我尝试为表单设置密码并使用lable,textbox和ok按钮创建一个新表单但是当我在文本框中写入密码时,它说密码正确时它是不正确的......问题是什么?

public partial class Password : Form
{
    private string password;
    public Password()
    {
        InitializeComponent();
    }

    private void pass_TextChanged(object sender, EventArgs e)
    {
      string password = "mypass";
    }

    private void okButton_Click(object sender, EventArgs e)
    {
        if (passtextBox.Text == password)
        {
            list form = new list();
            form.Show();
        }
        else
        {
            MessageBox.Show("Incorrect Password. Try Again!!");
        }
    }       
}

1 个答案:

答案 0 :(得分:2)

问题是这是创建一个局部变量字符串。

private void pass_TextChanged(object sender, EventArgs e)
{
  string password = "mypass";
}

而是这样做。

private void pass_TextChanged(object sender, EventArgs e)
{
  password = "mypass";
}