I have a list of lines that I draw on the axis. I want to rotate the strings (again, they must remain on the same horizontal axis when turning). I am trying to use the following code:
namespace DrawString
{
struct StringData
{
public string StringName;
public int X;
public int Y;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Font mFont = new Font("Arial", 10.0f, FontStyle.Bold);
List<StringData> data = new List<StringData> { new StringData() { StringName = "Label1", X = 10, Y = 30 },
new StringData() { StringName = "Label2", X = 130, Y = 30 }};
private void Form1_Paint(object sender, PaintEventArgs e)
{
foreach (var str in data)
{
e.Graphics.RotateTransform(30);
e.Graphics.DrawString(str.StringName, mFont, new SolidBrush(Color.Black), new Point(str.X, str.Y));
e.Graphics.ResetTransform();
}
}
}
}
But it does not work, as the graphic rotates for both lines at the same time, causing one line above the other. How can I rotate them individually using the center of the line as my axis of rotation?
Ioga3 source
share