Add judgment in form's formclosing event:
Private Sub frmSequenceEditor_FormClosing (ByVal sender As Object, ByVal e As System. Windows. Forms. FormClosingEventArgs) Handles Me. FormClosing
If MessageBox. Show ("The file has changed! Wocould you like to save? "," Save file ", MessageBoxButtons. YesNoCancel) = Windows. Forms. DialogResult. Yes Then 'indicates whether to Save
DlgSaveFile. InitialDirectory = Application. StartupPath
DlgSaveFile. OverwritePrompt = True
DlgSaveFile. Filter = "BurnIN Files (*. DUT) | *. DUT | All Files (*. *) | *.*"
If (dlgSaveFile. ShowDialog (Me) = System. Windows. Forms. DialogResult. OK) Then
Dim FileName As String = dlgSaveFile. FileName
'Todo: Add code here to save the current contents of the form to a file.
Dim str As String = ConfigDataXml (dgvSequence)
DutData. SaveDutFile (FileName, str)
MessageBox. Show ("Save To Dut success! The file path is "+ FileName)
'End
End If
Else
End If
End Sub