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 提供水平和垂直缩放值。 名为 ButtonOK 的实例用于设置控件实例的规模 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 属性通过编程修改或用户交互进行更改,则会引发此事件。

有关处理事件的详细信息,请参阅 处理和引发事件

适用于

另请参阅