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.
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With