Unloading af form

P

peter hansen

I tried a couple of weeks ago but I'll try again :D

I old VB6-days it was possible to unload a form bu using the Unload(Form)
command.
I have tried the Close-function but it'll unload the entire projekt.
The reason why I am asking is that I am creating a program and I need a
Splash-screen (like the tiny screen that appears when programs like Word
starts), and when the Splash-screen has been loaded for a couple of seconds
it should be unloaded (it is not for any use anymore)... how do I unload
just this form and not the entire project. Remember that this form (the
Splash-form) is the form that trigger triggers the next form and therefor is
the 'parent' to the entire project or something (I have been told that by
closing this form with the Close-command it'll close all the Child-forms)

// Kian
 
C

Cor

Hi Peter,

If you use another approach maybe the answer is easier

Create a kind of main form
Create your splash form
In the load event of your main form you say
\\\
dim frm as new splashform
me.hide
frm.showdialog
me.show
frm.dispose
///
And that is all,
Cor
 
S

solex

Kian,

How a Sub Main that controls the startup process

Public Sub Main()
Dim f As New SpashForm

f.Show
' loading project resources here
f.Dispose()
f = Nothing

Dim fm as New MyMainForm

fm.ShowDialog()
fm.Dispose()
fm = Nothing
End Sub
 
R

Russell Jones

The simplest method is to show the splash screen from your startup form,
like this:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim splash As New SplashForm
splash.Show()
' simulate normal initialization code here
' you wouldn't keep this dummy loop in a normal app
For i As Integer = 1 To 500000
Application.DoEvents()
Next
splash.Hide()
End Sub

Note that this simple method doesn't let the splash screen receive Paint
messages or perform any processing it needs to do, such as running an
animation. For a more robust version, see this article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/casoast.asp
 
M

Mike Labosh

The reason why I am asking is that I am creating a program and I need a
Splash-screen (like the tiny screen that appears when programs like Word
starts), and when the Splash-screen has been loaded for a couple of seconds
it should be unloaded (it is not for any use anymore)... how do I unload
just this form and not the entire project. Remember that this form (the
Splash-form) is the form that trigger triggers the next form and therefore is
the 'parent' to the entire project or something (I have been told that by
closing this form with the Close-command it'll close all the Child-forms)

The reason for your trouble is that in VB.NET, whatever your project calls
its "Startup Object" in the Project Properties dialog, is the thing that
provides the "Message Loop". Without a message loop, an application will
launch, appear briefly and then exit.

If your startup object is a form, that startup form holds the message loop.
When that form closes, the message loop ends and the application exits. You
have two solutions:

If you want your project to start from a form, set your main form to be the
startup object, and use the load event of your main form to show the splash
screen. (Don't forget to set the TopMost property of the splash form on its
property window)

frmMain.vb:

Private Sub frmMain_Load(...)

'frmMain is set to be the project's startup object.
'frmMain owns the message loop.

frmSplash.Show()

End Sub

If you want your project to start from Sub Main, do this:

basGlobal.vb:

Module basGlobal

Public Sub Main()

'Here, there is no form that owns a message loop because
'the startup object is Sub Main(). The message loop is
'handled by Application.Run() and is associated with
'whatever form you create an instance of, and pass to it.

frmSplash.Show()
Application.Run(New frmMain()))

End Sub

End Module
--
Peace & happy computing,

Mike Labosh, MCSD MCT
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei
 
M

Mike Labosh

OOPS!! Some Corrections: (That's what I get for typing it in a usenet post
instead of pasting it from a code window!)
frmMain.vb:

Private Sub frmMain_Load(...)

'frmMain is set to be the project's startup object.
'frmMain owns the message loop.
Dim f As New frmSplash()
f.Show()
basGlobal.vb:

Module basGlobal

Public Sub Main()

'Here, there is no form that owns a message loop because
'the startup object is Sub Main(). The message loop is
'handled by Application.Run() and is associated with
'whatever form you create an instance of, and pass to it.

Dim f As New frmSplash()
f.Show()
Application.Run(New frmMain()))

End Sub

End Module
--
Peace & happy computing,

Mike Labosh, MCSD MCT
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei
 
P

peter hansen

Well... you have all refered to my old question and your own answers which
wasn't (sorry) good enough :D
I need to unload one single form... and by using all your answers the entire
program is beeing unloaded.

// Peter
 
M

Mike Labosh

Well... you have all refered to my old question and your own answers which
wasn't (sorry) good enough :D
I need to unload one single form... and by using all your answers the entire
program is beeing unloaded.

Here is a code sample for you:

http://www.vbsensei.com/SplashCrash.zip

I have made a solution with two projects. The first project shows how to do
your splash screen if the project starts from Form1 (the main form) and the
splash screen is Form2. The second project shows you how to have a main
form (form1) and a splash form (form2) but startup from a Sub Main.

This Zip archive should be unzipped "with folders" so that it will create
C:\Temp\SplashCrash and the two projects underneath it. You should open
c:\temp\splashcrash\splashcrash.sln with VS.NET

If you are using VS.NET 2K3, you will get a conversion prompt. Just click
yes. I did this demo in VS.NET 2K2 for backward compatibility.

And no, I don't have a real web site. if you goto www.vbsensei.com by
itself, you will find nothing, because I don't have a default page. I just
use this web server to post articles and "gimmie files" to the world.

--
Peace & happy computing,

Mike Labosh, MCSD MCT
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei
 
S

Scott M.

me.close()

The other forms need not be "child" forms of the splash screen.

This will not close all the forms, just the one that me.close() is in.
 
H

Herfried K. Wagner [MVP]

* "peter hansen said:
Well... you have all refered to my old question and your own answers which
wasn't (sorry) good enough :D
I need to unload one single form... and by using all your answers the entire
program is beeing unloaded.

No, it isn't...
 

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