是否有可能在c#中制作一个心形的图片框? 我已经看过制作矩形和椭圆的代码,但我对制作心形区域没有任何想法。
有什么想法吗?
答案 0 :(得分:3)
这似乎有效:
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
答案 1 :(得分: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();
}
}}