Detect mouse click on winform titlebar
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%.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
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
Original Comments (3)
Recovered from Wayback Machine