simple question

  • Thread starter Thread starter peter hansen
  • Start date Start date
P

peter hansen

in VB6 it was possible to load and unload forms - how do I do this in VB.NET
:D I think I have been almost everywhere

// Peter
 
Peter,

Dim frmInstance as New Form1() ' Form is loaded
frmInstance.Dispose() ' Form is unloaded

Since a Form is nothing but a Class, the Form is loaded once the instance of
the (Form) Class is created. The Form is unloaded in the moment, you "free"
the space for it with Dispose.

Klaus
 
* "peter hansen said:
in VB6 it was possible to load and unload forms - how do I do this in VB.NET
:D I think I have been almost everywhere

Loading:

\\\
Dim f As New FooForm()
f.Show()
///

Unloading: Call the form's 'Close' method.
 
Klaus Löffelmann said:
Peter,

Dim frmInstance as New Form1() ' Form is loaded
frmInstance.Dispose() ' Form is unloaded

Hmmm... well it works 50% :D

Everytime Dim drmInstance as New Form1() is mentioned the program quits.
Therefor I have changed the frmInstance.Dispose to Me.Dispose and removed
the Dim

But when I run the Me.Dispose all the forms are beeing unloaded - not the
current form which was possible with the old VB6 Form1.Unload

// Peter
 
Herfried K. Wagner said:
Loading:

\\\
Dim f As New FooForm()
f.Show()
///

Unloading: Call the form's 'Close' method.


the Close-thing unloads the program - not only the current form. I need
something that unloads the current form

// Peter
 
Close should be the same as Dispose, since Close only calls Dispose
internally. Haven't checked it, though, but it should be the same with forms
according to the IDisposable-Pattern?!

Checking it tomorrow.

Klaus
 
That might be, if form1 is your last form. If it is closed, it's disposed -
I guess.
Try hide instead, that only disabled the form, not unloading it.

I'm going to check tomorrow,

Klaus
 
Klaus Löffelmann said:
That might be, if form1 is your last form. If it is closed, it's disposed -
I guess.
Try hide instead, that only disabled the form, not unloading it.

I'm going to check tomorrow,

Klaus

Well Form1 is not the last form. Form2 has been called (Form2.Show) 3
seconds before the Close-statement is sent to Form1

// Peter
 
....but maybe *from* Form1?

If form1 instantiated form2 in a form1-local-variable, and you close form1,
then form1 is destroyed and with it all member variables which would cause
to close form2, too, since its defining object variable runs out of scope
with the closing of form1.

But it's already quite late here (2am), so I'll take a closer look tomorrow.
Post some code here in the meanwhile, that would help!

Good night

Klaus
 
Klaus Löffelmann said:
...but maybe *from* Form1?

If form1 instantiated form2 in a form1-local-variable, and you close form1,
then form1 is destroyed and with it all member variables which would cause
to close form2, too, since its defining object variable runs out of scope
with the closing of form1.

But it's already quite late here (2am), so I'll take a closer look tomorrow.
Post some code here in the meanwhile, that would help!

Good night

Klaus

Well there is no big deal - i mean there is no code to paste caus you have
alreaddy answered the the question :D

Instead I'll try to describe the problem:
Its pretty simple - a program which has a Splash-screen... when the
splash-screen unloads the next form should be loaded and because of that the
Splash-screen isn't for any futher use I would like to unload it :D - not
just hide

// Peter
 
Hi Peter,

This is the normal scenario for this kinds of forms:
\\\
dim frm as new splashform
if frm.showdialog(me) = dialogresult.OK then
do something
end it
frm.dispose
///
Or just
\\\
dim frm as new splashform
frm.showdialog(me)
frm.dispose
////

I hope this helps?

Cor
 
Peter,

I guess you'll do this when starting your program. Try this (about, not
checked!):

Create a Module; Make Module/Sub Main the start object.

In Sub Main put:

Dim locfrmSplash as new SplashForm
locFrmSplash.Show
locFrmSplash.Update

dim locfrmMain as new MainForm
'This form-class does the time extensive parts now
'Notice, that if you like to prepare controls in that
'form, you put your preparing code *after* InitializeComponents
'in the constructor of the form!
locFrmSplash.Dispose
locFrmSplash.ShowDialog

That should do the job.

Klaus
 
By the way, I was wrong. Close - in contrast to many other classes - is not
a synonym for disposing the form, it only sends a message to close the form,
that is making it unvisible.

Klaus
 
Back
Top