Change Opacity When Dragging The Form In VB.NET

this is something awesome , i hope you understand what this actually do . open your visual basic 2008/2010 and create a new project and double click your form and add this code

Public Class Form1
    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
        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
End Class

code is explained now just debug your application and drag the form and enjoy this awesome effect

here is a video of how it works

Post a Comment