Поделиться через


Control.OnImeModeChanged(EventArgs) Метод

Определение

Вызывает событие 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)

Параметры

e
EventArgs

Объект EventArgs , содержащий данные события.

Примеры

В следующем примере кода используется метод создания событий, который выполняется при Text изменении значения свойства. Класс Control имеет несколько методов с шаблоном Onname PropertyNameChanged , которые вызывают соответствующее событие PropertyNameChanged при изменении значения PropertyName (PropertyName представляет имя соответствующего свойства).

В следующем примере кода изменяется ForeColor производный TextBox класс, отображающий данные валюты. В примере текст преобразуется в десятичное число и изменяется ForeColorColor.Red значение, если число отрицательное, а Color.Black если число положительное. В этом примере требуется, чтобы у вас был класс, производный от TextBox класса.

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

Комментарии

При вызове события обработчик событий вызывается через делегат. Дополнительные сведения см. в разделе "Обработка и создание событий".

Метод OnImeModeChanged также позволяет производным классам обрабатывать событие без присоединения делегата. Это предпочтительный способ обработки события в производном классе.

Примечания для тех, кто наследует этот метод

При переопределении OnImeModeChanged(EventArgs) в производном классе обязательно вызовите метод базового класса OnImeModeChanged(EventArgs) , чтобы зарегистрированные делегаты получали событие.

Применяется к

См. также раздел