مي توني به روش زير عمل كني!
PrivateSub SubForm_FormClosing(ByVal sender AsObject, ByVal e As System.Windows.Forms.FormClosingEventArgs) HandlesMe.FormClosing
Try
Dim Response As MsgBoxResult
Response = MsgBox("Do you want to close this Form?" & vbCrLf & vbCrLf & "All unsaved data will be lost!", MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Question, Me.Text)
If Response = MsgBoxResult.Yes Then
ExitSub
ElseIf Response = MsgBoxResult.No Then
e.Cancel = True
EndIf
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation And MsgBoxStyle.OkOnly, "Error")
EndTry
EndSub