我在 C#.Net 中编写了一个 WinForms 程序,以在密码表单中以编程方式单击按钮。
Form1
加载并显示Form2
为对话框。
如果 DialogResult 不是 DialogResult.OK,应用程序将关闭。
到目前为止,我有一个按钮点击事件,代码如下:
if (txtpass.Text == "")
{
MessageBox.Show("You need to enter a password", "Password", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
txtpass.Focus();
}
else
{
if (txtpass.Text == "1234")
{
radButton1.DialogResult = DialogResult.OK;
radButton1.PerformClick();
}
else
{
MessageBox.Show("Password Incorrect", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtpass.Text = "";
txtpass.Focus();
}
}
我使用radButton1.PerformClick();
,但运行程序会给我以下消息:
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
我不确定是什么导致这个异常抛出。