画圆线以与圆周围的文字配合 [英] Draw circle line to go with text around a circle

查看:66
本文介绍了画圆线以与圆周围的文字配合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一段代码,可以在一个圆圈(即时钟或指南针)周围绘制文本,现在我需要绘制与其相伴的圆圈.

这是代码段...

I found a piece of code that draws text around a circle (i.e. clock or a compass), now I need to draw the circle that goes with it.

Here is the code snippet...

  private void SetScale(Graphics g)
  {
    g.TranslateTransform(Width/2, Height/2);

    float inches = Math.Min(Width / g.DpiX, Height / g.DpiX);

    g.ScaleTransform(inches * g.DpiX / 2000, inches * g.DpiY / 2000);
  }

  private void DrawFace(Graphics g)
  {
    Brush brush = new SolidBrush(ForeColor);
    Font font = new Font("Arial", 40);
  
    float x, y;

    const int numHours = 12;
    const int deg = 360 / numHours;
    const int FaceRadius = 450;
    
    for (int i = 1; i <= numHours; i++)
    {
      x = GetCos(i*deg + 90) * FaceRadius;
      y = GetSin(i*deg + 90) * FaceRadius;

      StringFormat format = new StringFormat();
      format.Alignment = StringAlignment.Center;
      format.LineAlignment = StringAlignment.Center;

      g.DrawString( i.ToString(), font, brush, -x, -y,format);
    
    }
    brush.Dispose();
    font.Dispose();
  }  

  private static float GetSin(float degAngle)
  {
    return (float) Math.Sin(Math.PI * degAngle / 180f);
  }

  private static float GetCos(float degAngle)
  {
    return (float) Math.Cos(Math.PI * degAngle / 180f);
  }

}


问题是...如何使用画线或画圆来匹配圆周围的文字?感谢


Question is...how do I use drawline or draw the circle to match the text around the circle? thanks

推荐答案

,您应该使用 Graphics.DrawEllipse [ ^ ],您必须计算谁的边是圆的切线的矩形.
you should use Graphics.DrawEllipse[^], you have to calculate the rectangle whos sides are tangents of the circle.


这篇关于画圆线以与圆周围的文字配合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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