使用C# FormWindowState来恢复?
我想检测我的应用程序在某些情况下是否最小化,如果是,则需要恢复窗口。我可以轻松地做到这一点,如下所示:
if(this.WindowState == FormWindowState.Minimized) {
this.WindowState = FormWindowState.Normal;
}
但是,如果用户首先最大化表单,然后最小化它,会发生什么?我不知道是将 WindowState
设置为 FormWindowState.Normal
还是 FormWindowState.Maximized
。我可以检查是否有方法或 API 调用来解决此问题?
I'd like to detect if my application is minimized under certain situations, and if it is, the window needs to be restored. I can do that easily as follows:
if(this.WindowState == FormWindowState.Minimized) {
this.WindowState = FormWindowState.Normal;
}
However, what happens if the user first maximizes the form, then minimizes it? I don't know whether to set the WindowState
to FormWindowState.Normal
or FormWindowState.Maximized
. Is there a method or API call I can check to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
下面显示的代码可以满足您的需要。顺便说一句,覆盖用户的选择是非常不明智的。
The code shown below does what you need. Overriding the user's choice is pretty unwise btw.
我使用此解决方案以 MDI 形式恢复表单。首先,您必须定义:
当涉及到恢复时:
这会将表单恢复到之前的状态,而无需使用其他状态持有者。
另外,您可能会发现这篇文章很有趣
I use this solution to restore forms in MDI form. First you have to define:
and when it comes to restore:
This will restore form to the previous state without using additional state holders.
Also you may find this article interesting
我认为您应该能够调用
this.Show()
并且它将恢复到之前的(可见)状态。I think you should be able to call
this.Show()
and it will restore to the previous (visible) state.这是一种利用表单的 OnResize 方法 的方法
Here's an approach that utilizes the OnResize method of the form
https://stackoverflow.com/a/6837421/578731:
https://stackoverflow.com/a/6837421/578731:
我认为这是最好的选择(微软说):
I think this is the best option (Microsoft said):