通过


Control.Resize 事件

定义

调整控件大小时发生。

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

事件类型

示例

下面的代码示例处理 Resize 一个 Form. 调整窗体大小后,事件处理程序可确保窗体保持正方形(其 Height 保持 Width 相等)。 若要运行此示例,请确保将此事件处理方法与表单 Resize 的事件相关联。

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调整大小的控件,可以将已注册ControlEventHandler方法Control的参数强制转换为sender并单独获取其Size属性(或Height属性Width)。

若要处理自定义布局,请使用 Layout 事件而不是 Resize 事件。 事件 Layout 是在响应 Resize 事件时引发的,但也响应影响控件布局的其他更改。

有关处理事件的详细信息,请参阅 处理和引发事件

适用于

另请参阅