Free Hit Counters

Saturday, January 22, 2011

Form Transparent while Dragging


Private Const WM_NCLBUTTONDOWN As Long = &HA1
    Private Const WM_NCLBUTTONUP As Long = &HA0
    Private Const WM_MOVING As Long = &H216
    Private Const WM_SIZE As Long = &H5
    Protected Overrides Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
        Static LButtonDown As Boolean
        ' checks left click
        If CLng(m.Msg) = WM_NCLBUTTONDOWN Then
            ' as long as left button is down LButtonDown returns true
            LButtonDown = True
        ElseIf CLng(m.Msg) = WM_NCLBUTTONUP Then
            ' As long as left button is up, LButtonDown returns false
            LButtonDown = False
        End If
        If LButtonDown Then
            If CLng(m.Msg) = WM_MOVING Then
                ' Changes form opacity to 70% if the form is being dragged
                ' You can change the 0.7 to anything 0.1 = 10% 0.2 = 20 % and so on
                If Me.Opacity <> 0.9 Then Me.Opacity = 0.5
            ElseIf CLng(m.Msg) = WM_SIZE Then
                ' Set the forms opacity to 60% if user is resizing the window
                If Me.Opacity <> 0.6 Then Me.Opacity = 0.6
            End If
        ElseIf Not LButtonDown Then
            If Me.Opacity <> 1.0 Then Me.Opacity = 1.0
        End If
        MyBase.DefWndProc(m)
    End Sub

No comments:

Post a Comment

Free Hit Counters