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.

Recommended Answers

All 3 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.