显示恢复按钮而不显示最大化按钮
我想阻止用户将 Windows 窗体最大化为全屏,因此我禁用了“最大化”按钮。 但是,我希望能够让用户“恢复”表单。 当他们单击“恢复”按钮时,我希望它显示一个不同的、更小的、缩小的表单,这将向他们显示一个最大化按钮,该按钮将返回到原始表单。
有没有办法做到这一点?
谢谢。
编辑: 您不明白,我并没有阻止用户调整表单大小。 发生的情况是,当单击“恢复”按钮时,它将隐藏表单并打开一个控件较少的新表单。 当他们在较小的窗体上单击最大化时,它将返回到原始窗体。
I want to prevent the user from maximizing the Windows Form to full screen so I have disabled the Maximize button. However, I want to be able to have the user 'restore' the Form. When they click the Restore button I want it to show a different, smaller, minified, form, which will show them a maximize button which will return the use to the original form.
Is there a way to do this?
Thanks.
edit:
You don't understand, I'm not preventing the user from resizing the form. Whats happening is when the click the restore button, it will hide the form and open a new one with less controls on it. When they click maximize on the smaller form, it will return to the original form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在工作中遇到了与此类似的问题,我能找到的唯一解决方案涉及设置未记录的窗口样式,但我不愿意这样做。
因此,我认为解决您的问题的最佳解决方案是隐藏当前的最小化/最大化/恢复按钮并使用一些ownerdraw或其他命令添加您自己的按钮。
从用户交互的角度来看,我希望最小化/最大化/恢复按钮对您的应用程序执行与对所有其他应用程序执行的操作完全相同的操作。 覆盖该功能会给您的用户带来困惑,因此我建议在标题栏或界面上的其他位置创建不同的按钮来执行此功能。
I looked at a similar problem to this at work and the only solutions I could find involved setting undocumented window styles, which I was not inclined to do.
Therefore the best solution to your problem I would think would be to hide the current minimize/maximize/restore buttons and add your own using some ownerdraw or other commands.
Looking at this from a user interaction perspective I would want the minimize/maximize/restore buttons to do exactly the same thing for your application as they do for all others. Overriding that functionality would create confusion for your users, hence why I would recommend creating different buttons either on the title bar or somewhere else on your interface that perform this function.
您可以设置MaximumSize和MinimumSize并启用最大化按钮来获得这种效果。
You can set the MaximumSize and MinimumSize and enable the maximize button to get this kind of effect.
FWIW,正确的答案是使您的表单正确调整大小,适应任何窗口大小,而不是将用户限制在您的显示屏上以您的分辨率和< em>你的字体大小。 不可调整大小的窗口是我在应用程序中遇到的最烦人的事情之一(Windows 本身就充满了它们)。
FWIW, the right answer is to make your form resize properly, adapting to any window size and not to constrain the user to what looks right on your display at your resolution and your font size. Non-resizeable windows are one of the most annoying things I encounter in an application (Windows itself is full of them).
我最近也遇到了类似的情况,从UI设计的角度来看,在Windows Media Player中找到了一个很好的例子。 它保留了最小化、最大化和恢复按钮原样,并在右下角有一个单独的按钮用于“切换到紧凑模式”。 在迷你/紧凑模式下,同一按钮切换到“切换到完整模式”。 另一个替代示例是 Skype,它在标准最小化按钮左侧有一个额外的系统图标按钮,可在紧凑模式和标准模式之间切换。
(如果我有特权,我更愿意将其作为评论添加到 Daemin 接受的答案中,这对 StackOverflow 来说仍然相对较新)
I had a similar situation recently, and from a UI design perspective, found a good example in Windows Media Player. It leaves the Minimise, Maximise and Restore buttons as they are, and has a separate button on the bottom right for "Switch to Compact Mode". And in the mini/compact mode, the same button toggles to "Switch to Full Mode". Another alternative example is Skype, which has an additional system icon button just left of the standard minimise button, that toggles between Compact and Standard modes.
(If I had the privilege, I would've preferred to put this as a comment to add to Daemin's accepted answer, still relatively new to StackOverflow)
“恢复”表单会触发
Resize
事件,您可以在其中检查父表单是否不再是FormWindowState.Maximized
。 如果没有,您可以打开子窗体并隐藏父窗体。要扭转这种情况,您可以通过隐藏(或处置)子窗体来“最大化”子窗体,然后取消隐藏并将父窗体设置为
FormWindowState.Maximized
。我发现此方法的唯一问题是,在表单达到最大化状态之前,
Resize
事件可能会触发多次。 可能需要一个标志来忽略这些,直到表单从当前状态变为所需状态,这可能会导致无限循环。'Restoring' a form fires the
Resize
event where you can check if the parent form is no longerFormWindowState.Maximized
. If not, you can open the child form and hide the parent.To reverse this, you can 'maximize' the child form by hiding (or disposing) it, then un-hide and set the parent form to
FormWindowState.Maximized
.The only problem that I can see with this method is that the
Resize
event will likely fire several times before the form reaches a Maximumized state. A flag may be needed to ignore these until the form goes from the current state to the desired state, which can cause an infinite loop.