Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger an Control.Resize event without actually resizing?

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.

like image 896
mafu Avatar asked Feb 05 '09 10:02

mafu


2 Answers

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});
like image 140
Marc Gravell Avatar answered Sep 18 '22 09:09

Marc Gravell


I always do this by calling the Control's Resize event handler:

control_Resize(null, null);
like image 23
John Line Avatar answered Sep 22 '22 09:09

John Line