如何在C#中围绕圆圈绘制文字 [英] how to draw text around the circle in C#

查看:209
本文介绍了如何在C#中围绕圆圈绘制文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我找到这个....

Can some one help me to find this....

推荐答案

看看这里:使用VB.NET的路径文本 [ ^ ]


如果没有更多信息,很难回答我需要知道你对间距有什么限制。



如果你只想在圆圈周围均匀分布文字,那么这样的话就可能了为你做这个伎俩;



It's difficult to answer without more information, primarily I'd need to know what constraints you have on the spacing.

If you're just trying to evenly space the text all around the circle then something like this might do the trick for you;

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

namespace CircleText {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            SizeChanged += (s, e) => Invalidate();
        }

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

            var center = new Point(Width/2, Height/2);
            var radius = Math.Min(Width, Height) / 3;
            var text = "ABCDEFGHIJLKMNOPQRSTUVWXYZ";

            var font = new Font(FontFamily.GenericSansSerif, 24, FontStyle.Bold);
            for (var i = 0; i < text.Length; ++i)
            {
                var c = new String(text[i], 1);

                var size = e.Graphics.MeasureString(c, font);
                var charRadius = radius + size.Height;

                var angle = (((float)i / text.Length) - 0.25) * 2 * Math.PI;

                var x = (int)(center.X + Math.Cos(angle) * charRadius);
                var y = (int)(center.Y + Math.Sin(angle) * charRadius);


                e.Graphics.TranslateTransform(x, y);

                e.Graphics.RotateTransform((float)(90 + 360 * angle / (2 * Math.PI)));
                e.Graphics.DrawString(c, font, Brushes.Red, 0, 0);

                e.Graphics.ResetTransform();


                e.Graphics.DrawArc(new Pen(Brushes.DarkGreen, 2.0f), center.X - radius, center.Y - radius, radius*2, radius*2, 0, 360);
            }
   }
    }
}





希望这有帮助



Hope this helps


这篇关于如何在C#中围绕圆圈绘制文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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