Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing a form from Sub Main

Status
Not open for further replies.

Custom24

Programmer
Nov 27, 2001
591
0
0
GB
Hi I was working on a more elegant solution to OlderTimer's problem of showing a splash screen.
thread796-300075
I was thinking of something like this

Sub main()
Dim frmSplash As New frmSplash()
'disable the hide button until initialization complete
frmSplash.btnHide.Enabled = False
frmSplash.Show()
'now do our initialization
Dim frmMain As New frmMain()
'now just enable the hide button
frmSplash.btnHide.Enabled = True
frmMain.ShowDialog()


End Sub

and under frmSplash, then btnHide would do this

Private Sub btnHide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHide.Click
Me.Hide()
Me.Dispose()
End Sub

This kind of code works under VB6 - you don't have to use the equivalent of ShowDialog - forms initialised in Sub Main persist until the app ends.

However in .net, if you don't use ShowDialog, the GC collects the forms and ends the app, and if you do use ShowDialog, then even though frmMain can instantiate new forms, the user cannot hide frmSplash.

I also tried instanstiating frmSplash from the frmMain Load Event, but then I cannot see an easy way to set focus for frmSplash.

Any ideas?

Mark
PS This is my first .net post so be gentle!
 
Hi,
have you tried using Application.Run(Main Form)

Best Regards
Almi
 
No, but when I try it, it seems to acheive the same effect as ShowDialog - ie code after the show does not execute until the form is closed.

Also, even if I put the code for enabling the Splash hide button before the ShowDialog (or Application.Run(form)) then the new form ends up on top of the splash and there doesn't seem to be any way to "set focus" back to the splash.

Anyway, I'll take a look at some of the samples that come with VS.NET - some of them must have splash screens!

Thanks - Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top