我在表单上创建了一个按钮,我以编程方式为其设置了返回值,如下所示。首先是事件处理程序 psudocode,然后是对话结果返回的位置。
有一个默认属性可以在用户界面中设置按钮的返回行为,即对话框结果行为。在我的完整代码中,我看不到这个按钮的返回设置或修改的任何地方。
在执行代码期间第一次使用 buttonSaveSet_Click 事件处理程序进行测试(在调试模式下运行)时,尽管我单击了“设置”按钮,但返回的对话框结果值为“取消”。但是,我第二次执行该函数时,按相同的按钮,对话框结果返回为“是”。
似乎还有另一个地方正在修改对话框结果,我将该值设置在不正确的位置。
psudo code
private void buttonSaveSet_Click( object sender , EventArgs e )
{
setChars = new setChars();
//set the dr to yes.
buttonSaveSet.DialogResult = DialogResult.Yes;
// set the charCount
// set the rowCount
if ( conditional statement is true )
{
//return values;
}
else
{
//return nothing;
}
Close();
}
返回地点:
try
{
DialogResult dResult = setValPopup.ShowDialog();
SetChars sc = setValPopup.setChars;
int max;
if ( dResult == DialogResult.Yes )
{
if ( sc.set == true )
{
//do other work
}
}
}