Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Transparent forms (form opacity)

Covers how to change the opacity of a form (making a form transparent) and making only portions of the form transparent using TransparencyKey.

On Saturday, October 23rd 2004 at 05:42 AM
By Andrew Pociu (View Profile)
*****   (Rated 4.3 with 29 votes)
Contextual Ads
More C# Resources
Advertisement
Making a form transparent is farely simple, you only need to set one property.

Add to buttons to a form (btnIncrease and btnDecrease), one will increase the opacity of the form and one will decrease it, thus making it more transparent.

Also if you want to check out the current opacity you can add a TextBox (txtCurrOp) that will display it.



Now double click each of the buttons. For the Click event of the btnDecrease button use the following code:





// Decrease the opacity of the form by 0.01

this
.Opacity -= 0.01;

// Update the TextBox

txtCurrOp.Text = this.Opacity.ToString();



And for the btnIncrease Click event:





// Increase the opacity of the form by 0.01

this
.Opacity += 0.01;

// Update the TextBox

txtCurrOp.Text = this.Opacity.ToString();



Here's how the form looks with the opacity 0.75 (that means 75%):






Making portions of the form transparent (TransparencyKey)


But there's more than this, you can set the opacity for different portions of the form using the TransparencyKey property. By setting this property to a specified color any part of the form that has that color will be transparent.

Let's test this, double click the form to get to the Form1_Load event. Paste the following code there:





this.TransparencyKey = Color.Black;



This will make everything that's black on the form, transparent. The text on the buttons, label and TextBox is black, so are the Minimize, Maximize and Close buttons, thus they will be transparent. Here is the form on top of a photo (clouds):







But there's another way of using TransparencyKey. Add a Panel (Panel1) to the form with the BackColor property set to Red.







Inside the Load event of Form1 use the following:





this.TransparencyKey = Color.Red;



As you might expect, Panel1, being red will actually be transparent:








Also by using TransparencyKey you can create custom shaped forms, but this will be covered in a soon to come tutorial.
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by Sharad on Wednesday, December 20th 2006 at 12:28 AM

hi,

This is a good sample.
But this makes the rectangular portion as transparent....
what about a zig-zag bounded shap.

Regards

by MoZ on Monday, April 30th 2007 at 04:31 PM

The Zig-Zag question is simple -- the TransparentKey option makes anything that is that color \'transparent\' ... so if you place an image with a Zig-Zag line in Red and set the TransparentKey to red ... the red portions of the form become transparent

by Scott on Thursday, December 20th 2007 at 02:45 PM

This is what I'm trying to do:

I have a number of buttons that I want to show, but I do not want the form itself to show.

How can I make the FORM transparent but NOTHING else?

TIA,
Scott

by youCANTcme on Sunday, April 27th 2008 at 01:41 AM

@ SCOTT

just sent the forms transparency key to a color that you will never use in any text, button etc

and then set the form's back color to that color , that's it....

hope that helps

by youCANTcme on Sunday, April 27th 2008 at 01:48 AM

contd....

just to add something, what I earlier told you will make the font transparent, but not its border, to get that done, locate the property, FormBorderStyle and set it to NONE

then proceed :)

Hope that helps :)

by Eddie on Friday, March 20th 2009 at 08:44 AM

It works only on mdiParents forms

by haytham on Sunday, May 3rd 2009 at 07:05 PM

thank you

by haytham on Sunday, May 3rd 2009 at 07:05 PM

thank you

by haytham on Sunday, May 3rd 2009 at 07:05 PM

thank you

by haytham on Sunday, May 3rd 2009 at 07:05 PM

thank you

by Mans on Saturday, May 9th 2009 at 12:12 AM

thanks

by Mans on Saturday, May 9th 2009 at 12:12 AM

thanks

by Mans on Saturday, May 9th 2009 at 12:13 AM

thanks

by Mans on Saturday, May 9th 2009 at 12:13 AM

thanks

by Mans on Saturday, May 9th 2009 at 12:13 AM

thanks

by nubbie on Thursday, July 2nd 2009 at 03:56 AM

Thanks alot mate this really helped me out :)

by Sunny on Sunday, February 20th 2011 at 02:11 AM

can u plz mail me how 2 make a buttom transparent n not the whole forum

by web 2.0 linkwheels on Wednesday, December 14th 2011 at 09:40 AM

hi,
its good.
i want to know how can we get the current time without the date.
pls help me

by linkwheel service on Wednesday, December 14th 2011 at 09:42 AM

hi,
its good.
i want to know how can we get the current time without the date.
pls help me

by gd poker online on Saturday, January 21st 2012 at 06:02 PM

Wonderful site. Plenty of useful info here. I¡¦m sending it to a few friends ans also sharing in delicious. And certainly, thanks to your effort!

by Louis Vuitton Purses on Friday, August 17th 2012 at 10:30 PM

http://www.louisvuittonpursebags.org/ Louis Vuitton Purses
http://www.louisvuittonsonlineshop.org/ Louis Vuitton Outlet
http://www.greatlouisvuittonsbags.com/ louis vuitton outlet
http://www.cheap-suprashoe.net/ supra shoes
http://www.officiallouisvuittonzones.net/ louis vuitton outlet
http://www.hermesoutletsus.net/ hermes bags

by home intercom on Friday, October 5th 2012 at 05:33 AM

This is my Best of fortune that I discovered your publish which is according to my look for and topic.

by Silver Spring Locksmith on Thursday, October 25th 2012 at 01:08 AM

This webpage seems to me quite strange but exciting. Perhaps I will go on to study it

by tubal reversals on Friday, December 14th 2012 at 07:15 AM

Be ready and some day your opportunity will come.
http://www.tubal-reversal-surgery.net/services

by tubal reversal on Thursday, December 27th 2012 at 04:49 AM

Airport protection is necessary difficulty but it gives us satisfaction when journeying.
http://www.tubal-reversal-surgery.net/services

by tubal reversal surgery on Friday, December 28th 2012 at 04:37 AM

Always pay interest to your seniors not because they are always right but because they have more encounter of being wrong…
http://tubal-ligation-reversal-surgery.blogspot.com/2012/12/chances-of-conceiving-after-tubal.html

by Tubal reversal cost on Wednesday, January 16th 2013 at 05:44 AM

An act of goodness is a smart financial commitment.
http://www.tubal-reversal-surgery.net/tubal-ligation-reversal-financing-and-insurance-coverage.html

by web hosting on Wednesday, January 23rd 2013 at 11:26 PM

Thanks for upgrading us. I was just looking for the publish.
http://www.softhof.com/

by tienda bicicletas on Friday, February 15th 2013 at 12:00 AM

The simplest way to evade being disliked is to mind your own business and keep from giving good advice.
http://www.classicbikes.es/bicicletas/tienda-bicicletas-holandesas-de-segunda-mano


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C# Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Ads

From the creators of Geekpedia, a revolutionary new coupon website!

BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.

Coupons
Discover Geekpedia
Other Resources