卸载时自定义 Windows 窗体
我想在卸载时显示我的自定义 Windows 窗体。我将为此使用 C# 自定义操作。如何让自定义操作等到用户单击“确定”或“取消”?我希望我的自定义操作仅在表单关闭时完成。因此,在我的自定义操作中执行以下操作:
CollectUninstallData f = new CollectUninstallData();
f.Show();
return f.FormResult;
但是表单会闪烁一会儿,并且卸载会继续,而无需等待表单关闭。这是合乎逻辑的,因为 GUI 位于另一个线程中。但如何让它等待表单关闭呢?
我知道在安装包中显示自定义 Windows 窗体并不酷,因此如果有人可以提供更优雅的解决方案,那么我将感激地接受它。
I want to show my custom windows form on uninstall. I am going to use a C# custom action for this. How do I make the custom action wait till the user clicks OK or Cancel? I want my custom action to complete only when the form is closed. So do the following in my custom action:
CollectUninstallData f = new CollectUninstallData();
f.Show();
return f.FormResult;
But the form blinks for a moment and the uninstall continues without waiting for the form to close. And this is logical since the GUI is in another thread. But how do I make it wait for the form to close?
I am aware that showing custom windows forms in install packages isn't cool, so if anyone can offer a more elegant solution, then I will thankfully accept it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用
ShowDialog()
方法而不是Show()
。后者使表单可见并返回控制权,这就是您的自定义操作停止执行的原因。前者将表单显示为模式对话框,并且直到用户以任何方式关闭表单后才会返回。如果您想知道用户是否单击了“确定”或“取消”,请使用此语句
return r == DialogResult.OK ? 0:1。返回码为零通常表示成功,非零表示失败。
You have to use
ShowDialog()
method instead ofShow()
. The latter makes the form visible and returns control that's why your Custom Action stops its execution. The former shows the form as a modal dialog box and does not return until the user closes the form in any way.If you want to know whether user clicked OK or Cancel, use this statement
return r == DialogResult.OK ? 0 : 1
. Return code of zero usually indicates success and non-zero is for failure.