心形画框 [英] heart shaped picturebox

查看:64
本文介绍了心形画框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在C#中制作一个心形图片框? 我见过制作矩形和椭圆形的代码,但对制作心形区域一无所知.

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.

有什么主意吗?

推荐答案

这似乎可行:

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

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

这篇关于心形画框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆