How to prevent value changed events from firing on form initialization in .NET?

后端 未结 10 2431
清歌不尽
清歌不尽 2020-12-03 07:01

Consider a simple .NET form with a couple of radio buttons and a checkbox.

Each of the radio buttons has a CheckedChanged handler setup that performs some action bas

10条回答
  •  庸人自扰
    2020-12-03 07:53

    To make it feel slightly less dirty, if you initialize the controls in the constructor of the form you might be able to use the forms IsHandleCreated property rather than your own bool to check if it should actually validate or not.
    I would think that normally you wouldn't want to validate anything before it's been shown for the first time and handle isn't created until it is.

    Code Example:

    Private Sub myRadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles myRadioButton.CheckedChanged
    If myRadioButton.Checked AndAlso myRadioButton.IsHandleCreated Then
        'Do Work
    End If
    End Sub
    

提交回复
热议问题