我正在用C#创建一个模块化表单,想知道在关闭主表单上的用法时如何从模块化表单中检索数据?
答案 0 :(得分:1)
因为您使用ShowDialog
,所以可以使用using
块。如果您也将DialogResult设置为关闭,则可以确保仅在正确关闭时使用这些详细信息
//OnClosing...
DialogResult = DialogResult.OK;
using(var myFormInstance = new myForm())
{
myFormInstance.ShowDialog() //<-- Only if you dont need to check dlg result
//whilst in here myFormInstance will give me access to the variables
if(myFormInstance.ShowDialog() == DialogResult.OK) //<-If you do check result
{
//success
}
}
只需为要检索的值提供公共方法或属性,然后调用它们并相应地使用它们