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

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.
 
G

Guest

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
 
S

Stoitcho Goutsev \(100\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top