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.

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.

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.

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

Me.Hide()

Hope this helps.

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.

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.

why dont you try using IsMDIContainer

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?

Try This

Me.Dispose(False)

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.

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.

Dear CodeOrder and Luc001,

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

And thank you all for replying to my thread.

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"

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

commented: :) +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.