Hi,
I have a list of strings which I paint on an axis. I want to rotate the strings (again, they should stay on the same horizontal axis when rotated). 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 doesn't work since the Graphics is rotating for both of the strings at once, causing one string to be higher than the other. How can I rotate them individually using the center of the string as its rotation axis?