How to execute code after form displayed (every time)?

  • Thread starter Thread starter anon
  • Start date Start date
A

anon

I want to do some code once a form has been loaded and displayed, every
time when the form is displayed, not just the first time. How can I do
this?
From what I've read, the Form_Load method is only executed once, after
the form has been created. I've tried putting a MessageBox.Show()
inside the OnActivated method, but it just continually pops up a new
box as soon as I close the MsgBox.
 
OnActivated would be the right event, but each time your form is uncovered
by closing the MessageBox, it gets invoked again. So you might need a
variable to act as a toggle if the code you call will temporarily hide the
form so you control the behavior.

Ginny Caughey
..NET Compact Framework MVP
 
Thanks. So if the code that I want to execute OnActivated also makes
changes to the screen (i.e. drawing and refreshing), will those
activities also generate more OnActivated calls? In which case I'll
have to use a toggle or semaphore-like thing to ignore or swallow or
consume those events?
 
No. OnActivate happens when the Form is Activated. A MessageBox is another
Form, so when you acknowledge it, the MessageBox gets focus, then passes
control back to your Form, which gets another OnActivate.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
Back
Top