共用方式為


Control.BackgroundImageChanged 事件

定義

發生於 BackgroundImage 屬性的值變更時。

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

事件類型

範例

下列程式碼範例是屬性值變更時 Text 所執行的事件處理常式。 類別 Control 有數個名稱模式PropertyNameChanged 的方法,當對應的PropertyName值變更 (PropertyName代表對應屬性的名稱) 時引發。

下列程式碼範例會變更 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

備註

如果屬性是透過程式設計修改或使用者互動來變更,就會 BackgroundImage 引發這個事件。

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱