Showing Msgbox after Form_Load

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?
 
M

Mehdi

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

Guest

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
 
H

Herfried K. Wagner [MVP]

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

Johnny Jörgensen

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.
 

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