Control.Resize Control.Resize Control.Resize Control.Resize Event


在调整控件大小时发生。Occurs when the control is resized.

 event EventHandler ^ Resize;
public event EventHandler Resize;
member this.Resize : EventHandler 
Public Custom Event Resize As EventHandler 


下面的代码示例中处理Resize事件的FormThe following code example handles the Resize event of a Form. 在窗体的大小调整,事件处理程序将确保窗体仍方形 (其HeightWidth保持相等)。When the form is resized, the event handler ensures that the form stays square (its Height and Width remain equal). 若要运行此示例,请确保并将此事件处理方法与窗体的Resize事件。To run this example, make sure and associate this event-handling method with the form's Resize event.

   void Form1_Resize( Object^ sender, System::EventArgs^ /*e*/ )
      Control^ control = dynamic_cast<Control^>(sender);

      // Ensure the Form remains square (Height = Width).
      if ( control->Size.Height != control->Size.Width )
         control->Size = System::Drawing::Size( control->Size.Width, control->Size.Width );
private void Form1_Resize(object sender, System.EventArgs e)
   Control control = (Control)sender;
   // Ensure the Form remains square (Height = Width).
   if(control.Size.Height != control.Size.Width)
      control.Size = new Size(control.Size.Width, control.Size.Width);
Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize

   Dim myControl As Control
   myControl = sender

   ' Ensure the Form remains square (Height = Width).
   If myControl.Size.Height <> myControl.Size.Width Then
      myControl.Size = New Size(myControl.Size.Width, myControl.Size.Width)
   End If
End Sub


若要确定Size调整大小后的控件,可以强制转换sender的已注册的参数ControlEventHandler方法Control并获取其Size属性 (或HeightWidth属性单独)。To determine the Size of the resized control, you can cast the sender parameter of the registered ControlEventHandler method to a Control and get its Size property (or Height and Width properties individually).

若要处理自定义布局,请使用Layout而不是调整大小事件的事件。To handle custom layouts, use the Layout event instead of the Resize event. Layout在响应中引发事件Resize事件,也可以在响应会影响控件的布局的其他更改。The Layout event is raised in response to a Resize event, but also in response to other changes that affect the layout of the control.

有关处理事件的详细信息,请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.