次の方法で共有


Control.Resize イベント

定義

コントロールのサイズが変更されたときに発生します。

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

イベントの種類

次のコード例では、FormResize イベントを処理します。 フォームのサイズが変更されると、イベント ハンドラーはフォームが正方形 (その 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 パラメーターをControlにキャストし、そのSizeプロパティ (またはHeightプロパティとWidth プロパティ) を個別に取得します。

カスタム レイアウトを処理するには、Resize イベントの代わりに Layout イベントを使用します。 Layout イベントは、Resize イベントに応答して発生しますが、コントロールのレイアウトに影響を与えるその他の変更にも対応します。

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。

適用対象

こちらもご覧ください