我有一个字符串列表,我在坐标轴上绘制它们。我想要旋转这些字符串(注意,它们应该在旋转后仍然保持在同一水平轴上)。 我尝试使用以下代码:
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();
}
}
}
}
但是它不起作用,因为图形同时旋转这两个字符串,导致一个字符串比另一个字符串高。我该如何使用字符串中心作为旋转轴来单独旋转它们?