Message Handler in VB.NET
-
Hi, I'm trying to add a GUI effect for a form in VB.NET that will cause the window to fade to 50% transparency when the title bar is clicked on. It's easy to get the form to fade, but I'm having trouble finding a way to capture the event of clicking on the title bar. Since this is a nonclient area of the window, VB does not raise one of the built-in events for forms. If anyone knows a way for me to capture the messages for when the title bar is clicked, I would be most happy... the only way i think i can do this is by writing a control in C++ that will capture the window messages and let VB know when the title bar has been clicked... thanks in advance.. Jon
-
Hi, I'm trying to add a GUI effect for a form in VB.NET that will cause the window to fade to 50% transparency when the title bar is clicked on. It's easy to get the form to fade, but I'm having trouble finding a way to capture the event of clicking on the title bar. Since this is a nonclient area of the window, VB does not raise one of the built-in events for forms. If anyone knows a way for me to capture the messages for when the title bar is clicked, I would be most happy... the only way i think i can do this is by writing a control in C++ that will capture the window messages and let VB know when the title bar has been clicked... thanks in advance.. Jon
Try this in the form code:
Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_NCLBUTTONDOWN Then
Me.Opacity = 0.5
End If
MyBase.WndProc(m)
End Sub -
Try this in the form code:
Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_NCLBUTTONDOWN Then
Me.Opacity = 0.5
End If
MyBase.WndProc(m)
End Sub -
Thanks a bunch, that worked just great.. one more question, is there a way to capture the left mouse button being released? I tried &HA2 as a code, but that is a double click (i think). Even Spy++ doesn't capture WM_NCLBUTTONUP. Thanks for the help!
&HA2 is the correct code, but the window never seems to get it! Spy++ seems to see it as a WM_LBUTTONUP with a negative y value, but that message never gets to the WndProc on the form. :confused:
-
&HA2 is the correct code, but the window never seems to get it! Spy++ seems to see it as a WM_LBUTTONUP with a negative y value, but that message never gets to the WndProc on the form. :confused:
Unfortunately, that's correct. I did some investigation this weekend and discovered that same problem. I think the only way to do this is to write a mouse hook to intercept the messages before Windows sends them to the form. I have a project that somebody did like this in C++ and i'm trying now to convert it to a DLL to use in my VB project.. i can post it here if I am successful, if you like. Jon