Problem with multiple forms

Roberto

Member
Joined
Mar 9, 2006
Messages
16
Programming Experience
Beginner
Hi, i'm building an application with 26 forms with a list of items on each page sorted by letter, so have FormA, FormB, FormC etc. There are buttons the user clicks to open whichever letter they want. I want to be able to open the Form and close the previous one at the same time. I've played around with Show and Hide but don't want lots of Forms in memory, i'm sure this is a simple solution but cannot find it. Thanks in advance for anyone's time on this.
 
Well, you would do this:

VB.NET:
FormB.Show()
FormA.Close()

That would be put into the 'Click' event for the button. You would change the form names accordingly.

Hope that helps.
 
I've tried:

VB.NET:
FormB.Show
FormA.Close

But i get

WindowsApplication1.FormA cannot refer to itself through its default instance; Use 'Me' instead

I change it to
VB.NET:
FormB.Show
Me.Close

This gets rid of the error but then the program just ends
 
Your application is probably closing because you are starting the application using a form, rather than Sub Main. You'll need to call sub Main and start your first form from there.

Having said that, would it not be better to replace 26 forms with either :-

1. 26 panels on one form (hiding, showing and BringToTop as necessary)
2. a Tabcontrol with 26 TabPages on one form
3. one panel, and re-use & re-label the controls according to the appropriate letter
 
You don't really have to do that. You can just change th shutdown mode to 'When last form closes'. It is defaulted to 'When startup form closes'

It is on the Project page.
 
I've gone with the multiple ListBoxes set to show and hide on the one form.
My project can move forward now so thankyou very much both of you for your help on this.
 
Back
Top