Control.OnParentVisibleChanged(EventArgs) Метод

Определение

Вызывает событие VisibleChanged при изменении значения свойства Visible контейнера элемента управления.

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

Параметры

e
EventArgs

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

Примеры

В следующем примере кода показан метод вызова событий, который выполняется при Text изменении значения свойства. Класс Control имеет несколько методов с шаблоном On имени 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

Комментарии

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

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

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

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

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

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