link to a form, then ok quits

whosyodaddy

Well-known member
Joined
Jun 23, 2003
Messages
83
how do you make it so that lets say you click on "Food" in the MainMenu on Form1, then Form2 comes up. And then when you click on the button OK on Form2, Form1 and Form2 quits?:confused: :D
 
You need to modify the constructor of Form2 (thats the New() sub) to accept a form as a parameter. So modify it to look like this:
Code:
Public Sub New(caller As Form)
        MyBase.New()
        InitializeComponent()

        m_fCaller = caller  You must define m_fCaller as a class level variable first
End Sub
Then, when you create the form on Form1, do this:
Code:
Dim f2 As New Form2(Me)

f2.Show()
When you wish to close both forms, in Form2, do this:
Code:
m_fCaller.Close()
Me.Close()
 
VF thats absolutely correct if you still want to do work in the application , but if whosyodaddy
wants to just quit the application he can simply use End
 
Remarks
The End statement can be placed anywhere in a procedure to end code execution, close files opened with an Open statement, and clear variables. The End statement calls the Exit method of the Environment class in the System namespace. System.Environment.Exit requires that you have SecurityPermissionFlag.UnmanagedCode permissions. If you do not, a SecurityException error occurs.

When executed, the End statement clears all variables at module and class level and all static local variables in all modules.

Note The End statement stops code execution abruptly, without invoking the Finalize method or any other Visual Basic code. Object references held by other programs are invalidated.
The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created and no code executing.

With an additional keyword, End delineates the end of the definition of the appropriate procedure or block.
 
Ill consider that as just as bad then ;)
I always avoided it in VB6 because of the way it abruptly ended a running app, seems like it does the same in .Net.
 
Sometimes it does have its uses, if your program hits a critical error, then you can show the error, run End, then it wont run things like any save code you have in your Exit events. Which means the next time your app loads, it will actually load :).
 
Back
Top