tags:

views:

97

answers:

1

Hi, 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 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.

+1  A: 

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;
  }
}
Hans Passant
In may case parent form is also a user control. So I cannot cast the parent control into a form.
Ram
@Ram: that's why the while loop is there. Did you try it?
Hans Passant