[TuT]Preventing your Program from Closing

Posts 1–5 of 5 · Page 1 of 1
[TuT]Preventing your Program from Closing
Add this code to your form.
Code:
    Private Sub Form1Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        e.Cancel = True
    End Sub
If you want to be able to exit, add this code to a button
Code:
End
It should look something like this, IF your button is called Button1 and your form is called Form1
Code:
Public Class Form1

    Private Sub Form1Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        e.Cancel = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        End
    End Sub
End Class
Fail..... e.cancel = true is not right...Give a error!

Put: eventArgs.Cancel = True and then it will work...

Thank me if I helped!
Quote Originally Posted by Zoom View Post
Fail..... e.cancel = true is not right...Give a error!

Put: eventArgs.Cancel = True and then it will work...

Thank me if I helped!
You need to have
Code:
 Private Sub Form1Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
huh.... I´m know that....
Quote Originally Posted by Zoom View Post
huh.... I´m know that....
If you knew that how come you said it gave an error?
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us