[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


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

Posted on 2004-11-01
Medium Priority
Last Modified: 2010-04-24
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.

Question by:majnun
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 12469385
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.


Author Comment

ID: 12469863
Can you break this down into plain english? It's way over my head.

Accepted Solution

andrewharris earned 2000 total points
ID: 12470284
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


Author Comment

ID: 12483796
And then I check for the mouse position in the form's onClick event?

Author Comment

ID: 12858446
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.

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question