使调整大小与窗口的特定宽度对齐
背景: 我有一个宽度为 240px 的窗口,一些视觉元素只能以特定的方式显示在这个宽度上,但是调整大小是允许的并且必须允许。
如果有人决定调整大小,那么我将需要某种“捕捉”来恢复到原始宽度。要求用户获得准确的像素以恢复完整的视觉效果将是一件痛苦的事/几乎不可能。
问题:那么,如果它们在任一方向上距离 240px 达到一定距离(比如说,4px 以内),我该如何做到这一点,它将捕捉到该宽度,并调整为不同的大小仅当调整大小光标偏离宽度超过 4px 时才调整大小。
失败的想法:我尝试过几种不同的方法,在 sizeChanged 事件上将窗口的宽度设置为 240(如果窗口宽度在 4px 之内) ,但由于这是关于大小事件的,因此它将在窗口大小调整后进行计算。这意味着当将其大小调整为/远离默认宽度时,您会得到非常不稳定的效果。
Background:
I have a window that starts out with a width of 240px, some visual elements can only be displayed a particular way at this width, however resizing is allowed and must be allowed.
If someone decides to resize, then i will need some sort of "Snap" to get back to the original width. It would be a pain/next to impossible to require the users to get the exact px right in order to restore full visual effects.
Question: So, how can i make it so if they get to a certain distance (lets say, within 4px) away from 240px in either direction, it will snap to that width, and resize to a different size only when the resize cursor has strayed over 4px away from the width..
Failed Ideas: ive played with several different things that set the width of the window to 240 on the sizeChanged event if its within the 4px, but since that is on the size event, it will do the calculations after the window has already resized. which means that you get a really choppy effect when it is being resized to/away from the default width.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下消息解释了如何通过在您自己的窗口过程中处理 WM_SIZING 消息来获得对大小调整的细粒度控制:
主持人的示例代码是用 VB 编写的,但有很多您可以使用 C#/WinForms 示例来入门。
Here is a message that explains how to gain fine-grained control over the resizing by handling the WM_SIZING message in your own window procedure:
The moderator's sample code is in VB but there are plenty of C#/WinForms examples you can use to get started.