CheckedChanged after load form

I have radiobutton controler on my form. I would like to ask why on load form is triggered my code which handles only checkedchange metode.
Private Sub rdgDisplayAspectRatio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdg1DisplayAspectRatioBox.CheckedChanged, rdg1DisplayAspectRatioPan.CheckedChanged, rdg1DisplayAspectRatioStretch.CheckedChanged, rdg1DisplayAspectRatioPanScan.CheckedChanged
        If CType(sender, RadioButton).Checked Then
            frmMain.frmvideo1.VideoGrabber1.Display_AspectRatio = CType(CType(sender, RadioButton).Tag, VidGrab.TAspectRatio)
        End If
    End Sub

Open in new window

patrikmichnacAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hello patrikmichnac,

That is because one of the radio buttons is set to Checked at design time or you are changing it at form load. You can do the following to get around it.

Public Class Form1

    Private FormIsLoaded As Boolean = False

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        FormIsLoaded = True

    End Sub

    Private Sub rdgDisplayAspectRatio_CheckedChanged(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles rdgDisplayAspectRatio.CheckedChanged

        If Not FormIsLoaded Then Return

        'Do whatever here

    End Sub

End Class


Regards,

FernandoSoto
0
 
Fernando SotoRetiredCommented:
Hi TheLearnedOne;

My reason for this objection is - I have posted a solution that should work.

Fernando
0
 
Fernando SotoRetiredCommented:
A solution to this question was posted above
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23898989.html:#a22942210

Thanks you;
Fernando
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.