VB icon

Detect mouse click on winform titlebar

Email
Submitted on: 1/2/2015 4:50:00 PM
By: Mick George (from psc cd)  
Level: Beginner
User Rating: By 11 Users
Compatibility: VB.NET
Views: 1738
 
     Left mouse click on a winform titlebar to set the forms opacity to 50% while dragging the form, release the mouse to set the form opacity back to 100%.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :Detectmouse click on winform titlebar
//**************************************
Thanks to Franci Penov @ MS for pointing me to this C# example http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20701571.html
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Detectmouse click on winform titlebar
// Description:Left mouse click on a winform titlebar to set the forms opacity to 50% while dragging the form, release the mouse to set the form opacity back to 100%.
// By: Mick George (from psc cd)
//
// Assumes:This is handy if you have a modal dialog and you want to see something behind the dialog, just click it and move it to set the opacity.
Copy the code below to a Winform class and run it.
//**************************************

Private Const WM_NCLBUTTONDOWN As Long = &HA1
Private Const WM_NCLBUTTONUP As Long = &HA0
Protected Overrides Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
' -- You might want to trap for user clicking, min, max or close and ignore
' -- Trap left mouse click down on titlebar
If CLng(m.Msg) = WM_NCLBUTTONDOWN Then
' -- Set the forms opacity
If Me.Opacity <> 0.5 Then Me.Opacity = 0.5
' -- Trap left mouse click up on titlebar
ElseIf CLng(m.Msg) = WM_NCLBUTTONUP Then
If Me.Opacity <> 1.0 Then Me.Opacity = 1.0
End If
' -- Business as usual
MyBase.DefWndProc(m)
End Sub


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.