Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Studio app closes when using Me.Close() & Me.Hide()

Status
Not open for further replies.

Catadmin

Programmer
Oct 26, 2001
3,097
US
Okay, this is aggrivating and the threads I found when searching this forum don't help or I don't understand them well enough.

I'm using Visual Studio to develop a Windows VB .Net app. I've got two forms: the startup and the child which is opened in front by a button on the startup. I have a "cancel" button on the child for closing out the child form, but I want the startup form to stay there and be able to open future child forms.

I tried a Me.Close() in the child form's cancel button, but it closed out the entire app (I was debugging in VS 2k5). I tried Me.Hide() per a suggestion from another thread and got the very same behavior. None of the forms have "DIM xxx" in any of the code I see.

Can someone help me figure out how to close the child form while leaving both the App running and the startup form (which is behind the child form) open?

Thanks,



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
How are you opening the parent form? How are you opening the child form?

When the primary thread ends, the application will close. So if the child is the parent of the primary thread, and it closes (or is hidden due to the way GDI works) it will end the thread.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
The child shouldn't be the parent of the primary form, unless I'm missing something obvious...

Anyway, here's what I've got:

Code:
Public Class ChooseEnvironment

    Private Sub ChooseEnvironment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.CenterScreen
    End Sub
'The above opens the startup form in the center of the screen
....
'other subs for buttons which set variables
...
    Private Sub ChooseDBButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChooseDBButton.Click
        CreateMyConnection(MyEnv)
        My.Forms.BackupDatabase.ShowDialog()
    End Sub
'This sub opens the child form
End Class

I've checked the Project page and StartUp form is listed as ChooseEnvironment.



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
DOH!!!

Nevermind. I was cutting n pasting from another app and accidently got an "END" right after the Me.Hide() in the button event.

No wonder it kept closing everything... Sorry for taking up everyone's time. I've got it fixed now.



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
VB.Net 2003 w/ Crystal Viewer form

I have the exact opposite problem. I'm opening one form (a viewer), from another (the app startup form), but would like to close both forms (in other words the whole app) when the viewer is closed. Although I can get them all to "disappear" (using Hide, etc.), I can't get the entire app to close from the viewer. Although it appears closed, when I look at Task MAnager, it is still there. I've searched through dozens of references to Hide(,) Close(), Exit(), Dispose() and on & on, and have yet to find the answer (the help is terrible sometimes).

What I have been doing is opening the Startup form, pressing a button which opens the viewer form, and at the same time hides the startup form (that works fine) - then I am trying to close the hidden startup form, when the viewer is closed (I've also tried closing it when the viewer opens). I've tried re-"Showing" and then closing the hidden startup form, and everything else I could find. Still no luck.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top