心形的图片盒
本文关键字: | 更新日期: 2023-09-27 17:51:13
是否可以在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);
}
}
}
Bezier的东西从这里:http://www.codeproject.com/Tips/177794/Heart-shaped-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();
}
}}