彩色字ClipText

博客介绍了如何利用FontMenuForm基类实现字体裁剪应用,详细内容可参考提供的链接,主要内容围绕彩色字体的创建和使用展开。
摘要由CSDN通过智能技术生成

FontMenuForm 基类见:http://blog.csdn.net/u013384702/article/details/17884617

字体裁剪的应用

Code:

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace CsStudy
{
    class ClipText : FontMenuForm
    {
        public new static void Main()
        {
            Application.Run(new ClipText());
        }

        public ClipText()
        {
            Text = "Clip Text";
            Width *= 2;
            strText = "猪爷爷";
            font = new Font("Times New Roman", 108, FontStyle.Bold);//加粗
        }

        protected override void DoPage(Graphics grph, Color clr, int cx, int cy)
        {
            GraphicsPath path = new GraphicsPath();
            float fFontSize = PointToPageUnits(grph, font);

            //添加文本到图形路径
            path.AddString(strText, font.FontFamily, (int)font.Style, fFontSize, new Point(0, 0), new StringFormat());
            //设置裁剪区域
            grph.SetClip(path);

            RectangleF rectfBounds = path.GetBounds();
            grph.TranslateClip((cx - rectfBounds.Width) / 2 - rectfBounds.Left, 
                (cy - rectfBounds.Height) / 2 - rectfBounds.Top);
            //绘制裁剪线条
            Random rand = new Random();

            for (int i = 0; i < cy; i++)
            {
                Pen pen = new Pen(Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255)));
                grph.DrawBezier(pen, new Point(0, i), new Point(cx / 3, i + cy / 3),
                    new Point(2 * cx / 3, i - cy / 3), new Point(cx, i));
            }
        }
    }
}

效果图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值