Monday, 19 August 2013

How can I set a form to have a 100% transparent background | How to animate the form. | Make a form's background 100% transparent

                                         Hi friends, in this article I will explain about make a form's background 100% transparent or how can I set a form to have a 100% transparent background or how to animate the form.
Basically we use the windows forms but we know how to change form’s background color, form’s font, forms’ height and form’s width etc.
I explain how to make form’s background as transparent in two ways.
1. Using Opacity property
2. Using TransparencyKey property:

1. Using Opacity property:
Take one new project (file---new---project) then one form will be created.
Double click on the form and write the following code.
In VB.NET:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '' Animate Windows Form using vb.net
        '' Set Transparency  of Form as 100 %
        Me.Opacity = 0
        '' Start the Timer 0.1% To change Form Transparency
        Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        '' increase Transparency  of Form to 1 %
        Me.Opacity += 0.01
    End Sub
End Class

In C#:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
Public Class Form1
{
                private void Form1_Load(System.Object sender, System.EventArgs e)
                {
                                //' Animate Windows Form using C#
                                //' Set Transparency  of Form as 100 %
                                this.Opacity = 0;
                                //' Start the Timer 0.1% To change Form Transparency
                                Timer1.Enabled = true;
                }
                private void Timer1_Tick(object sender, System.EventArgs e)
                {
                                //' increase Transparency  of Form to 1 %
                                this.Opacity += 0.01;
                }
    Public Form1()
                {
                                Load += Form1_Load;
                }
}
And run the form it will like below.


2. Using TransparencyKey property:
Take one new project (file---new---project) then one form will be created.
Double click on the form and write the following code.

In VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TransparencyKey = Color.Turquoise
        Me.BackColor = Color.Turquoise
    End Sub

In C#:
private void Form1_Load(System.Object sender, System.EventArgs e)
{
                this.TransparencyKey = Color.Turquoise;
                this.BackColor = Color.Turquoise;
}
And run the form it will like below.


 I think you like my blog Aspdotnet-Roja why are waiting following me on facebook fan page Aspdotnet-roja

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.