Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to display an given string in a specific angle. I tried to to do this with the System.Drawing.Font class. Here is my code:

Font boldFont = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold, GraphicsUnit.Pixel, 1, true);
graphics.DrawString("test", boldFont, textBrush, 0, 0);

Can anyone help me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

String theString = "45 Degree Rotated Text";
SizeF sz = e.Graphics.VisibleClipBounds.Size;
//Offset the coordinate system so that point (0, 0) is at the
center of the desired area.
e.Graphics.TranslateTransform(sz.Width / 2, sz.Height / 2);
//Rotate the Graphics object.
e.Graphics.RotateTransform(45);
sz = e.Graphics.MeasureString(theString, this.Font);
//Offset the Drawstring method so that the center of the string matches the center.
e.Graphics.DrawString(theString, this.Font, Brushes.Black, -(sz.Width/2), -(sz.Height/2));
//Reset the graphics object Transformations.
e.Graphics.ResetTransform();

Taken from here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...