Close Example VB

In this example, when the Close event fires, the code evaluates the ImageModified property to see if changes were made to the image.  If the value of the ImageModified property is True, the code prompts the user to save the image.

Private Sub ImgEdit1_Close()
    'This code could be used at the time a user attempts to open
    'a new file or clear a previously displayed image in order
    'to prompt for changes to be saved if the image has been modified.
    Dim intSaveImg As Integer

    If ImgEdit1.ImageModified = True Then
      intSaveImg = MsgBox("Do you want to save changes?", vbYesNoCancel,
       "Image has been modified")
      Select Case intSaveImg
        Case vbYes
          'Save the changes
          ImgEdit1.Save
          'Drop down to the Open file code
        Case vbNo
          'Don't save file, just drop down to the Open
          'file code
        Case vbCancel
          'User pressed cancel
          'Don't open a file, don't save changes
          Exit Sub
      End Select
    
    End If
    'Open a new file at this point
End Sub