共用方式為


Control.SizeChanged 事件

定義

發生在 Size 屬性值變更時。

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

事件類型

範例

下列程式碼範例示範 SizeChanged 事件。 已提供控制項的 Button 實例,可以水準和垂直縮放。 NumericUpDown實例提供水準和垂直小數位數值。 名為OKButton 實例可用來設定控制項實例的 Button 縮放值。 每當控制項的大小變更時,就會呼叫與控制項事件相關聯的 SizeChanged 事件處理常式。 這個事件處理常式會顯示訊息方塊,指出控制項的大小已變更。

private:
   void RegisterEventHandler()
   {
      myButton1->SizeChanged += gcnew EventHandler( this, &MyForm::MyButton1_SizeChanged );
   }

   void MyButton2_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Set the scale for the control to the value provided.
      float scale = (float)myNumericUpDown1->Value;
      myButton1->Scale( scale );
   }

   void MyButton1_SizeChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      MessageBox::Show( "The size of the 'Button' control has changed" );
   }
private void RegisterEventHandler()
{
   myButton1.SizeChanged += new EventHandler(this.MyButton1_SizeChanged);
}

private void MyButton2_Click(object sender, System.EventArgs e)
{
   // Set the scale for the control to the value provided.
   float scale = (float)myNumericUpDown1.Value;
   myButton1.Scale(scale);
}

private void MyButton1_SizeChanged(object sender, System.EventArgs e)
{
   MessageBox.Show("The size of the 'Button' control has changed");
}
Private Sub RegisterEventHandler()
   AddHandler myButton1.SizeChanged, AddressOf MyButton1_SizeChanged
End Sub

Private Sub MyButton2_Click(sender As Object, e As EventArgs) 
   ' Set the scale for the control to the value provided.
   Dim scale As Single = CSng(myNumericUpDown1.Value)
   myButton1.Scale(scale)
End Sub

Private Sub MyButton1_SizeChanged(sender As Object, e As EventArgs)
   MessageBox.Show("The size of the 'Button' control has changed")
End Sub

備註

最好使用 Layout 事件來處理自訂配置。 事件 Layout 會在回應 Resize 事件時引發,但在可能需要套用版面配置時,也會在其他狀況中引發。

如果屬性是透過程式設計修改或使用者互動來變更, Size 就會引發這個事件。

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

適用於

另請參閱