String_format.LineAlignment = StringAlignment.Near įor (int i = 0 i < bottom_text.Length i++) Reset the StringFormat to draw above the drawing origin. Width_query = from RectangleF rect in rects Rects = MeasureCharacters(gr, font, bottom_text) Gr.DrawString(top_text.ToString(), font, brush, Gr.TranslateTransform((float)x, (float)y, Gr.RotateTransform((float)(radians_to_degrees * Theta += rects.Width / 2 * width_to_angle ĭouble x = cx + radius * Math.Cos(theta) ĭouble y = cy + radius * Math.Sin(theta) Var width_query = from RectangleF rect in rectsįor (int i = 0 i < top_text.Length i++) Use LINQ to add up the character widths. Used to scale from radians to degrees.ĭouble radians_to_degrees = 180.0 / Math.PI String_format.LineAlignment = StringAlignment.Far String_format.Alignment = StringAlignment.Center Using (StringFormat string_format = new StringFormat()) Private void DrawTextOnCircle(Graphics gr, Font font,īrush brush, float radius, float cx, float cy, Draw text centered on the top and bottom of the circle. The DrawTextOnCircle method shown in the following code uses that information to draw text along the top and bottom of a circle. In particular, it shows how to determine the width and height of each of the characters in a string. The previous post explains how to determine where the characters in a string will be drawn. This example uses some of the techniques described in the post Measure character positions when drawing long strings in C# to draw text on a circle.
0 Comments
Leave a Reply. |