Control.OnImeModeChanged(EventArgs) Metodo

Definizione

Genera l'evento ImeModeChanged.

protected:
 virtual void OnImeModeChanged(EventArgs ^ e);
protected virtual void OnImeModeChanged (EventArgs e);
abstract member OnImeModeChanged : EventArgs -> unit
override this.OnImeModeChanged : EventArgs -> unit
Protected Overridable Sub OnImeModeChanged (e As EventArgs)

Parametri

e
EventArgs

Oggetto EventArgs che contiene i dati dell'evento.

Esempio

L'esempio di codice seguente è un metodo di generazione di eventi che viene eseguito quando il valore della Text proprietà viene modificato. La Control classe dispone di diversi metodi con il modello On di nome PropertyNameChanged che genera l'evento PropertyName corrispondente quando il valore PropertyNameChanged cambia (PropertyName rappresenta il nome della proprietà corrispondente).

Nell'esempio di codice seguente viene modificato l'oggetto ForeColor di una TextBox classe derivata che visualizza i dati di valuta. Nell'esempio il testo viene convertito in un numero decimale e viene modificato in ForeColorColor.Red se il numero è negativo e in Color.Black se il numero è positivo. Questo esempio richiede che sia presente una classe che deriva dalla TextBox classe .

protected:
   virtual void OnTextChanged( System::EventArgs^ e ) override
   {
      try
      {
         // Convert the text to a Double and determine
         // if it is a negative number.
         if ( Double::Parse( this->Text ) < 0 )
         {
            // If the number is negative, display it in Red.
            this->ForeColor = Color::Red;
         }
         else
         {
            // If the number is not negative, display it in Black.
            this->ForeColor = Color::Black;
         }
      }
      catch ( Exception^ ) 
      {
         // If there is an error, display the
         // text using the system colors.
         this->ForeColor = SystemColors::ControlText;
      }

      TextBox::OnTextChanged( e );
   }
protected override void OnTextChanged(System.EventArgs e)
{
   try
   {
      // Convert the text to a Double and determine
      // if it is a negative number.
      if(double.Parse(this.Text) < 0)
      {
         // If the number is negative, display it in Red.
         this.ForeColor = Color.Red;
      }
      else
      {
         // If the number is not negative, display it in Black.
         this.ForeColor = Color.Black;
      }
   }
   catch
   {
      // If there is an error, display the 
      // text using the system colors.
      this.ForeColor = SystemColors.ControlText;
   }
   
   base.OnTextChanged(e);
}
Protected Overrides Sub OnTextChanged(e As System.EventArgs)
   Try
      ' Convert the text to a Double and determine
      ' if it is a negative number.
      If Double.Parse(Me.Text) < 0 Then
         ' If the number is negative, display it in Red.
         Me.ForeColor = Color.Red
      Else
         ' If the number is not negative, display it in Black.
         Me.ForeColor = Color.Black
      End If
   Catch
      ' If there is an error, display the
      ' text using the system colors.
      Me.ForeColor = SystemColors.ControlText
   End Try

   MyBase.OnTextChanged(e)
End Sub

Commenti

Quando viene generato un evento, il gestore dell'evento viene richiamato tramite un delegato. Per altre informazioni, vedere la gestione e generazione di eventi.

Il metodo OnImeModeChanged consente inoltre alle classi derivate di gestire l'evento senza associare un delegato. È la tecnica consigliata per la gestione dell'evento in una classe derivata.

Note per gli eredi

Quando si esegue l'override di OnImeModeChanged(EventArgs) in una classe derivata, verificare di chiamare il metodo OnImeModeChanged(EventArgs) della classe di base in modo che i delegati registrati ricevano l'evento.

Si applica a

Vedi anche