问题
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