First create a new Windows Forms project using C#. (This can be done in any .NET language, but we'll use C# for this example.) Add a button to the middle of the form. Add this code to the button:
private void button1_Click(object sender, System.EventArgs e) { System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath(); int width = this.ClientSize.Width; int height = this.ClientSize.Height; p.AddClosedCurve(new Point[]{new Point(width/2, height/10), new Point(width,0), new Point(width, height/3), new Point(width-width/3, height), new Point(width/7, height-height/8)}); this.Region = new Region(p); } |
Go ahead and run the code because you just made a nonrectangular form!
The code is fairly self-explanatory, but I'll explain a little anyway. A new GraphicsPath object is created first. This is the object used to create the shape of the border. There are a lot of different shapes that can be created with this method. Take a look through the documentation for this object and experiment with the different methods. An easy way to create a speific shape is to use the AddClosedCurve method. It takes an array of points and connects them with a curve. Finally, the Region property of the form is set to the a new Region which takes the GraphicsPath in the constructor.
Like I said, this is really very simple, but it's a great technique to set your program above everyone else's!
Info Source:
http://msdn.microsoft.com/code/default.asp?URL=/code/sample.asp?url=/MSDN-FILES/026/002/445/msdncompositedoc.xml
This code was accepted as a tutorial on Devhood!
Disclaimer:
By installing this software, you assume complete responsibility for any
damage that may occur to your system or your oldest child. I assume no
liability. Besides, if you tried to sue me you wouldn't get much.
May cause cancer in pregnant
lab rats on rainy days in Arkansas. Violators will be persecuted. Do not
pass Go, do not collect $200, go directly to jail. An apple a day keeps the
doctor away. Caffeine-free (although I am probably not). Look both ways
before crossing the road. Don't put that quarter in your mouth, you don't
know where it's been. Do not use in areas of high radiation. Do not use
while being chased by a rabid African tiger (a healthy one maybe, but not a
rabid one). I am not responsible for any lost or stolen brain cells. And
last, but not least, have fun!