Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ResizeEnd" equivalent for usercontrols

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.

like image 468
Ram Avatar asked Apr 05 '10 10:04

Ram


1 Answers

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:

public bool Resizing { get; set; }

private void UserControl1_Load(object sender, EventArgs e) {
  if (!this.DesignMode) {
    var parent = this.Parent;
    while (!(parent is Form)) parent = parent.Parent;
    var form = parent as Form;
    form.ResizeBegin += (s, ea) => this.Resizing = true;
    form.ResizeEnd += (s, ea) => this.Resizing = false;
  }
}
like image 78
Hans Passant Avatar answered Oct 18 '22 15:10

Hans Passant