multiple forms
-
i have two forms say form1 and form2... on clicking button1 on form1 , form2 gets open... form2 has 2 two buttons back and close i have dne coding in this way: form1 : button1_click event dim a as new form2 a.show() me.hide() form2: for close button me.close() my problem is on clicking close buttton of form2, form2 gets close but form1 which is already hidden doesnt close... i want that wen i click close buttton all the hidden and active forms should close... and debugging should stop.. thanks for any kind of help.
-
i have two forms say form1 and form2... on clicking button1 on form1 , form2 gets open... form2 has 2 two buttons back and close i have dne coding in this way: form1 : button1_click event dim a as new form2 a.show() me.hide() form2: for close button me.close() my problem is on clicking close buttton of form2, form2 gets close but form1 which is already hidden doesnt close... i want that wen i click close buttton all the hidden and active forms should close... and debugging should stop.. thanks for any kind of help.
Change the
Shutdown Mode
in your project properties.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
Change the
Shutdown Mode
in your project properties.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
sorry i am not able to see any option in project property window... can u explain a little bit more.....
manni_n wrote:
sorry i am not able to see any option in project property window...
Are you using Visual Studio 2.0? If not, then just add
Form1.close()
to your close button on form2.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
manni_n wrote:
sorry i am not able to see any option in project property window...
Are you using Visual Studio 2.0? If not, then just add
Form1.close()
to your close button on form2.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
i am using VS 2003. and about form1.close() i have already used this one, its not working telling that refernce to non shares members need object refernce... i am ussing me.close, but if i apply it on form2 then this works for form2 2 only , form1 still remains hidden..
-
i am using VS 2003. and about form1.close() i have already used this one, its not working telling that refernce to non shares members need object refernce... i am ussing me.close, but if i apply it on form2 then this works for form2 2 only , form1 still remains hidden..
manni_n wrote:
i have already used this one, its not working telling that refernce to non shares members need object refernce...
It works fine for me. Could you post your full code for the Form2 close button?
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
manni_n wrote:
i have already used this one, its not working telling that refernce to non shares members need object refernce...
It works fine for me. Could you post your full code for the Form2 close button?
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
there is no such great code involved in close button... i have jst used like... button2_click() me.close() end sub thats it... and if i also write form1.close then its shows the error i told u in previous post.... you do one thing just tell me your way, i'll implement that method... i just want to close all forms whenevr close button is clicked.. whether its on form2 or any other form say next form form3 or form4.
-
there is no such great code involved in close button... i have jst used like... button2_click() me.close() end sub thats it... and if i also write form1.close then its shows the error i told u in previous post.... you do one thing just tell me your way, i'll implement that method... i just want to close all forms whenevr close button is clicked.. whether its on form2 or any other form say next form form3 or form4.
Alright, just to make sure, goto your project properties (Project Name Properties). Click
Application
, from there, you should have an option that saysShutdown Mode
(or something similar). If there's no such option, then try the following:Dim x As Integer For x = 0 To (Me.OwnedForms.Length) - 1 Me.OwnedForms(x).Close() Next x
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
i have two forms say form1 and form2... on clicking button1 on form1 , form2 gets open... form2 has 2 two buttons back and close i have dne coding in this way: form1 : button1_click event dim a as new form2 a.show() me.hide() form2: for close button me.close() my problem is on clicking close buttton of form2, form2 gets close but form1 which is already hidden doesnt close... i want that wen i click close buttton all the hidden and active forms should close... and debugging should stop.. thanks for any kind of help.
Give this a try. What I've done is added a handler for the child forms formclosed event. This way we know when the child is closed and can close too.
Public Class Form1
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As New Form1 'Register our method (ChildClosed) with the new forms FormClosed event AddHandler a.FormClosed, AddressOf ChildClosed a.Show() End Sub 'When the child closes this method will run which will close the current form Private Sub ChildClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Me.Close() End Sub
End Class
***EDIT*** Also what are you doing to go back? **EDIT2*** Oh, ya. You can also just use 'End' or 'Application.exit' to shutdown everything. I forgot about the easy answer :)
-
i have two forms say form1 and form2... on clicking button1 on form1 , form2 gets open... form2 has 2 two buttons back and close i have dne coding in this way: form1 : button1_click event dim a as new form2 a.show() me.hide() form2: for close button me.close() my problem is on clicking close buttton of form2, form2 gets close but form1 which is already hidden doesnt close... i want that wen i click close buttton all the hidden and active forms should close... and debugging should stop.. thanks for any kind of help.
The right way to do this, is to have the two forms defined as user controls and showing them both on the one form, your button changes which is visible.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Give this a try. What I've done is added a handler for the child forms formclosed event. This way we know when the child is closed and can close too.
Public Class Form1
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As New Form1 'Register our method (ChildClosed) with the new forms FormClosed event AddHandler a.FormClosed, AddressOf ChildClosed a.Show() End Sub 'When the child closes this method will run which will close the current form Private Sub ChildClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Me.Close() End Sub
End Class
***EDIT*** Also what are you doing to go back? **EDIT2*** Oh, ya. You can also just use 'End' or 'Application.exit' to shutdown everything. I forgot about the easy answer :)
yeah this End and application.exit are working... well to go back i am coding like this.. suppose i am on form 2 and button "back" in back_click dim a as new form1 me.close() ' to close the existing form a.show() here thing is a new form1 gets open by this method... what if i want same form1 which is hidden...?? any idea.?
-
yeah this End and application.exit are working... well to go back i am coding like this.. suppose i am on form 2 and button "back" in back_click dim a as new form1 me.close() ' to close the existing form a.show() here thing is a new form1 gets open by this method... what if i want same form1 which is hidden...?? any idea.?
You could use the same code I posted earlier. However, instead of closing form1 when the child is closed you would just show it. Form2 doesn't need to worry about form1 at all in this case. When the back button is clicked just call me.close. Form1's method will then get called because you registered that method with form2's closed event.