如何触发Control.Resize事件而不需要实际调整大小? [英] How to trigger an Control.Resize event without actually resizing?

查看:154
本文介绍了如何触发Control.Resize事件而不需要实际调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是对控件进行子类化。尝试通过 Control.Size = Control.Size 触发事件,因为即使没有新的大小实际上不同,它也不会触发。

解决方案

如果您是子类化 Control ,可以调用 OnResize 直接或公开在API上:

  public void OnResize(){
this.OnResize (EventArgs.Empty);
}

但是,您无法为任意控件执行此操作。您可以更改大小来回?或者,你可以使用反射,但是这是很奇怪的:

  typeof(Control).GetMethod(OnResize,
BindingFlags.Instance | BindingFlags.NonPublic)
.Invoke(myControl,new object [] {EventArgs.Empty});


I'm not subclassing the control. Trying to trigger the event via Control.Size = Control.Size fails, since it does not trigger then even unless the new size is actually different.

解决方案

If you are subclassing Control, you can call OnResize directly, or expose it on the API:

 public void OnResize() {
     this.OnResize(EventArgs.Empty);
 }

However, you can't do this for arbitrary controls. You could change the Size to-and-fro? Alternatively, you could use reflection, but that is hacky:

 typeof (Control).GetMethod("OnResize",
     BindingFlags.Instance | BindingFlags.NonPublic)
     .Invoke(myControl, new object[] {EventArgs.Empty});

这篇关于如何触发Control.Resize事件而不需要实际调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆