E.cancel loop in Visual basic

Posted by Ahmed on Stack Overflow See other posts from Stack Overflow or by Ahmed
Published on 2012-08-27T11:03:59Z Indexed on 2012/08/28 9:38 UTC
Read the original article Hit count: 282

Filed under:

I am making an server control application ( simple with some buttons to start/stop the server ) And when the user wants to close the application there will be prompted an confirm box.

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing

    Dim response As Integer
    response = MsgBox("Are you sure you want to stop the server", vbYesNo, "Stop Server ?")
    If response = vbYes Then
        Shell("cscript ""stop.vbs""", 1)
        Close()
    Else
        e.Cancel = True
    End If
End Sub

That is the code I have now. But when I start the application and close it with the X button or with "Close Window" I will be prompted with the question until I click on no, then it will close. It's a loop and it stops when you first click on yes then on no.

Can someone help me with solving this ?

© Stack Overflow or respective owner

Related posts about vb.net