关闭form前提示是否保存

在form的formclosing事件中加上判断:

 

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!would you like to save?", "Save file", MessageBoxButtons.YesNoCancel) = Windows.Forms.DialogResult.Yes Then '提示是否保存
            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

posted on 2008-11-24 09:42  小灰熊  阅读(305)  评论(0编辑  收藏  举报

导航