Try it like this :
Protected Overrides Sub OnFormClosing(e As System.Windows.Forms.FormClosingEventArgs)
Dim myResult As DialogResult = MessageBox.Show(Me, "FormClosing-Message", "Caption-Text", MessageBoxButtons.YesNo)
If myResult = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
MyBase.OnFormClosing(e)
End Sub
I don't use the Event but the Event-calling-Method.
You don't Need to do anything when DialogResult is "Yes" - it is the normal case ...
and additional as C#-Code :
protected override void OnFormClosing(System.Windows.Forms.FormClosingEventArgs e)
{
DialogResult myResult = MessageBox.Show(this, "FormClosing-Message", "Caption-Text", MessageBoxButtons.YesNo);
if (myResult == Windows.Forms.DialogResult.No) {
e.Cancel = true;
}
base.OnFormClosing(e);
}