是否可以在 C# 中制作心形图片框?我看过制作矩形和椭圆的代码,但我对制作心形区域一无所知。
任何的想法?
这似乎有效:
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);
}
}
}
贝塞尔曲线来自这里: http: //www.codeproject.com/Tips/177794/Heart-shape-Form-in-C-2-0
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();
}
}}