Is there a way to stop control events during the form load?

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I have a VB.NET app with a radio button that has check changed handler on
it, and the InitializeComponent() code sets the .checked value to true which
triggers the event handler. Is there a way to suspend event processing
until initialization is complete?

Thanks.
 
I would remove the Handles clause from the end of the following statement:

Private Sub RadioButton_CheckedChanged(ByVal sender as Object, ByVal e as
EventArgs) Handles RadioButton.CheckedChanged

Then in the Form_Load event handler, add the following line to hook up the
radio button event handler manually:

AddHandler RadioButton.CheckedChanged, AddressOf Me.RadioButton_CheckedChanged

Tony
 
Eric,

VB.NET handles events using WithEvents keywords, which hooks the events
little bit too early. My suggestion is either not to hook the events in the
designer, but rather manually after InitializeComponent call or having a
flag that you check in your event handlers before performing any operation.
The falg can be set in the constructor before calling InitializeComponent
and reset after that. Use Try/Finally to enusre that the flag will be reset.
 
Back
Top