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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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)

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.

majnunAuthor Commented:
Can you break this down into plain english? It's way over my head.
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

        ' 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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
majnunAuthor Commented:
And then I check for the mouse position in the form's onClick event?
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.