Control.Resize 事件

定义

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

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

事件类型

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 为, ControlSize) 单独 (或和属性获取其属性 Height WidthTo 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. 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.

适用于

另请参阅