Control.DockChanged 事件  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当 Dock 属性的值更改时发生。
public:
 event EventHandler ^ DockChanged;public event EventHandler DockChanged;public event EventHandler? DockChanged;member this.DockChanged : EventHandler Public Custom Event DockChanged As EventHandler 事件类型
示例
下面的代码示例是属性值更改时 Text 执行的事件处理程序。 当相应的 PropertyName 值更改 (PropertyName 表示相应属性的名称) 时,该Control类具有多个具有名称模式 PropertyNameChanged 的方法。
下面的代码示例更改ForeColorTextBox显示货币数据。 该示例将文本转换为十进制数,并将数字为负数和数字正数时Color.Black更改为ForeColorColor.Red。 此示例要求你有一个Form包含 .TextBox
private:
   void currencyTextBox_TextChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      try
      {
         // Convert the text to a Double and determine if it is a negative number.
         if ( Double::Parse( currencyTextBox->Text ) < 0 )
         {
            // If the number is negative, display it in Red.
            currencyTextBox->ForeColor = Color::Red;
         }
         else
         {
            // If the number is not negative, display it in Black.
            currencyTextBox->ForeColor = Color::Black;
         }
      }
      catch ( Exception^ ) 
      {
         // If there is an error, display the text using the system colors.
         currencyTextBox->ForeColor = SystemColors::ControlText;
      }
   }
private void currencyTextBox_TextChanged(object sender, EventArgs e)
{
   try
   {
      // Convert the text to a Double and determine if it is a negative number.
      if(double.Parse(currencyTextBox.Text) < 0)
      {
         // If the number is negative, display it in Red.
         currencyTextBox.ForeColor = Color.Red;
      }
      else
      {
         // If the number is not negative, display it in Black.
         currencyTextBox.ForeColor = Color.Black;
      }
   }
   catch
   {
      // If there is an error, display the text using the system colors.
      currencyTextBox.ForeColor = SystemColors.ControlText;
   }
}
Private Sub currencyTextBox_TextChanged(sender As Object, _ 
  e As EventArgs) Handles currencyTextBox.TextChanged
   Try
      ' Convert the text to a Double and determine if it is a negative number.
      If Double.Parse(currencyTextBox.Text) < 0 Then
         ' If the number is negative, display it in Red.
         currencyTextBox.ForeColor = Color.Red
      Else
         ' If the number is not negative, display it in Black.
         currencyTextBox.ForeColor = Color.Black
      End If
   Catch
      ' If there is an error, display the text using the system colors.
      currencyTextBox.ForeColor = SystemColors.ControlText
   End Try
End Sub
注解
如果 Dock 属性通过编程修改或用户交互更改,则会引发此事件。
有关处理事件的详细信息,请参阅 处理和引发事件。