如何正确处理居中的MDI表单背景图像
我有一个带有居中背景图像的 MDI 表单。
每次用户更改表单的大小或状态时,图像根本不会更新。它保留在原来的位置(不再居中),甚至当表格太小时会丢失。
如何正确处理这种情况?
我真的必须在与表单大小和状态相关的所有事件处理程序中调用“this.Refresh()”吗?
应用程序是在.net 3.5SP1 C# 和 Windows.Forms 中实现的。
I have an MDI form with a centered background image.
Each time the user changes the size or state of the form, the image isn't updated at all. It remains in the old place (not centered any more) and is even lost when the form is made too small.
How can this situation correctly be handled?
Do I really have to call "this.Refresh()" in all event handlers related to form size and state?
Application is realized in .net 3.5SP1 C# with Windows.Forms.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不幸的是,似乎没有一种超级快速的方法可以做到这一点,但以下是我的解决方案,至少似乎不依赖于巧合。
在 mdi 构造函数中,处理调整大小:
然后此重写来处理最大化/恢复事件
常量值定义为:
Unfortunately there doesn't seem to be a super-quick way to do this, but the following is my solution and at least doesn't seem to rely on coincidences.
In the mdi constructor, handle resizing:
And then this override to handle maximize/restore events
Constant values are defined as:
您可以执行所有这些操作,也可以将
me.refresh
放入 MDI 的resize
事件中。You could do all of that, or you could just put a
me.refresh
in the MDI'sresize
event.在 MDI 表单的 Resize 事件中调用 PositionContainersToParentMiddle 方法。
我还没有测试过,但它应该可以工作。您可能必须在调整大小事件中添加条件,以在每次调整大小时停止图像位置更改。
Call PositionContainersToParentMiddle method in Resize event of your MDI form.
I have not tested it, but it should work. You might have to put conditions in Resize event to stop Image location change at every resize.