471,310 Members | 1,031 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Question on Working With Forms

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.
Jul 22 '05 #1
7 1144
Using VB.Net 2003
"Stingray5678" wrote:
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.

Jul 22 '05 #2
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
Jul 22 '05 #3
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?
"Cor Ligthert" wrote:
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

Jul 22 '05 #4
> 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
Jul 22 '05 #5
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)
"Cor Ligthert" wrote:
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

Jul 22 '05 #6
Stingray,

As I said the taskmanager is not giving the correct figurs

Calling GC cost you performance. I assume you know that.

Have a look at a message from Willy in this newsgroup.

http://groups-beta.google.com/group/...2c39983d?hl=en

Cor
Jul 22 '05 #7
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.

:-)

"Cor Ligthert" wrote:
Stingray,

As I said the taskmanager is not giving the correct figurs

Calling GC cost you performance. I assume you know that.

Have a look at a message from Willy in this newsgroup.

http://groups-beta.google.com/group/...2c39983d?hl=en

Cor

Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Damian Greene | last post: by
5 posts views Thread by Rasmus Kromann-Larsen | last post: by
1 post views Thread by Natalia DeBow | last post: by
reply views Thread by Dave Coate | last post: by
9 posts views Thread by Scott Stark | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.