" ResizeEnd"相当于为用户控件控件、用户、QUOT、ResizeEnd

2023-09-03 00:33:26 作者:彼岸·灯火阑珊

我写一个用户控件。我想提请用户控件时调整大小完成。我无法找到任何事件等效的Windows窗体为ResizeEnd。

有任何同等事件的用户控件?

  

请注意,在这种情况下,用户控件的父控制是   本身就是一个用户控件,所以我不能   转换(父用户控件)成   表单。由于我使用了一个框架,我   不能访问此形式   用户控制将被显示。的

解决方案

没有等同。表单有模式大小循环,开始当用户点击边缘或形式的一个角落里。子控件不能调整大小的方式,它只能看到更改其Size属性。

添加一个集束性,以你的用户控件解决这个问题。该表格​​可以很容易地从OnResizeBegin /结束分配()覆盖。继在UC的Load事件Parent属性,直到找到表也是可能的:

 公共BOOL调整大小{获得;组; }

私人无效UserControl1_Load(对象发件人,EventArgs的){
  如果(!this.DesignMode){
    VAR父= this.Parent;
    而(!(父母是表))母公司= parent.Parent;
    VAR形式=父母为表;
    form.ResizeBegin + =(S,EA)=> this.Resizing = TRUE;
    form.ResizeEnd + =(S,EA)=> this.Resizing = FALSE;
  }
}
 

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.

UI模块 tab选项卡 分段控件和它们的好朋友...

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;
  }
}