Control Form Closing Order in MDI Application in

Good Morning! I had a pretty good night sleep for a change and am getting ready for my trip to Madison WI this week. Otherwise not a whole lot going on. At work, I just completed the graphing portion of an application automating Excel. But like I said not a whole lot going on. I am looking for a graphing component I can use in an ASP.NET web page but it is not urgent.

Today’s topic is if you wish to shut down your MDI application and control the closing order of the forms. Make it a great day!

Join me on Facebook

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace WindowsFormsApplication1
    Public Partial Class Form1
        Inherits Form
        Public Sub New()
        End Sub
        Public Const SC_CLOSE As Integer = &Hf060
        Public Const WM_SYSCOMMAND As Integer = &H112
        Protected Overloads Overrides Sub WndProc(ByRef m As Message)
            Select Case m.Msg
                Case WM_SYSCOMMAND
                    If CInt(m.WParam) = SC_CLOSE Then
                        ‘ <— the USER initiated the close
                        If MessageBox.Show("Quit?", "Closing…", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

= DialogResult.No Then
                            Exit Sub
                            ‘ don’t allow "base.WndProc(ref m)" to execute below
                        End If
                    End If
                    Exit Select
            End Select
        End Sub
        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            ‘ just FYI…
            ‘ programmatically closing the form will NOT trigger the messagebox in WndProc() above
        End Sub
    End Class
End Namespace

Technorati Tags: ,,,,,,,,,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: