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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
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



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Hi TheLearnedOne;

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

Fernando SotoRetiredCommented:
A solution to this question was posted above

Thanks you;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.