【发布时间】:2012-01-11 06:49:24
【问题描述】:
我正在使用 WPF 中的 DrawingContext 进行一些自定义绘图。我正在使用DrawingContext.DrawText 绘制字符串。现在,在我想垂直绘制文本的地方。 DrawingContext OR DrawText() 函数中是否有任何选项可以垂直绘制文本?
【问题讨论】:
我正在使用 WPF 中的 DrawingContext 进行一些自定义绘图。我正在使用DrawingContext.DrawText 绘制字符串。现在,在我想垂直绘制文本的地方。 DrawingContext OR DrawText() 函数中是否有任何选项可以垂直绘制文本?
【问题讨论】:
这是我的解决方案:需要围绕文本原点创建旋转变换,因此我们将 x 和 y 传递给 RotateTransform 构造函数
...
// ft - formatted text, (x, y) - point, where to draw
dc.PushTransform(new RotateTransform(-90, x, y));
dc.DrawText(ft, new Point(x, y));
dc.Pop();
...
【讨论】:
RotateTransform 定义旋转点以供一般使用是很有意义的。 x 和 y 是文本位置坐标。
您将不得不使用DrawingContext 类的PushTransform 和Pop 方法。
DrawingContext dc; // Initialize this correct value
RotateTransform RT = new RotateTransform();
RT.Angle = 90
dc.PushTransform(RT)
dc.DrawText(...);
dc.Pop();
【讨论】:
DrawingContext dc;
Point textLocation
var RT = new RotationTransform(-90.0);
// You should transform the location likewise...
location = new Point(-location.Y, location.X);
dc.PushTransform(RT);
dc.DrawText(formattedText, location);
抱歉,我不得不发布这个,因为我用头撞墙 15 分钟试图弄清楚这一点。我不想让其他人经历那件事。
【讨论】: