环绕的字WrapText


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 WrapText : FontMenuForm
    {
        float fRadius = 100;
        public new static void Main()
        {
            Application.Run(new WrapText());
        }

        public WrapText()
        {
            Text = "Wrap Text";
            strText = "猪爷爷";
            font = new Font("Times New Roman", 48);
        }

        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 PointF(0, 0), new StringFormat());

            RectangleF rectf = path.GetBounds();
            path.Transform(new Matrix(1, 0, 0, -1, -rectf.Left, GetAscent(grph, font)));

            float fScale = 2 * (float)Math.PI / rectf.Width;
            path.Transform(new Matrix(fScale, 0, 0, fScale, 0, 0));
            //修改路径
            PointF[] aptf = path.PathPoints;
            for (int i = 0; i < aptf.Length; i++)
            {
                aptf[i] = new PointF(fRadius * (1 + aptf[i].Y) * (float)Math.Cos(aptf[i].X),
                    fRadius * (1 + aptf[i].Y) * (float)Math.Sin(aptf[i].X));
            }
            path = new GraphicsPath(aptf, path.PathTypes);
            //填充路径
            grph.TranslateTransform(cx / 2, cy / 2);
            grph.FillPath(new SolidBrush(Color.Red), path);
        }
    }
}

效果图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值