Control.SizeChanged 事件


發生在 Size 屬性值變更時。Occurs when the Size property value changes.

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




下列程式碼範例示範 SizeChanged 事件。The following code example demonstrates the SizeChanged event. 已提供可水準和垂直縮放的 Button 控制項實例。An instance of a Button control has been provided that can be scaled both horizontally and vertically. NumericUpDown 實例提供水準和垂直尺規值。A NumericUpDown instance provides the horizontal and vertical scale value. 名為OKButton 實例用來設定 Button 控制項實例的小數值。The Button instance named OK is used to set the scale values for the Button control instance. 每當控制項的大小變更時,就會呼叫與控制項之 SizeChanged 事件相關聯的事件處理常式。Whenever the size of the control changes, the event handler associated with the SizeChanged event of the control is called. 這個事件處理常式會顯示訊息方塊,指出控制項的大小已變更。This event handler displays a message box indicating that the size of the control has changed.

   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;

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)
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 事件來處理自訂版面配置。It is preferable to use the Layout event to handle custom layouts. 會引發 Layout 事件以回應 Resize 事件,但在其他情況下,則可能需要套用版面配置。The Layout event is raised in response to Resize events, but also in other conditions when layout might need to be applied.

如果 Size 屬性是以程式設計方式修改或使用者互動來變更,就會引發這個事件。This event is raised if the Size property is changed by either a programmatic modification or user interaction.

如需處理事件的詳細資訊,請參閱處理和引發事件For more information about handling events, see Handling and Raising Events.