【发布时间】:2011-01-17 07:56:51
【问题描述】:
我在 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
我不确定是什么导致这个异常抛出。
【问题讨论】:
-
忘记添加了,这段代码在它试图模拟的按钮内
-
你能发布更多关于你想要做什么的信息吗?从本质上讲,您似乎以错误的方式解决问题,因此您的问题。如果我们知道您要做什么,也许可以提出更好的方法。
标签: c# button click stack-overflow simulate