Showing Msgbox after Form_Load

  • Thread starter Thread starter John Dann
  • Start date Start date
J

John Dann

Something very simple that I can't spot how to do:

I wand to display a msgbox showing some current configuration
parameters when my VB2005 program starts up. However, I want the main
form to paint before the msgbox appears so that the main form appears
as the background to the msgbox. At present I just have the msgbox as
the last item in the Form.Load procedure but not surprisingly it's
appearing on its own and out of context before the main form is
visible.

Is there any event-dependent way of doing this other than using timers
of one sort or another?
 
Something very simple that I can't spot how to do:

I wand to display a msgbox showing some current configuration
parameters when my VB2005 program starts up. However, I want the main
form to paint before the msgbox appears so that the main form appears
as the background to the msgbox. At present I just have the msgbox as
the last item in the Form.Load procedure but not surprisingly it's
appearing on its own and out of context before the main form is
visible.

Is there any event-dependent way of doing this other than using timers
of one sort or another?

Use the Activated event instead of the Load event. The Activated event is
raised whenever the window has been shown on the screen. Note that this
event is raised *everytime* the window is shown on the screen (when it's
unminimized for example), so you'll want to unsubscribe from the event or
use a boolean flag to only show your message box the first time the event
is raised.

I think that in .NET 2, there is a new event that's raised only once the
first time that the window is shown. I haven't switched to .NET 2 yet so I
forgot the name but you might want to look for it.
 
Mehdi,

Yes, in .Net 2 the form now has a Shown event that is raised when the form
is first displayed.

I had not noticed that. Thanks for pointing it out.

Kerry Moorman
 
John Dann said:
I wand to display a msgbox showing some current configuration
parameters when my VB2005 program starts up. However, I want the main
form to paint before the msgbox appears so that the main form appears
as the background to the msgbox. At present I just have the msgbox as
the last item in the Form.Load procedure but not surprisingly it's
appearing on its own and out of context before the main form is
visible.

The 'Load' event is raised prior to showing the form. The 'Form' class in
..NET 2.0 provides a 'Shown' event which can be utilized for a solution to
your question.
 
Or you can do:

Private Sub Form_Load() Handles Mybase.Load

'..... Some stuff here

Me.Show()
Application.DoEvents()

'..... Possibly more stuff here

End Sub


Should work too...

Cheers,
Johnny J.
 
Back
Top