Редагувати

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


RadioButton.OnCheckedChanged(EventArgs) Method

Definition

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)

Parameters

e
EventArgs

An EventArgs that contains the event data.

Examples

The following code example demonstrates how the CheckAlign property can be changed at run time. The check box portion of a RadioButton is moved to the right or left of the text when the Checked value changes. 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

Remarks

Raising an event invokes the event handler through a delegate. For more information, see Handling and Raising Events.

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.

Notes to Inheritors

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.

Applies to