Control.BackColorChanged Událost

Definice

Nastane, když se změní hodnota BackColor vlastnosti.

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

Event Type

EventHandler

Příklady

Následující příklad kódu je obslužná rutina události, která se spustí při Text změně hodnoty vlastnosti. Třída Control má několik metod se vzorem name PropertyNameChanged , které jsou vyvolány, když se odpovídající PropertyName hodnota změní (PropertyName představuje název odpovídající vlastnosti).

Následující příklad kódu změní ForeColor TextBox zobrazení dat měny. Příklad převede text na desetinné číslo a změní ForeColor Color.Red hodnotu, zda je číslo záporné a jestli Color.Black je číslo kladné. Tento příklad vyžaduje, abyste měli Form hodnotu obsahující 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

Poznámky

Tato událost se vyvolá, pokud BackColor je vlastnost změněna buď programovou úpravou, nebo interakcí uživatele.

Další informace o zpracování událostí naleznete v tématu Zpracování a vyvolávání událostí.

Platí pro

Viz také