הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Sunday, May 8, 2016 12:37 PM
When I run the Visual studio debugger on a program with a series of forms, I sometimes click the 'x' of a form, I find that it closes the program only if I'm on the first form. If I go from the first form to the second form, and click that 'x', the form closes, but the program is still active and I have to go to the Visual Studio menu and click 'stop debugging' to end the program.
The reason for this is that the first form has a "NEXT >>" button, and when you click on that, the button event does two things:
1. me.hide
2. form2.show
So the first form, while invisible, is still present, and the program will not shut down when I click the 'x' in form2 (or in form3).
If I could have done:
1. me.close
2. form2.show
in the first form, I would have done that, but I find that this terminates the program instead of moving to the next form (form2).
So what do I do? Do I have to keep a list of handles to forms and go through them, closing each one, when a user click on an 'x' in a form that follows the first form?
Thanks.
All replies (1)
Sunday, May 8, 2016 12:52 PM ✅Answered | 1 vote
If you go to your Project`s Properties you can set the "Shutdown Mode" to "When Last Form Closes" as shown in the image below. Then instead of Hiding the first form, you close the first Form after showing the second Form as shown in the code below the image.
Dim f2 As New Form2
f2.Show()
Me.Close()
If there is some reason that you need to leave the first Form opened and just want to hide it, then in the second form you can use the Application.Exit method lin the Form.Closed event.
Private Sub Form2_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
Application.Exit()
End Sub
If you say it can`t be done then i`ll try it