Control.SizeChanged Control.SizeChanged Control.SizeChanged Control.SizeChanged Event


發生在 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. ANumericUpDown執行個體會提供水平及垂直調整值。A NumericUpDown instance provides the horizontal and vertical scale value. Button具名執行個體 [確定] 用來設定的小數位數值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 'RegisterEventHandler

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 'MyButton2_Click

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


建議您最好使用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.