WinForms - 调整大小事件后的操作
是否可以在(用户控件的)调整大小事件之后执行特定操作,例如释放鼠标按钮时?我需要手动调整内部控件的大小,并且在事件的每次触发时都执行此操作,嗯,效率低下......
Is it possible to perform a specific action after the resize event (of the user control), for example when mouse button is released? I need to manually resize an inner control and doing it on every single firing of the event would be quite, hmm, inefficient...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需使用
ResizeEnd
事件:来自 MSDN:
Just use the
ResizeEnd
event:From MSDN:
您可以像这样伪造本地 ResizeEnd:
可以修改间隔。它越高,最后一次调整大小事件之后的延迟就越多。
You can fake a local ResizeEnd like this:
The interval can be modified. The higher it is the more delay after the last resize event it will be.
一个简单的解决方案是重写表单中的 OnResize 并阻止它调用基本方法。
请在 OnResizeEnd 阶段开始时调用此基本方法。
最大化或恢复的表单只能在 OnResize 中检测到。
为了适应这种情况,您需要跟踪窗口状态并允许 OnResize 在其更改时继续进行:
另一方面,使用这样的代码应该是最后的手段。控件自然调整大小的问题通常表明设计/编码不当。
A simple solution is to override the OnResize in the form and prevent it calling the base method.
Call this base method at the start of the OnResizeEnd stage instead.
Forms being maximised or restored can only be detected in the OnResize.
To accommodate this, you need to track the window state and allow the OnResize to go ahead when it changes:
On another note, using code like this should be a last resort. Problems with controls resizing naturally would usually indicate bad design/coding.
如果您使用的是控件而不是表单,并且希望在调整大小完成后执行操作(用户停止调整控件大小),则还有另一种选择:
Another option if you are using a control and not a form and would like to perform actions after the resize has been completed (user stopped resizing control):
也许您可以使用 SizeChanged事件。但我不知道在调整大小期间调用它的频率或时间。
Maybe you can use the SizeChanged Event. But i don´t know how often or when it´s called during resizing.