CheckedChanged Event

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

i got a form with some checkboxes and they are set to be checked on design
time... when the program loads it fires the CheckChanged event for every one
of them.... there is any way to avoid this?? this is happening before the
Load event.... i was thinking on putting a Boolean Variable to avoid this
while loading but i think that it has to be a better approach.

Thanks.
Alex.
 
Hi Alex,

I think the behavior is by design.

If you debug into the code you will find that the program procedure is as
following.
1. Public Sub New()
2. InitializeComponent()
3. Me.CheckBox1.Checked = True
4. Private Sub CheckBox1_CheckedChanged
5. Form_Load()
You may find that you check the checkbox in design time, but the code will
be execute in runtime.
I think the declare a boolean is a good way.

Dim flag As Boolean
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.SuspendLayout()
'
'CheckBox1
'
Me.CheckBox1.Checked = True
Me.CheckBox1.CheckState = System.Windows.Forms.CheckState.Checked
Me.CheckBox1.Location = New System.Drawing.Point(112, 64)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.TabIndex = 0
Me.CheckBox1.Text = "CheckBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.CheckBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Debug.WriteLine("loaded")
flag = True
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CheckBox1.CheckedChanged
If flag Then
Debug.WriteLine("checked")
End If
End Sub

If you have any related question, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
Peter,

Thank you very much for responding, but I did not post the
question and do not use VB.

(e-mail address removed) is the alias that I use when posting the
messages here. Maybe there is another Alex who requested
the same alias and the system got confused and associated
it with my real email address instead of rejecting it.

Thanks again,

Alexander Freylicher
 
Hi Alex,

Did my suggestion works for you?
If you have any question on this issue please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top