locked
Where's the WinForm event for AFTER a form has finished loading? RRS feed

  • Pytanie

  • I need to fire an event AFTER a form has finished loading and is displayed to the user.

    Currently, I'm initializing my MapPoint control on my form in the form_load event.  But, if the connection to the MapPoint server is down, the form never really finishes loading before an exception is thrown and it's very slow.

    I want to put my MapPoint initialize inside an event that fires AFTER the form has finished loading and is displayed to the user.

    How can I do this?
    piątek, 15 grudnia 2006 00:10

Odpowiedzi

  • Hello All.

    _Quimbly_:

    You could use either Shown (as ahmedilyas said) or Activated, depending on your situation.  Shown fires once when the form is first created, and never fires again.  Activated fires each time the form is made the active form.  Whichever one best fits your situation.

    HTH.

    piątek, 15 grudnia 2006 03:10

Wszystkie odpowiedzi

  • how about the shown event?
    piątek, 15 grudnia 2006 00:41
  • Hello All.

    _Quimbly_:

    You could use either Shown (as ahmedilyas said) or Activated, depending on your situation.  Shown fires once when the form is first created, and never fires again.  Activated fires each time the form is made the active form.  Whichever one best fits your situation.

    HTH.

    piątek, 15 grudnia 2006 03:10
  • Hmm, there's seems to be a problem with using either of these events.

    There is some delay in actually displaying the form such that even though I'm initializing my MapPoint map in the form_Shown event, the form STILL doesn't display properly.  It's about half-way drawn when the form_Shown event is fired.  Then when this happens, the form stops finishing it's drawing and just hangs while it tries to initialize the map.  Uhhhh.

    I suppose I could start a timer in my form_load or form_shown event, and then have it fire a few seconds after....but that's ridiculous.
    piątek, 15 grudnia 2006 17:49
  • Hello All.

    _Quimbly_:

    And it does the same thing in the Activated event handler?  Have you tried setting the DoubleBuffered property of the form to true?

    HTH.

    piątek, 15 grudnia 2006 18:22
  • The Activation is wrong way. It may be called, but is not guarranteed to be called. There are cases where it will not be.

    sobota, 16 grudnia 2006 20:19
  • Ok, so the Activated event is out...

    But as I mentioned, the Shown event isn't working either.  The form still doesn't finish displaying before the Shown event is called.  And because of this, the form drawing still doesn't finish before the MapPoint calls are made.  The result is a half-drawn form that stalls until MapPoint times out.

    I tried setting the form's DoubleBuffered property.  That didn't seem to help.

    Any other suggestions?
    poniedziałek, 18 grudnia 2006 16:56
  • Hello All.

    _Quimbly_:

    Well then, what about putting the MapPoint ini on a background worker thread?

    HTH.

    poniedziałek, 18 grudnia 2006 17:09
  • Well, I was thinking that, but I was running into exceptions with cross-thread access to the MapPoint reference. After a bit of research, I found that I could disable this exception, by allowing cross-thread access, but I was thinking that I would eventually run into some problems. Hmmmm....  Maybe I'm just using it incorrectly.
    poniedziałek, 18 grudnia 2006 17:36
  • Hello All.

    _Quimbly_:

    Well, I'm not the one to advise you about cross-thread issues.  You might want to start a new thread on that question, and get some of the threading experts hereabouts to lend a hand.

    HTH.

    poniedziałek, 18 grudnia 2006 18:31
  •  Mark Benningfield wrote:

    Hello All.

    _Quimbly_:

    Well, I'm not the one to advise you about cross-thread issues. You might want to start a new thread on that question, and get some of the threading experts hereabouts to lend a hand.

    HTH.



    Ha!  No pun intended? 

    poniedziałek, 18 grudnia 2006 18:36
  • Hello All.

    poniedziałek, 18 grudnia 2006 20:37
  • Hmm, there's seems to be a problem with using either of these events.

    There is some delay in actually displaying the form such that even though I'm initializing my MapPoint map in the form_Shown event, the form STILL doesn't display properly.  It's about half-way drawn when the form_Shown event is fired.  Then when this happens, the form stops finishing it's drawing and just hangs while it tries to initialize the map.  Uhhhh.

    I suppose I could start a timer in my form_load or form_shown event, and then have it fire a few seconds after....but that's ridiculous.
    Still no good answer to this?  I am having the same problem.  I have a form with a collection of controls on it.  The Shown event fires after the base form is painted, but before the contained controls are.
    wtorek, 14 kwietnia 2009 23:56
  • I have an app that needs to do a blocking SQL call on form-load, and I've wrestled with this exact issue. (I've actually been wrestling with it since Win 3.1!)

    In WinForms, I've find that calling
      Application.DoEvents();
    as the very 1st thing in your form_Shown() handler solves this - it allows all the child windows (aka contained controls) to fully render before you do your stuff.

    • Zaproponowany jako odpowiedź przez Aliza.K czwartek, 28 lutego 2013 10:00
    czwartek, 11 lutego 2010 18:25
  • Please mark this as the best answer!
    Had the same issue and  Application.DoEvents(); was the only solution that worked! Tried everything else without success!

    (datgridview cell painting event with draw override where my column width change wasn't painted correctly while loading )
    niedziela, 24 sierpnia 2014 23:54
  • The Best Answer....easy, fast, reliable! Thanks Dave!
    piątek, 1 czerwca 2018 15:20