如何在C#中围绕圆圈绘制文字

如何在C#中围绕圆圈绘制文字

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

问题描述

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

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

推荐答案


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#中围绕圆圈绘制文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 15:47