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 方法的 參數轉換成 senderControl 並個別取得其 Size 屬性 (或 HeightWidth 屬性) 。

若要處理自訂配置,請使用 Layout 事件,而不是 Resize 事件。 事件 Layout 會引發以 Resize 回應事件,但也回應影響控制項版面配置的其他變更。

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

適用於

另請參閱