我的应用程序有两种不同的形式;
- 主要申请表
- 另一种显示警告,信息,错误等的消息(仅在需要时显示)。
在表单1(应用程序的主表单)中,第二行的表单如下所示;
FormMain:
...
if (sth_goes_wrong) {
this.formWarn = new FormWarn("explanatory message...");
this.formWarn.Dispose(); // <- this is the line in question
}
...
FormWarn:
internal class FormWarn : Form {
...
public FormWarn(String msg) {
this.SetupStuff();
this.btnOk.Click += FormWarn_BtnOkClick;
...
this.ShowDialog();
}
private FormWarn_BtnOkClick(Object sender,EventArgs e) {
...
this.Close();
}
...
}
警告形式显示为“对话框”,并且用户在阅读消息后,应该按下按钮(btnOk),该按钮将程序流发送到使用Close()
方法的一行。
我的问题是; (在Close()
类中的FormWarn
方法是否负责释放资源,还是返回主表单后我需要使用Dispose()
方法?