VB icon

Make Form Transparent on Move and Resize

Email
Submitted on: 1/2/2015 4:54:00 PM
By: Chris Pietschmann (from psc cd)  
Level: Beginner
User Rating: By 8 Users
Compatibility: C#, VB.NET
Views: 1350
 
     Make your Form transparent when it is Moved and Resized with this little code snippet. I think this adds a nice touch to any user interface. This wont make your forms transparent on Win98/WinME because those versions don't support transparencies, but this will work perfect on Win2K, WinXP and Windows Longhorn.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Make Form Transparent on Move and Resize
// Description:Make your Form transparent when it is Moved and Resized with this little code snippet. I think this adds a nice touch to any user interface. This wont make your forms transparent on Win98/WinME because those versions don't support transparencies, but this will work perfect on Win2K, WinXP and Windows Longhorn.
// By: Chris Pietschmann (from psc cd)
//**************************************

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
 'Check the state of the Left Mouse Button
 If CLng(m.Msg) = WM_NCLBUTTONDOWN Then
'set LButtonDown to True is Left Mouse Button is down
LButtonDown = True
 ElseIf CLng(m.Msg) = WM_NCLBUTTONUP Then
'set LButtonDown to False is Left Mouse Button is not down
LButtonDown = False
 End If
 If LButtonDown Then
If CLng(m.Msg) = WM_MOVING Then
'Set the forms opacity to 50% if user is draging the window
If Me.Opacity <> 0.5 Then Me.Opacity = 0.5
ElseIf CLng(m.Msg) = WM_SIZE Then
'Set the forms opacity to 50% if user is resizing the window
If Me.Opacity <> 0.5 Then Me.Opacity = 0.5
End If
 ElseIf Not LButtonDown Then
If Me.Opacity <> 1.0 Then Me.Opacity = 1.0
 End If
 MyBase.DefWndProc(m)
 End Sub


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.