954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Loading and closing form in VB 2005

Dear Sir/Madam,

I have two form in my application form1 and form2. Here, i want to show the form2 from form1 by using a button. And i want to reverse back to my form1 from form2 using same technique. But i want to close form1 (Not visible=false or hide) after loading form2 and same thing in reverse back also.

I have tried like this....

'for from1
form2.show()
'form1.close ' not accepted
me.close


In my above code whole application is closing.

'for form2
form1.show()
me.close()


Here it is working in form2

I want to know that can we close our current form after showing another form? Please guide me.

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

Because VB.NET version 2005 and later version uses "Default Form Instance". ( here is good discussion) It means the name of Form (or you can say class name) represents an instance (object reference) and of course the form inside you are working is also an instance of same form. In short you can't use or access the members of current form using "Default Form Instance" name, use Me instead.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Dear Adatapost,

Thanks for replying sir, i understand that i can't access the members of current form using "Default Form Instance" name. My question is that can't we close the form1 after showing the form2? And when i use me.close in form1 (as i have mentioned earlier) the whole program is closing.

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

That is because your Form1 is your applications main form.
Rather just hide form1

Me.Hide()


Hope this helps.

Animal Mother
Light Poster
39 posts since Aug 2010
Reputation Points: 18
Solved Threads: 7
 

Dear Animal Mother,

Thanks for replying sir, Hiding and making visible = False, i can do that as i have mentioned in my thread also. May be it is not possible for closing form1 after loading/showing form2. Because it is possible in VB 6.0. I just want to know that things.

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

I apologize I don't know how I missed that.
What I did was set a form up to be my projects main form but the form is never used and is always hidden.
Instead of showing the main form on load I showed form1.
When doing this you can close and load forms as you please without having the application close, as long as you don't touch the main form(the hidden one). And when you want to exit your application you just use.

Application.Exit()

There is probably a better way to do this, but not one that I know of.

Animal Mother
Light Poster
39 posts since Aug 2010
Reputation Points: 18
Solved Threads: 7
 

why dont you try using IsMDIContainer

vanzhyme
Light Poster
45 posts since Jan 2011
Reputation Points: 14
Solved Threads: 5
 

Dear Animal Mother,

Hiding my form1 (first form) and as you told, hiding first form completely for closing and showing other form is more or less same. Actually, i want to free the complete memory which is taking by form1. Anyway, thanks for your suggestion sir.

Dear Vanzhyme,

Thanks for replying sir, but sorry, right now I don't want to use IsMDIContainer. Any other suggestion sir?

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

Try This

Me.Dispose(False)
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

Dear Sir/Madam,

I have two form in my application form1 and form2. Here, i want to show the form2 from form1 by using a button. And i want to reverse back to my form1 from form2 using same technique. But i want to close form1 (Not visible=false or hide) after loading form2 and same thing in reverse back also.

I have tried like this....

'for from1
form2.show()
'form1.close ' not accepted
me.close

In my above code whole application is closing.

'for form2
form1.show()
me.close()

Here it is working in form2

I want to know that can we close our current form after showing another form? Please guide me.

Hi,

You just need to go to the properties of your application and set:Shutdownmode = When last form closes

Your application will only close when last form closes.

Luc001
Posting Whiz
376 posts since Mar 2010
Reputation Points: 85
Solved Threads: 98
 

I apologize I don't know how I missed that. What I did was set a form up to be my projects main form but the form is never used and is always hidden. Instead of showing the main form on load I showed form1. When doing this you can close and load forms as you please without having the application close, as long as you don't touch the main form(the hidden one). And when you want to exit your application you just use.

Application.Exit()

There is probably a better way to do this, but not one that I know of.

You have said, "set a form up to be my projects main form but the form is never used and is always hidden." But what if at some point there is bug and it closes all of the visible forms but not call Application.Exit(). The app will be running forever, isn't it?

Thanks for the tip. It may be useful for some other ways.

PdotWang
Newbie Poster
20 posts since Mar 2011
Reputation Points: 27
Solved Threads: 5
 

Dear CodeOrder and Luc001,

Thanks for replying with right answer. It has solved my thread.

And thank you all for replying to my thread.

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

You have to change the propierties of your Project in order to make the program closing until ALL FROMS are closed. You will be able to Open Form2 (before) and Close Form1 (After) with out the program get closed.

In the Editor Menu: Project -> Properties of [Project Name]
Project Properties will apear on a new tablet
In "Application" look for something like: "Turn Off Mode" and select something like "When closing last form"

Abiba
Newbie Poster
1 post since Mar 2012
Reputation Points: 10
Solved Threads: 0
 

Dear Abiba,

The thread had been marked as SOLVED on 21st March 2011 by me as i had got the answer. So, there is not need to reply on this thread.

Probably, you have posted without observing that. Anyway, welcome to Daniweb and waiting for more reply from your side on unsolved thread.

Thanks

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: