[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

VB. NET: Handle Titlebar clicks, hovers, and other events

Is it possible to wire events to a forms titlebar?

For example I want to do something when the user hovers over the title bar, or clicks the title bar, etc.

Thanks!
0
majnun
Asked:
majnun
  • 3
  • 2
1 Solution
 
andrewharrisCommented:
You can do as this points out http://forums.devshed.com/archive/t-183681 and place the following code in form code.

Overrides Protected Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)

If m.Msg = &H84 And IntPtr.op_Equality(m.Result, New IntPtr(2))
m.Result = New IntPtr(1)
End If
End Sub

The if the mouses Y co-ordinates is < 0 then you are on the titlebar.

Andrew
0
 
majnunAuthor Commented:
Can you break this down into plain english? It's way over my head.
0
 
andrewharrisCommented:
To start with I will make the method a little more clear:

    Protected Overrides Sub WndProc(ByRef windowMessage As Message)
        Const WM_NCHITTEST As Integer = &H84 ' Mouse Event
        Const HTCLIENT As Integer = &H1 ' Form Area
        Const HTCAPTION As Integer = &H2 ' Titlebar Area

        ' Call the standard WndProc Method that would have been called anyway
        MyBase.WndProc(windowMessage)

        ' If a Mouse Event happened AND the Event was that the mouse was moved over the Titlebar
        If windowMessage.Msg = WM_NCHITTEST And IntPtr.op_Equality(windowMessage.Result, New IntPtr(HTCAPTION)) Then
            ' Then "Change" the event to think it was in the Form Area
            m.Result = New IntPtr(HTCLIENT)
        End If
    End Sub

Have a read of this article...Its pretty good. http://support.microsoft.com/default.aspx?kbid=320684

Andrew
0
 
majnunAuthor Commented:
And then I check for the mouse position in the form's onClick event?
0
 
majnunAuthor Commented:
I haven't had a chance to try to implement it (this particular project is no longer the clients top priority), so I can't say for sure it works, but it sounds reasonable.

Sorry for the hold up.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now