环绕的字WrapText

来源:互联网 发布:国产rpg单机游戏 知乎 编辑:程序博客网 时间:2024/05/17 01:23


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);        }    }}

效果图:


0 0