DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009

    Question Detecting mouse button down & up events on the system menu of form.

    How do I detect left mouse button down and up events on the 'Close' option of the system menu that appears when the mouse is clicked on the top left corner of a form?

  2. #2
    Join Date
    Feb 2014
    Riviera Beach, Maryland, USA

  3. #3
    Join Date
    Mar 2009

    Thumbs up

    Here’s what I found. Though it’s not exactly what I originally posted for but at least it narrows down to my requirement.

    Instead of identifying separately if the user clicked the Close button at the top right corner of the title bar of the form or the ‘Close’ option in the system menu, or he/she pressed the Alt+F4 keys, we can combine these factors together to check if the user is consuming the system command (i.e. any of the above three techniques) to close the form or is doing so programmatically. If the system command is used, action is taken accordingly; else we ignore.

    A button is used to close down the form programmatically without any interruption.

    Public Class Form2
        Private Const WM_SYSCOMMAND As Integer = &H112
        Private Const SC_CLOSE As Integer = &HF060
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            ' Check if the user is consuming the system command to close the form.
            If (m.Msg = WM_SYSCOMMAND) AndAlso (CInt(m.WParam) = SC_CLOSE) Then
                MsgBox("Form closing by system command. Take necessary actions here...")
            End If
        End Sub
        Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        End Sub
    End Class

  4. #4
    Join Date
    Feb 2014
    Riviera Beach, Maryland, USA
    When a program won't allow using a "system command" to close a window, some simply yank the plug.

Similar Threads

  1. Replies: 2
    Last Post: 12-14-2005, 01:36 AM
  2. Replies: 0
    Last Post: 03-17-2005, 11:47 AM
  3. Form's menu in system menu
    By anonymous in forum VB Classic
    Replies: 0
    Last Post: 12-31-2001, 09:04 AM
  4. Removing system menu item without changing form
    By John Knoop in forum VB Classic
    Replies: 1
    Last Post: 09-20-2001, 05:51 AM
  5. Detecting the ather mouse button
    By anonymous in forum VB Classic
    Replies: 0
    Last Post: 02-14-2001, 06:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.