Click here to Skip to main content
15,892,059 members
Articles / Programming Languages / Visual Basic
Article

How to detect a left mouse click on a Winform titlebar

Rate me:
Please Sign up or sign in to vote.
2.21/5 (14 votes)
1 Jun 2004 52.3K   12   2
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


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow to detect a left mouse click on a Winform titlebar [modified] Pin
Morteza Karimian Kelishadrokhi19-Feb-11 3:31
Morteza Karimian Kelishadrokhi19-Feb-11 3:31 
GeneralRocks Pin
James Garner (jadaradix)23-Jul-08 15:17
James Garner (jadaradix)23-Jul-08 15:17 

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

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