heart shaped picturebox

杀马特。学长 韩版系。学妹 提交于 2019-12-12 03:49:09

问题


Is it possible to make a heart shaped picturebox in c#? I have seen codes in making rectangle and ellipse but I don't have any idea on making a heart shaped region.

Any idea?


回答1:


This seems to work:

public class HeartPictureBox : PictureBox {
    protected override void OnPaint(PaintEventArgs pe) {
        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);
        }
    }
}

Bezier stuff from here: http://www.codeproject.com/Tips/177794/Heart-shaped-Form-in-C-2-0




回答2:


using System;
namespace ConsoleApplication6
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("    o o.o o   ");
            Console.WriteLine("  o         o      ");
            Console.WriteLine("  o         o       ");
            Console.WriteLine("   o       o         ");
            Console.WriteLine("     o    o       ");
            Console.WriteLine("       o         ");
            Console.ReadKey();
        }
  }}


来源:https://stackoverflow.com/questions/14248003/heart-shaped-picturebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!