0

How can I trigger my "save" event when a user clicks the 'X' on the control box? I have code written for saving all of the information, but I don't know how to modify the control box features other than declaring it true or false.

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Begginnerdev
0

if user clicks on X button call the save_click event in the form_formclosing event....
before that u can ask the user with a msg box whether the user wants to save the form or just close without saving.....if user wants to save call the save event else dispose the form...

chrck below

write the below event for ur form1_formclosing

Dim dr As Object
    If e.CloseReason = CloseReason.UserClosing Then
       dr = MsgBox("Do you want to save the changes?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question)
       If dr = vbYes Then
          Me.Dispose()
          e.Cancel = False
       Else
          btnSave(sender,e)
    End If
End If
0

You will want to do the reverse of what poojavb has posted.

Dim dr As Object    
If e.CloseReason = CloseReason.UserClosing Then       
    dr = MsgBox("Do you want to save the changes?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question)       
    If dr = vbNo Then          
        Me.Dispose()          
        e.Cancel = False       
    Else          
        btnSave(sender,e)
        Me.Dispose()          
        e.Cancel = False  
    End If
End If

If the user pressed YES it would have just disposed.

Edited by Begginnerdev

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.