在 VB.NET 中以动画方式调整窗体大小
我的桌面窗口右下角的任务栏/系统托盘上方有一个表单。 这有点像弹出通知。 通知本身看起来很棒,但它上面有一个按钮,可以向上调整表单大小,以 5 像素的增量动画调整大小,同时保持其相对于屏幕右下角的位置。
这样做的问题是它看起来不太光滑。 调整 Me.Width 从左侧调整大小,因此您必须使用 Me.Left 将表单向左移动以进行补偿。 Me.SetBounds 似乎只是设置这些属性的包装器。
我可以做些什么来使表单顺利(或至少看起来)从表单左侧向外调整大小?
I have a form positioned slightly above the taskbar/system tray in the bottom right corner of my desktop window. It's sort of like a pop-up notification. The notification itself looks great, but there's a button on it which resizes the form up, animating the sizing in increments of 5px whilst keeping it's position relative to the bottom-right corner of the screen.
The problem with this is that it doesn't look very smooth. Adjusting Me.Width resizes from the left so you have to then move the form to the left with Me.Left to compensate. Me.SetBounds just seems to be a wrapper for setting those properties anyway.
Is there anything I can do to have the form smoothly (or at least appear to) resize outwards from the left of the form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
预计到达时间:您实际上可以使用
SetBounds
来完成此操作,因为SetBounds
将委托给SetBoundsCore
,而SetBoundsCore
又将调用设置窗口位置
。 因此,SetBounds
将在内部真正一次性设置所有边界,并且窗口管理器将仅在设置所有属性后重绘窗口。另一种选择是导入
MoveWindow function
并使用它。 它在这里产生平滑的动画,因为它可以在告诉窗口管理器重绘窗口之前同时设置大小和位置。
我的测试代码如下所示(在 Reflector 的帮助下从 C# 通过 IL 转换为 VB):
ETA: You can actually do this using
SetBounds
, asSetBounds
will delegate toSetBoundsCore
which, in turn will invokeSetWindowPos
. SoSetBounds
will internally really set all bounds at once and the window manager will redraw the window only after all properties are set.Another option would be to import the
MoveWindow
function and use that instead. It produces a smooth animation here, as it can set size and position simultaneously before telling the window manager to redraw the window.My test code looked like this (converted from C# via IL to VB with help from Reflector):
我从未尝试过此操作,但是您是否尝试过将表单的 DoubleBuffer 属性设置为 True? 这将使绘图变得平滑。
I never tried this, but have you tried setting the DoubleBuffer property of the form to True? This should smooth the drawing.
您可以尝试减少像素步数,它也会增加到 1-2,5px 似乎需要调整大小很多,我可以看到这会显得不稳定。
You might try reducing the pixel steps it's incrementing down to 1-2 as well, 5px seems like a lot to be adjusting size, I could see how this could appear choppy.