3

我尝试为表单设置密码,并使用标签、文本框和确定按钮制作了一个新表单,但是当我在文本框中输入密码时,它说密码不正确,而密码正确..有什么问题?

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!!");
        }
    }       
}
4

1 回答 1

2

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

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

而是这样做。

private void pass_TextChanged(object sender, EventArgs e)
{
  password = "mypass";
}
于 2013-11-09T22:54:57.403 回答