• 大小: 49KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-04
  • 语言: C#
  • 标签: C#  GDI+  旋转文字  

资源简介

C#利用GDI+绘制旋转文字,矩形内可以根据布局方式排列文本

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace RotateText
{
    public partial class FormMain : Form
    {
        private Font _font = new Font(“Arial“ 12);
        private Brush _brush = new SolidBrush(Color.Black);
        private Pen _pen = new Pen(Color.Black 1f);
        private string _text = “Crow Soft“;

        public FormMain()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            GraphicsText graphicsText = new GraphicsText();
            graphicsText.Graphics = e.Graphics;

            // 绘制围绕点旋转的文本
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            graphicsText.DrawString(_text _font _brush new PointF(100 80) format 45f);
            graphicsText.DrawString(_text _font _brush new PointF(200 80) format -45f);
            graphicsText.DrawString(_text _font _brush new PointF(300 80) format 90f);
            graphicsText.DrawString(_text _font _brush new PointF(400 80) format -60f);

            // 绘制矩形内旋转的文本
            // First line
            RectangleF rc = RectangleF.FromLTRB(50 150 200 230);
            RectangleF rect = rc;
            format.Alignment = StringAlignment.Near;

            e.Graphics.DrawRectangle(_pen rect.Left rect.Top rect.Width rect.Height);
            graphicsText.DrawString(_text _font _brush rect format 30);

            rect.Location += new SizeF(180 0);
            format.LineAlignment = StringAlignment.Near;
            e.Graphics.DrawRectangle(_pen rect.Left rect.Top rect.Width rect.Height);
            graphicsText.DrawString(_text _font _brush rect format -30);

            rect.Location += new SizeF(180 0);
            format.LineAlignment = StringAlignment.Center;
            e.Graphics.DrawRectangle(_pen rect.Left rect.Top rect.Width rect.Height);
            graphicsText.DrawString(_text _font _brush rect format -90);

            rect.Location += new SizeF(180 0);
            format.LineAlignment = StringAlignment.Far;
            e.Graphics.DrawRectangle(_pen rect.Left rect.Top rect.Width rect.Height);
            graphicsText.DrawString(_text _font _brush rect format 70);

            // Second line
            rect = rc;
            rect.Location += new SizeF(0 100);
            format.Alignment = StringAlignment.Center;

            e.Graphics.DrawRectangle(_pen rect.Left rect.Top rect.Width rect.Height);
            graphicsText.DrawString(_text _font _brush rect format 40);

            rect.Location += new SizeF(180 0);
            format.LineAlignment = StringAlignment.Near;
            e.Gra

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-28 16:22  RotateText\
     目录           0  2013-11-28 16:31  RotateText\RotateText\
     文件        2666  2013-11-28 17:06  RotateText\RotateText\FormMain.Designer.cs
     文件        4937  2013-11-28 17:20  RotateText\RotateText\FormMain.cs
     文件        5817  2013-11-28 17:06  RotateText\RotateText\FormMain.resx
     文件        5290  2013-11-28 17:20  RotateText\RotateText\GraphicsText.cs
     文件         505  2013-11-28 16:22  RotateText\RotateText\Program.cs
     目录           0  2013-11-28 16:22  RotateText\RotateText\Properties\
     文件        1432  2013-11-28 16:22  RotateText\RotateText\Properties\AssemblyInfo.cs
     文件        2848  2013-11-28 16:22  RotateText\RotateText\Properties\Resources.Designer.cs
     文件        5612  2013-11-28 16:22  RotateText\RotateText\Properties\Resources.resx
     文件        1095  2013-11-28 16:22  RotateText\RotateText\Properties\Settings.Designer.cs
     文件         249  2013-11-28 16:22  RotateText\RotateText\Properties\Settings.settings
     文件        3737  2013-11-28 16:52  RotateText\RotateText\RotateText.csproj
     目录           0  2013-11-28 16:22  RotateText\RotateText\bin\
     目录           0  2013-11-28 16:56  RotateText\RotateText\bin\Debug\
     文件       12288  2013-11-28 17:20  RotateText\RotateText\bin\Debug\RotateText.exe
     文件       30208  2013-11-28 17:20  RotateText\RotateText\bin\Debug\RotateText.pdb
     文件       11600  2013-11-28 17:26  RotateText\RotateText\bin\Debug\RotateText.vshost.exe
     目录           0  2013-11-28 17:26  RotateText\RotateText\bin\Release\
     目录           0  2013-11-28 16:22  RotateText\RotateText\obj\
     目录           0  2013-11-28 16:22  RotateText\RotateText\obj\x86\
     目录           0  2013-11-28 17:20  RotateText\RotateText\obj\x86\Debug\
     文件        2164  2013-11-28 16:22  RotateText\RotateText\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6281  2013-11-28 17:20  RotateText\RotateText\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         230  2013-11-28 17:06  RotateText\RotateText\obj\x86\Debug\GenerateResource.read.1.tlog
     文件         570  2013-11-28 17:06  RotateText\RotateText\obj\x86\Debug\GenerateResource.write.1.tlog
     文件         180  2013-11-28 17:06  RotateText\RotateText\obj\x86\Debug\RotateText.FormMain.resources
     文件         180  2013-11-28 16:52  RotateText\RotateText\obj\x86\Debug\RotateText.Properties.Resources.resources
     文件         664  2013-11-28 17:26  RotateText\RotateText\obj\x86\Debug\RotateText.csproj.FileListAbsolute.txt
     文件       12288  2013-11-28 17:20  RotateText\RotateText\obj\x86\Debug\RotateText.exe
............此处省略4个文件信息

评论

共有 条评论