Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Heart shaped Form in C# 2.0

5.00/5 (5 votes)
6 Apr 2011CPOL 16.4K  
My alternate uses the AddBezier method, and the size of the heart adjusts to the size of the form.private void Form1_Load(object sender, EventArgs e){ using(System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath()) { path.AddBezier(...
My alternate uses the AddBezier method, and the size of the heart adjusts to the size of the form.

C#
private void Form1_Load(object sender, EventArgs e)
{
    using(System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath())
    {
        path.AddBezier( this.Width >> 1,  
                        this.Height >> 2, 
                        this.Width * 1.25f, 0f, 
                        this.Width, 
                        this.Height * 0.75f, 
                        this.Width >> 1, 
                        this.Height);
        path.AddBezier( this.Width >> 1, 
                        this.Height >> 2, 
                        - this.Width * .25f, 0f,
                        0f, 
                        this.Height * 0.75f, 
                        this.Width >> 1, 
                        this.Height);
        this.Region = new Region(path);
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)