'show confirm close message in all project forms vb.net?

I have Project containing multi forms main page and others inside main page used next code to make confirm close in main page

Public Sub MyForm_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles MyBase.FormClosing
        If MessageBox.Show("Do you want to close the form?", "Confirm", MessageBoxButtons.YesNo) <> DialogResult.Yes Then
            e.Cancel = True
        End If
    End Sub

and want the confirm message to show in all forms not only main page !



Solution 1:[1]

Here is a process I use because MessageBox while it is nice I like to design my own.
You will see some variables in the code that look like this

Public gvalertType As String
Public gvRESEdit As String

These are declared in a Module
Now we need some code for the frmAlert You will use If and ElseIf to trap multiple errors. I will post a screen shot of the frmAlert

Private Sub frmAlert_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    If gvalertType = "10" Then
        btnNO.Visible = True
        lblAI.Text = " Caution "
        tbAlert.Text = "OK To Delete        " & vbCrLf & vbCrLf & "NO Do NOT Delete"
    End If
End Sub
    Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
    If btnNO.Visible = True Then
        gvRESDelete = "YES"
    End If
    Close()
End Sub

Private Sub btnNO_Click(sender As Object, e As EventArgs) Handles btnNO.Click
    gvRESDelete = "NO"
    Close()
End Sub

OK Now on the form and button click that calls the frmAlert.
Because you are changing forms this is why the variables are declared in a Module.

 Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
    gvalertType = "10"
    frmAlert.ShowDialog()
    If gvRESDelete = "NO" Then
        btnBack.Focus()
        Return
    End If
    If gvRESDelete = "YES" Then
        DeleteSiteData()
    End If
End Sub

Form Alert

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vector