RadioButton.OnCheckedChanged(EventArgs) 方法

定義

引發 CheckedChanged 事件。Raises the CheckedChanged event.

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

參數

e
EventArgs

包含事件資料的 EventArgsAn EventArgs that contains the event data.

範例

下列程式碼範例會示範如何 CheckAlign 在執行時間變更屬性。The following code example demonstrates how the CheckAlign property can be changed at run time. 當值變更時,的核取方塊部分 RadioButton 會移至文字的右邊或左邊 CheckedThe check box portion of a RadioButton is moved to the right or left of the text when the Checked value changes. 此範例需要在 RadioButton 表單上具現化控制項,而且已 System.Drawing 包含命名空間的參考。This example requires that a RadioButton control has been instantiated on a form and that a reference to the System.Drawing namespace has been included.

private:
   Void radioButton1_CheckedChanged( System::Object^ sender, System::EventArgs^ e )
   {
      // Change the check box position to be opposite its current position.
      if ( radioButton1->CheckAlign == ContentAlignment::MiddleLeft )
      {
         radioButton1->CheckAlign = ContentAlignment::MiddleRight;
      }
      else
      {
         radioButton1->CheckAlign = ContentAlignment::MiddleLeft;
      }
   }
private void radioButton1_CheckedChanged(Object sender, 
                                         EventArgs e)
{
   /* Change the check box position to 
   be the opposite its current position.*/
   if (radioButton1.CheckAlign == ContentAlignment.MiddleLeft)
   {
      radioButton1.CheckAlign = ContentAlignment.MiddleRight;
   }
   else
   {
      radioButton1.CheckAlign = ContentAlignment.MiddleLeft;
   }
}

Private Sub radioButton1_CheckedChanged(sender As Object, e As EventArgs)
    ' Change the check box position to
    ' be the opposite its current position.
    If radioButton1.CheckAlign = ContentAlignment.MiddleLeft Then
        radioButton1.CheckAlign = ContentAlignment.MiddleRight
    Else
        radioButton1.CheckAlign = ContentAlignment.MiddleLeft
    End If
End Sub

備註

引發事件會透過委派叫用此事件處理常式。Raising an event invokes the event handler through a delegate. 如需詳細資訊,請參閱 處理和引發事件For more information, see Handling and Raising Events.

OnCheckedChanged 方法也允許衍生類別處理事件,而不用附加委派。The OnCheckedChanged method also allows derived classes to handle the event without attaching a delegate. 這是在衍生類別中處理事件的慣用技巧。This is the preferred technique for handling the event in a derived class.

給繼承者的注意事項

OnCheckedChanged(EventArgs)在衍生類別中覆寫時,請務必呼叫基類的方法, OnCheckedChanged(EventArgs) 以便註冊的委派會接收事件。When overriding OnCheckedChanged(EventArgs) in a derived class, be sure to call the base class' OnCheckedChanged(EventArgs) method so that registered delegates receive the event.

適用於