Question on Working With Forms

G

Guest

This should be an easy questions, but I have not had any luck with the answer.

Can you load all forms in a project at once and just have the visible =
False for all but one??? Then to switch between forms, all you would have to
do is work with the visibility property.

I have a project that has forms and I will need to switch between all of
them. One is the main form and it stays loaded (And visible), but the others
will load depending on the operator input. Also, I will have other forms
start even more forms. For example, I will have the main form (Form1) start
form2. Then form2 will start form3. When form3 closes, I need to close form2
& form3. It would be easy if I could just change the visiblity of form2 &
form3.

Maybe I am going about this wrong. Is there a better way?

PLEASE HELP.
 
C

Cor Ligthert

Stingray,

When you start one form as the owner, than you can hanlde them all handle
them all.

(You can start from form2 a form3, however I would instance them all from
the owner).

Cor
 
G

Guest

Ok, I think that is what I am doing.

Say, from from1,
Code on button1

dim form2 as new form2
dim form3 as new form3
form2.showdialog()
form3.showdialog()

On form2, when it closes, I run
dispose()

Then this will auto start form3
When form3 closes, I run
dispose()

This takes me back to form1. Just how I want it. This process will happen
multipule times. From from1-> Form2 -> form3 back to form1. But watching the
memory in
task manager on this process, the memory keeps going up each time.

Is dispose() the correct way to remove each form?
 
C

Cor Ligthert

Ok, I think that is what I am doing.
Say, from from1,
Code on button1
dim frm2 as new form2
frm2.showdialog()
frm2.dispose
dim frm3 as new form3
frm3.showdialog()
frm3.dispose

This is a normal for modal forms, you was confusing me. If you want to hide
form1 in the maintime you can even do me.visible = fals and me.visible =
true (me is the instanced object from the class)
This takes me back to form1. Just how I want it. This process will happen
multipule times. From from1-> Form2 -> form3 back to form1. But watching
the
memory in
task manager on this process, the memory keeps going up each time.

Is dispose() the correct way to remove each form?
Dispose does not remove memory. The memory is removed by the Garbage
Collector. That runs at the moment that it is efficient to run. Watching the
taskmanager gives by the way only a kind of avarage result.

The modal form is one of the exceptions where it is *useful* to use the
dispose.

I hope this helps,

Cor
 
G

Guest

Well, I am still getting the same results.

Running the code below:
dim frm2 as new form2
frm2.showdialog()
frm2.dispose
dim frm3 as new form3
frm3.showdialog()
frm3.dispose
CG.Collect()

If you keep clicking the buttons.... Load Form2, close, load form3 close &
Repeat
the memory in the task manager keeps going up. Even if it's not that
accurate, it still goes up.

If you let it sit there a little while, you can see the GC kick in and lower
the memory usage some but never all the way.

Going from form to form like shown will happen approx 10,000 times before
the app is closed. I am worried about the memory getting out of hand.

Is there a better way to accomplish this same task?

Main Form -> Input Form1 -> Input Form2 (Close Form1 & Form2)
 
G

Guest

Thanks for your help Cor.

That was a great post by Willy. I was freeking out over nothing :)

Started to make me worry. I will be testing this in the next few days.
Should be fine after reading Willy's post.

:)
 

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

Similar Threads


Top