VB.Net에서 종료 대화 상자의 구현 확인

코드를 두드릴 때 더욱 인성화된 디자인을 위해 우리는 사용자가 시스템을 종료하기 전에 다음과 같은 힌트를 해야 한다.
   
실현 방법은 두 가지로 나뉘는데 그것이 바로 창 이벤트와 컨트롤 이벤트입니다. 다음은 하나하나 보여 드리겠습니다.
   

1. FormClosing 이벤트(이하 몇 가지 방법으로 나뉜다)


    a.
    Private Sub frmPractise_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MessageBox.Show("     ?", "    ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

    b.
    Private Sub Practise_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MsgBox("     ?", MessageBoxButtons.OKCancel, "    ") = Windows.Forms.DialogResult.Cancel Then
            e.Cancel = True
        End If
    End Sub

    c.
    Private Sub Practise_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim p As Integer
        p = MsgBox("         ?", MsgBoxStyle.OkCancel, "  ")
        If p = 2 Then
            e.Cancel = True
        End If
    End Sub

   
d. (가장 간단)
    Private Sub Practise_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MsgBox("         ?", MsgBoxStyle.OkCancel, "    ") = MsgBoxResult.Cancel Then e.Cancel = True
    End Sub

 
이상은 창 닫기 단추를 눌렀을 때의 사용법일 뿐입니다. 창 컨트롤에서 종료를 눌렀을 때 다음과 같은 방법으로 할 수 있습니다.
 

2. ButtonClick 이벤트

    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click

        If MsgBox("       ?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "  ") = MsgBoxResult.Yes Then
            Application.Exit()
        End If

    End Sub

 

좋은 웹페이지 즐겨찾기