使用DrawingContext.DrawText()在WPF中绘制垂直文本

Ram*_*oni 8 .net c# wpf drawing

我在WPF中使用DrawingContext进行一些自定义绘图.我DrawingContext.DrawText用来绘制字符串.现在,在一个我想垂直绘制文本的地方.DrawingContext或DrawText()函数中是否有任何选项可以垂直绘制文本?

Mah*_*eep 13

你将不得不使用PushTransform和类的Pop方法DrawingContext.

DrawingContext dc; // Initialize this correct value
RotateTransform RT = new RotateTransform();
RT.Angle = 90
dc.PushTransform(RT)
dc.DrawText(...);
dc.Pop();
Run Code Online (Sandbox Code Playgroud)


Jor*_*dan 5

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);
Run Code Online (Sandbox Code Playgroud)

抱歉,我不得不发布此消息,因为我将头撞在墙上十五分钟,试图找出答案。我不想让其他人经历那件事。