将字符串变量从Visual Studio(C#)中的另一个形式更改
我可以得到一些帮助吗?我想在Visual Studio中制作一个应用程序,并且我创建了一个密码重置表单,我想在其中更改密码。但是,如何用Form2的NewPassword字符串从Form1中替换密码字符串变量?
form1:
namespace Aplicatie
{
public partial class Aplicatie : Form
{
public string Password = "123";
public Aplicatie()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
}
public void textBox2_TextChanged(object sender, EventArgs e)
{
}
public void textUsername_TextChanged(object sender, EventArgs e)
{
}
public void ButtonLogin_Click(object sender, EventArgs e)
{
if (textUsername.Text == "augnova001")
{
if (textPassword.Text == Password)
{
MessageBox.Show("Autentification Succesfull");
new Form2().Show();
this.Hide();
}
else
{
MessageBox.Show("ACCESS DENIED!");
MessageBox.Show("Have a great day!");
this.Close();
}
}
else
{
MessageBox.Show("ACCESS DENIED!");
MessageBox.Show("Have a great day!");
this.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
new PasswordReset().Show();
this.Hide();
}
public void textPassword_TextChanged(object sender, EventArgs e)
{
}
private void unhideButton_Click(object sender, EventArgs e)
{
if (textPassword.PasswordChar == '*')
{
hideButton.BringToFront();
textPassword.PasswordChar = '\0';
}
}
private void hideButton_Click(object sender, EventArgs e)
{
if (textPassword.PasswordChar == '\0')
{
unhideButton.BringToFront();
textPassword.PasswordChar = '*';
}
}
}
}
密码reset表格:
namespace Aplicatie
{
public partial class PasswordReset : Form
{
public PasswordReset()
{
InitializeComponent();
}
public void buttonReset_Click(object sender, EventArgs e)
{
Aplicatie app = new Aplicatie();
if (textOldPassword.Text == app.Password)
{
if (textNewPassword.Text == textRetypeNewPassword.Text)
{
Pass = textNewPassword.Text;
app.Password = Pass;
MessageBox.Show("The Password has been changed succesfully!");
}
else
{
MessageBox.Show("The Passwords do NOT correspond! Please Try Again... ");
}
}
else
{
MessageBox.Show("The old password is not correct! Please Try Again... ");
}
}
public void textOldPassword_TextChanged(object sender, EventArgs e)
{
}
public void textNewPassword_TextChanged(object sender, EventArgs e)
{
}
public void textRetypeNewPassword_TextChanged(object sender, EventArgs e)
{
}
}
}
Can I get some help? I wanna make an app in Visual Studio and I've created a password Reset Form in which I want to change the password. However, how can I replace the password string variable from the Form1 with the NewPassword string from Form2?
Form1:
namespace Aplicatie
{
public partial class Aplicatie : Form
{
public string Password = "123";
public Aplicatie()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
}
public void textBox2_TextChanged(object sender, EventArgs e)
{
}
public void textUsername_TextChanged(object sender, EventArgs e)
{
}
public void ButtonLogin_Click(object sender, EventArgs e)
{
if (textUsername.Text == "augnova001")
{
if (textPassword.Text == Password)
{
MessageBox.Show("Autentification Succesfull");
new Form2().Show();
this.Hide();
}
else
{
MessageBox.Show("ACCESS DENIED!");
MessageBox.Show("Have a great day!");
this.Close();
}
}
else
{
MessageBox.Show("ACCESS DENIED!");
MessageBox.Show("Have a great day!");
this.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
new PasswordReset().Show();
this.Hide();
}
public void textPassword_TextChanged(object sender, EventArgs e)
{
}
private void unhideButton_Click(object sender, EventArgs e)
{
if (textPassword.PasswordChar == '*')
{
hideButton.BringToFront();
textPassword.PasswordChar = '\0';
}
}
private void hideButton_Click(object sender, EventArgs e)
{
if (textPassword.PasswordChar == '\0')
{
unhideButton.BringToFront();
textPassword.PasswordChar = '*';
}
}
}
}
PasswordReset Form:
namespace Aplicatie
{
public partial class PasswordReset : Form
{
public PasswordReset()
{
InitializeComponent();
}
public void buttonReset_Click(object sender, EventArgs e)
{
Aplicatie app = new Aplicatie();
if (textOldPassword.Text == app.Password)
{
if (textNewPassword.Text == textRetypeNewPassword.Text)
{
Pass = textNewPassword.Text;
app.Password = Pass;
MessageBox.Show("The Password has been changed succesfully!");
}
else
{
MessageBox.Show("The Passwords do NOT correspond! Please Try Again... ");
}
}
else
{
MessageBox.Show("The old password is not correct! Please Try Again... ");
}
}
public void textOldPassword_TextChanged(object sender, EventArgs e)
{
}
public void textNewPassword_TextChanged(object sender, EventArgs e)
{
}
public void textRetypeNewPassword_TextChanged(object sender, EventArgs e)
{
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用密码表格创建事件,然后在密码表单中单击按钮时将其发送到调用表格。
儿童
呼叫表格
Create an event in the password form then when a button is clicked in the password form send it to the calling form.
Child form
Calling form
使密码变量静态
:
make Password variable static
like this: