【发布时间】:2015-08-27 01:37:50
【问题描述】:
我是 C# 新手。我正在尝试在 textbox1 中输入密码以登录我的表单。此登录按钮启用某些控件。这行得通。这是问题开始的地方。我也做了一个更改密码部分,我在 textbox2 中输入旧密码,在 textbox3 中输入新密码并在 textbox4 中确认密码。我想要的是从 textbox3 或 textbox4 更新密码,然后设置为密码。因此,在 textbox3 或 textbox 4 中输入的任何内容现在都是密码。当我在 textbox1 中输入这个新更改的密码时,它会登录。我已经尝试了所有我能想到的方法,但没有解决方案。这是我正在使用的代码。
private void button14_Click(object sender, EventArgs e) // Main Screen Password Login Button
{
String passWord;
passWord = "login";
if (textBox1.Text == passWord)
{
passWord = textBox3.Text;
// textBox1.Clear();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
button6.Enabled = true;
button7.Enabled = true;
button8.Enabled = true;
button9.Enabled = true;
button10.Enabled = true;
button11.Enabled = true;
button12.Enabled = false;
button16.Enabled = true;
button16.Visible = true;
button20.Enabled = true;
numericUpDown1.Enabled = true;
numericUpDown2.Enabled = true;
button14.Click += ResetTimer;
}
else
{
MessageBox.Show("Password is Incorrect");
textBox1.Clear();
}
}
private void button19_Click(object sender, EventArgs e) // Admin Confirm Old Password Button
{
// String passWord;
// passWord = textBox2.Text;
if (textBox1.Text == textBox2.Text)
{
//MessageBox.Show("Password is Correct");
textBox3.Enabled = true;
textBox4.Enabled = true;
}
else
{
MessageBox.Show("Password is Incorrect");
}
private void button17_Click(object sender, EventArgs e) // Admin Update New password Button
{
String passWord;
//passWord = textBox3.Text;
// passWord = textBox3.Text;
// passWord = textBox4.Text;
if(textBox3.Text == textBox4.Text)
{
passWord = textBox3.Text;
MessageBox.Show("Password Changed");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox3.Enabled = false;
textBox4.Enabled = false;
}
else
{
MessageBox.Show("Password Does Not Match");
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox3.Enabled = false;
textBox4.Enabled = false;
}
button17.Click += ResetTimer;
}
因此,当我单击 button17 时,我希望密码更改为 textbox3 或 textbox4 中输入的任何内容。然后,这个新密码将用于在 textbox1 登录。我希望我正确地描述了我的问题。任何帮助都感激不尽。谢谢你。 詹妮弗。
【问题讨论】:
-
首先,我建议将所有控件重命名为有意义的名称,例如 oldPasswordTextBox、newPasswordTextBox 和 confirmPasswordTextBox。它将使您的代码更具可读性。
-
@juharr 是的,我讨厌 someControl1。
标签: c#