Control.SizeChanged 事件

定义

Size 属性值更改时发生。Occurs when the Size property value changes.

public:
 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.

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 事件来处理自定义布局。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.

适用于

另请参阅