共用方式為


Control.Resize 事件

定義

當控制大小被調整時會發生。

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

事件類型

範例

以下程式碼範例處理ResizeForm事件。 當表單調整大小時,事件處理程序會確保表單保持方形(其 HeightWidth 保持相等)。 執行此範例時,請確保將此事件處理方法與表單的 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方法的參數鑄造sender到 aControl,並取得其Size屬性(或HeightWidth單獨取得屬性)。

要處理自訂版面配置,請使用 Layout 事件代替調整大小事件。 事件 Layout 不僅是針對事件 Resize 提出,也會因應影響控制配置的其他變更而提出。

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱