FormClosing 이벤트를 처리 할 수 있습니다. 처리기에서 양식을 닫기 전에 작업을 수행 할 수 있으므로 닫는 이벤트를 취소 할 수도 있습니다. 다음은 예입니다 :
Dim Saved As Boolean = False
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If Not Saved Then
Dim Result As DialogResult = MessageBox.Show("Do you want to save your text?", "Save Text?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
Select Case Result
'Since pressing the No button will result in closing the form without
'saving the text we don't need to handle it here
Case Windows.Forms.DialogResult.Yes
SaveText_Click()
Case Windows.Forms.DialogResult.Cancel
e.Cancel = True
End Select
End If
End Sub
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
Saved = False
End Sub
'SaveText is a button for the user to manually save the text on demand.
'Since we don't need the sender or the eventargs, we can handle the click event without them.
'this way we can call this like any sub without having to worry about providing the right parameters.
Private Sub SaveText_Click() Handles SaveText.Click
'Add your procedure to save the text here
Saved = True
End Sub
당신이 옵션을 그냥 저장하지 않고 닫습니다하지 않으려면
는 메시지 박스와 선택 블록을 생략하고 그냥 거기에 데이터를 저장하는 SaveText을 (전화) 및 코드를 포함한다.
이 VBA 또는 VB.net입니까? – enderland
@enderland, VB.net을 사용하여 요청 해 주셔서 감사합니다. – XXXXXXXXXXXXXX