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

定义

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

public:
 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.

private:
   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请使用事件而不是 Resize 事件。To handle custom layouts, use the Layout event instead of the Resize event. 事件是为了响应Resize事件而引发的,但也用于响应影响控件布局的其他更改。 LayoutThe 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.

适用于

另请参阅