Windows Blend Effect (Transparency) in VB.NET
This tutorial will teach you how to create a blend effect in your windows form or a transparency/opacity of the form using vb.net. This will use "user32" library of our computer system so that it will take effect.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Create only a Form in your project. Insert also a Timer on it. It's up to you to put any other controls on it.
3. Now, we will do the coding.
We will first declare the function named AnimateWindow to use the user32 library with the following values of it.
- Private Const AW_BLEND = &H80000
- Private Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Int32, ByVal dwTime As Int32, ByVal dwFlags As Int32) As Boolean
- Dim winHide As Integer = &H10000
- Dim winBlend As Integer = &H80000
We will first to code for ticking our Timer, we will have the form's opacity of it to activate the transparency of the Form.
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- Me.Opacity = Me.Opacity + 0.1
- If Me.Opacity = 1 Then
- Timer1.Enabled = False
- End If
- End Sub
Then, we'll trigger to load the form by its transparency using the timer code.
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Timer1.Enabled = True
- Me.Opacity = 0.1
- End Sub
To have the blended effect, we will put this code on the closing of Form. We will also call the function that we have declared above.
- Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs)
- AnimateWindow(Me.Handle.ToInt32, CInt(500), winHide Or winBlend)
- Catch ex As Exception
- End Try
- End Sub
Try it! :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware