How to trigger an Control.Resize event without actually resizing?
24,152
Solution 1
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});
Solution 2
I always do this by calling the Control's Resize event handler:
control_Resize(null, null);
Author by
mafu
Updated on December 19, 2020Comments
-
mafu over 3 years
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. -
mafu over 15 yearsReflection would be possible, but it's probably an overkill and also feels really ugly.
-
user3147973 about 4 yearsThis is incorrect. Setting a new Size does not issue a resize event for that control.