Solved

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

Posted on 2004-11-01
387 Views
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.

Thanks!
0
Question by:majnun
    5 Comments
     
    LVL 4

    Expert Comment

    by:andrewharris
    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
     

    Author Comment

    by:majnun
    Can you break this down into plain english? It's way over my head.
    0
     
    LVL 4

    Accepted Solution

    by:
    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
     

    Author Comment

    by:majnun
    And then I check for the mouse position in the form's onClick event?
    0
     

    Author Comment

    by:majnun
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    857 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now