“调整大小结束”相当于用户控件
我正在写一个用户控件。我想在调整大小完成后绘制用户控件。我无法找到任何相当于 Windows 窗体的“ResizeEnd”的事件。
用户控件是否有等效的事件?
请注意,在这种情况下,用户控件的父控件本身就是一个 UserControl,因此我无法将其(父用户控件)转换为表单。由于我正在使用框架,因此我无法访问将显示此用户控件的表单。
I am writing a UserControl. I want to draw the user control when the resize is done. I am not able to find any event equivalent to "ResizeEnd" of a windows form.
Is there any equivalent event for user controls?
Please note that in this case the parent control of the user control is itself an UserControl, so I cannot convert it (parent user control) into a form. As I am using a framework, I cannot access the form on which this user control will be displayed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有同等的。表单具有模态大小调整循环,当用户单击表单的边缘或角落时启动。子控件无法以这种方式调整大小,它只能看到其 Size 属性的更改。
通过向用户控件添加 Sizing 属性来解决此问题。表单可以轻松地从其 OnResizeBegin/End() 覆盖中分配它。跟踪 UC 的 Load 事件中的 Parent 属性,直到找到 Form 也是可能的:
There is no equivalent. A form has a modal sizing loop, started when the user clicks the edge or a corner of the form. Child controls cannot be resized that way, it only sees changes to its Size property.
Solve this by adding a Sizing property to your user control. The form can easily assign it from its OnResizeBegin/End() overrides. Following the Parent property in the UC's Load event until you find the Form is possible too:
Hans 解决方案正在工作(看起来这是唯一的方法),但它需要每种形式的这些处理程序,这些处理程序使用您的控件(这并不总是可以接受的)。
因此,您可以使用简单的解决方法,在调整大小时启动计时器。
每次更改大小时,您的计时器都会重新启动。并且只有当一段时间(_timer.Interval)没有大小变化时,它才会调用 ResizeFinished() 方法。
如您所见,您的代码仅在上次大小更改调用后 500 毫秒后才会被调用。
The Hans solution is working (and it looks like it is the only way to do it), but it's requires these handlers in every form, which using your control (which is not always acceptable).
So, you can use simple workaround, starting timer when resizing occurs.
Every time size will be changed your timer will be restarted. And only when there will be no size changes for some time (_timer.Interval) it will invoke ResizeFinished() method.
As you can see, your code will be invoked only after 500 ms after last size changed invocation.