C# 隐藏或处理表格
我有一个C# 隐藏或处理表格,c#,winforms,hide,dispose,C#,Winforms,Hide,Dispose,我有一个main表单,从main表单我调用确认表单 using (var f = new ConfirmationForm()) f.ShowDialog(); 然后在确认表单中,我想显示另一个用户列表表单 if (ConfirmSuccess) { this.Hide; //or this.Close using (var f = new UsersListForm()) f.ShowDialog(); } 现在,当ConfirmSuccess等于true时
main表单
,从main表单
我调用确认表单
using (var f = new ConfirmationForm())
f.ShowDialog();
然后在确认表单
中,我想显示另一个用户列表表单
if (ConfirmSuccess)
{
this.Hide; //or this.Close
using (var f = new UsersListForm())
f.ShowDialog();
}
现在,当ConfirmSuccess等于true时,MainForm
也将Hide
或Close
如何防止
主窗体
不隐藏
或关闭
?有什么想法吗?提前谢谢。
更新:我的问题是解决。我首先调用
UsersListForm
并从UsersListForm
的加载事件调用确认表单,然后使用DialogResult==System.Windows.Forms.DialogResult.OK
现在一切都好了:)如果您想在打开主表单之前请求用户确认,最好的方法是,在创建表单后调用确认表单并调用MainForm。
如果您打算在应用程序开始时寻求确认,请将call ConfirmationForm放在application.Run(new MainForm())之前的程序类中
静态类程序
{
///
///应用程序的主要入口点。
///
[状态线程]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ConfirmationForm confForm=新的ConfirmationForm();
confForm.ShowDialog();
运行(新的MainForm());
}
}
但是,如果打算在单独的调用点中请求应用程序内的验证,则应使用ShowDialog调用确认表单,然后调用所需表单
但是,如果您确实想用打开的表单验证请求并将其隐藏,则可以使用ConfirmationForm的DialogResult属性通过比较(
ConfirmationForm.ShowDialog()==DialogResult.OK
)返回验证的成功或失败。请参见显示MainForm的整个函数,其中显示了确认表单。在使用中的最后一个语句之后,您正在使用using(){}它将处理您的f这是您想要的还是不想要的?它只是一个单击事件private void usersToolStripMenuItem\u单击(对象发送方,事件参数e){using(var f=new ConfirmationForm())f.ShowDialog();}
sir@Jordy,即使我们不使用using(){}
我的问题仍然存在。但我想在UserListForm打开之前隐藏或关闭确认表单:)实际上,我已经在从LoginForm到MainForm中使用了这个技巧。然后我应用了你的建议,确认表仍然有效。
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ConfirmationForm confForm = new ConfirmationForm();
confForm.ShowDialog();
Application.Run(new MainForm());
}
}