Click here to Skip to main content
Licence 
First Posted 1 Jun 2004
Views 29,340
Bookmarked 12 times

How to detect a left mouse click on a Winform titlebar

By | 1 Jun 2004 | Article
This simple code will trap a left mouse click on a winform titlebar and sets the opacity of the form to 50%, when the left mouse button is released the forms opaccity is set back to 100%
       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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

TheAphextwin

Web Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow to detect a left mouse click on a Winform titlebar [modified] PinmemberMorteza Karimian3:31 19 Feb '11  
GeneralRocks PinmemberNeo-Code15:17 23 Jul '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 2 Jun 2004
Article Copyright 2004 by TheAphextwin
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid