使用隐藏标题栏最小化/恢复使 Windows 窗体窗口变大
在使用 SetWindowLongPtr 的 PInvoke 从可调节窗口中删除标题 (WS_CAPTION) 后,我在 Windows 窗体中遇到了此问题。此后,每当窗口最小化或最大化,然后恢复到正常时,它就会增长(通过 CaptionHeight + 边框)。
看来 Windows 窗体的布局机制正在尝试补偿它认为仍然存在的标题栏。 (如果我从 None 的 FormBorderStyle 开始并添加我想要的内容,即相当大的边框,我最终会遇到相反的问题,窗口缩小)。
我发现另外一个人在 codeplex 上遇到了 此问题, 但没有发布解决方案。
尝试在自定义处理程序中调整大小事件之一的大小都为时过早,即 Windows 窗体在 Layout、Resize 和 SizeChanged 事件触发后进行调整,并且如果没有标题栏,则 ResizeEnd 不会触发。无论如何,这只是一种解决方法,我想要一种方法来告诉 Windows 窗体做正确的事情。 有想法吗?
(我有一个可行的解决方法,我将很快发布,但最终用户可以看到。)
I hit this problem in Windows Forms, after using PInvoke of SetWindowLongPtr to remove the caption (WS_CAPTION) from a Sizable window. After that whenever the window is either Minimized or Maximized and then restored to Normal it grows (by the CaptionHeight + border).
It appears that Windows Forms' layout mechanism is trying to compensate for the caption bar that it thinks is still there. (If I start with a FormBorderStyle of None and add what I want, i.e. the sizable border, I end up with the opposite problem, the window shrinks).
I found one other person had hit this problem on codeplex,
but no solution was posted.
Attempts to adjust the size in a custom handler for one of the resizing events all are too early, i.e. Windows Forms makes its adjustments after Layout, Resize and SizeChanged events have fired and ResizeEnd does not fire if there is no Caption bar. This would just be a workaround in any case, I'd like a way to tell Windows Forms to do the right thing.
Ideas?
(I have a workaround that works, that I'll post shortly, but it is visible to the end user.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您按照 Windows 窗体的方式执行此操作,则效果很好。将此代码粘贴到您的表单中:
It works fine if you do this the Windows Forms' way. Paste this code into your form:
链接文本我的解决方案,由 Justin Rogers 引发Windows 窗体消息泵技巧:
BeginInvoke 将 ShrinkWindow 调用放在消息泵上;直接从 Resize 事件处理程序中调用它还为时过早
当标题栏不可见时,ResizeEnd 事件似乎不会触发。最终用户确实看到了这种增长和缩小,但它是
相当快。
link textMy solution, sparked by Justin Rogers Awesome Windows Forms message pump trick:
The BeginInvoke puts the ShrinkWindow call on the message pump; calling it directly from within the Resize event handler is too early
and the ResizeEnd event doesn't seem to fire when the caption bar is not visible. The end user does see this grow and shrink, but it's
pretty quick.