Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Does the Shown event get queued up for later processing? Egad, do we need to call DoEvents() after every Show()?

$
0
0

On first call to Show() of one of our Forms, we need to do some processing... but that processing doesn't work until the controls are visible.  Sooo, we moved that processing from the Load event handler to the Shown event handler.  MS documentation indicates that the order of events following a first call to Show() will be:  Load, VisibleChanged, Activated, and Shown.  Perfect.

So, in the event handler where the user invokes this Form, we do a Show() and then we do some processing specific to the user's request.  Unfortunately, that doesn't work because the Shown event handler hasn't fired!  Huh?

We can "fix" this by putting a DoEvents() after the Show().  But obviously, that's undesirable for many reasons.

It appears that calling Show() directly invokes the Load event but queues up (BeginInvoke's) the Shown event.  Is that so?  Is that controllable?

Should we instead move the code from the Shown event handler to the VisibleChanged event handler, and implement our own logic to make sure it only gets invoked the first time?

If you can shed any light on this it would be greatly appreciated.


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>