Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing vertical text in WPF using DrawingContext.DrawText()

Tags:

c#

.net

wpf

drawing

I am doing some custom drawing using DrawingContext in WPF. I am using DrawingContext.DrawText for drawing strings. Now, at a place I want to draw the text vertically. Is there any option in the DrawingContext OR DrawText() function to draw text vertically?

like image 513
Ramesh Soni Avatar asked Jan 11 '12 06:01

Ramesh Soni


1 Answers

Here is my solution: It is need to create rotate transform around the text origin, so we pass x and y to RotateTransform constructor

       ...
        // 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();
        ...
like image 150
Netstep Avatar answered Sep 23 '22 20:09

Netstep