Click here to Skip to main content
15,892,005 members
Articles / Programming Languages / C#
Article

Shaped Forms without a line of code

Rate me:
Please Sign up or sign in to vote.
4.25/5 (15 votes)
16 Mar 20042 min read 96.8K   1K   36   21
Have you ever wondered how to make a very customized form but you cannot make its graphics with code?

Sample Image - 009.jpg

Introduction

First of all, I am a newbie at C#. I started it from only two days ago so, sorry for the experts if they didn’t like my article or didn’t find anything useful here. But I think there is some one who may need it to improve his application's interface. The trick is same as the technique which is used at the movies to make the actors do the scene at a room the walls of which is painted with a illuminated color, then the graphic designers put another scene of a forest or a planet or any place else, this is how it works for us.

The first step is to make the required Form graphics by any graphics tool (I usually use the Photoshop). The form graphics must have the background color as illuminated green because this color can be easily grouped and deleted without deleting any edges of the shape you want. In other words, if we used non illuminated color, the dark edges of the shape will be deleted with the background color.

Any way the work will show how it is done, as I did in my sample. You can see what I was saying:

Sample screenshot

But the main problem is that Visual studio needs the same exact color as the background and if you mismatched this rule, the background color will stick to your form. If we take a closer view of our painted form, you can see a small difference at a point on the curved edges:

Sample screenshot

The Visual Studio considers it as a different color than the background, so it leaves it without deleting and it looks very awful at your form as:

Sample screenshot

So try to eliminate all different colors from your graphic before using it. Now another thing …. When you save your background color, try to make the background color take a little space from it because the VS considers it as a part of the form although it eliminates it.

Now save your work as .bmp file and open VS.NET. Make a project that contains a C# empty form and start modifying it as the following:

Sample screenshot

Add the button and the label you want and adjust the form properties as the following:

  • BackgroundImage: your background with extension .bmp
  • FormBorderStyle: None
  • TransparencyKey: Web, then choose Lime

Adjust the Button properties as the following:

  • BackColor: Web, then choose White Smoke
  • Text: OK

Adjust the Label properties as the following:

  • BackColor: Web, then choose Transparent
  • FlatStyle: Popup

Add this code to the button1_Click function:

C#
Application.Exit();

If you want your form moveable, you can use the code at Jibin's article (Interactive Shaped Forms). That is all.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Marketing
Egypt Egypt
http://hossamabbas.blogspot.com/

Comments and Discussions

 
GeneralThis way it'll work Pin
balazs_hideghety18-Aug-09 1:40
balazs_hideghety18-Aug-09 1:40 
1) picture must be a PNG with transparency BG color. you can make such an image in Paint.NET or adobe photoshop
2) you have to set controls BackColor and TransparencyColor to the same value

and that's it...

C#, ASPX, SQL, novice to NHibernate

Generalchange color depth and it will work Pin
osamahamed12326-Feb-06 1:30
osamahamed12326-Feb-06 1:30 
GeneralThe true way to make any shaped form Pin
Rezaul17-Oct-04 21:08
Rezaul17-Oct-04 21:08 
GeneralThanks and another trick Pin
raak3-Apr-04 10:44
raak3-Apr-04 10:44 
GeneralRe: Thanks and another trick Pin
Hossam Abbas28-Apr-04 12:58
Hossam Abbas28-Apr-04 12:58 
Generaldidn't worked Pin
Member 95548128-Mar-04 18:51
Member 95548128-Mar-04 18:51 
GeneralVery clean...Thanks Pin
))lance((26-Mar-04 0:08
))lance((26-Mar-04 0:08 
GeneralNot on NT4 Pin
Martin Robins23-Mar-04 5:47
professionalMartin Robins23-Mar-04 5:47 
GeneralRe: Not on NT4 Pin
Hossam Abbas23-Mar-04 12:44
Hossam Abbas23-Mar-04 12:44 
GeneralRe: Not on NT4 Pin
Ed.Poore12-Mar-06 4:56
Ed.Poore12-Mar-06 4:56 
Generaldoesnt work for me Pin
_taz_18-Mar-04 1:41
_taz_18-Mar-04 1:41 
GeneralRe: doesnt work for me Pin
Wilhelm Berg18-Mar-04 3:55
Wilhelm Berg18-Mar-04 3:55 
GeneralRe: doesnt work for me Pin
Hossam Abbas18-Mar-04 3:57
Hossam Abbas18-Mar-04 3:57 
GeneralRe: doesnt work for me Pin
Matthew Hazlett18-Mar-04 8:21
Matthew Hazlett18-Mar-04 8:21 
GeneralRe: doesnt work for me Pin
Hossam Abbas18-Mar-04 9:40
Hossam Abbas18-Mar-04 9:40 
GeneralRe: doesnt work for me Pin
Kareem Shaker20-Mar-04 22:01
Kareem Shaker20-Mar-04 22:01 
GeneralWorks for me! Pin
breinholt25-Mar-04 11:23
breinholt25-Mar-04 11:23 
GeneralRe: doesnt work for me Pin
Hossam Abbas28-Apr-04 12:56
Hossam Abbas28-Apr-04 12:56 
GeneralRe: doesnt work for me Pin
djones793627-Mar-04 17:46
djones793627-Mar-04 17:46 
GeneralRe: doesnt work for me Pin
gazza_28-Mar-04 10:36
gazza_28-Mar-04 10:36 
GeneralRe: doesnt work for me Pin
Hossam Abbas28-Mar-04 13:18
Hossam Abbas28-Mar-04 13:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.