שתף באמצעות


Capture Form Title Bar Double Click Event.

Question

Monday, January 1, 2018 2:58 PM

Recently I asked about a method to capture the event when a user clicks on the 'Maximise' icon.  IronRazerz proposed the method repeated below.  That method has been very successful - thank you.  I would like to also capture a double click on the Title Bar of the Child Forms.  How could the method be modified to trap the Form Title double click?  I have looked at WM_SYSCOMMAND message but could not find a reference to the Form Title.  Many thanks.

Public Class Form1
    Private Const WM_SYSCOMMAND As Integer = &H112
    Private Const SC_MAXIMIZE As Integer = &HF030

    Protected Overrides Sub WndProc(ByRef m As Message)
        If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_MAXIMIZE Then
            Me.Bounds = New Rectangle(0, 0, 500, 300)
            m.Result = CType(0, IntPtr)
            Return
        End If
        MyBase.WndProc(m)
    End Sub
End Class

Margarita_Cody

All replies (2)

Monday, January 1, 2018 3:26 PM ✅Answered

 You can also check to see if the window message is a WM_NCLBUTTONDBLCLK message which indicates that the left mouse button has been double clicked in a non-client area of the form.  If this message is received,  you can check the wParam of the message to see if it is the HTCAPTION message which is a Hit Test message described in the WM_NCHITTEST message document.

 

Public Class Form1
    Private Const WM_NCLBUTTONDBLCLK As Integer = &HA3
    Private Const HTCAPTION As Integer = &H2
    Private Const WM_SYSCOMMAND As Integer = &H112
    Private Const SC_MAXIMIZE As Integer = &HF030

    Protected Overrides Sub WndProc(ByRef m As Message)
        If (m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_MAXIMIZE) OrElse (m.Msg = WM_NCLBUTTONDBLCLK AndAlso m.WParam.ToInt32 = HTCAPTION) Then
            Me.Bounds = New Rectangle(0, 0, 500, 300)
            m.Result = CType(0, IntPtr)
            Return
        End If
        MyBase.WndProc(m)
    End Sub
End Class

If you say it can`t be done then i`ll try it


Monday, January 1, 2018 3:29 PM

Excellent.  Thank you.

Margarita_Cody