change text orientation

P

Peter Demeyer

Does anyone know how to put text on a form (using DrawString or another
method) in a certain angle?
I can only find ways to orientate text vertically or horizontally, but I'd
like to display a string in an angle of 30 or 45 degrees...
 
W

Wiktor Zychla

I can only find ways to orientate text vertically or horizontally, but I'd
like to display a string in an angle of 30 or 45 degrees...

use RotateTransform method of a Graphics object.

Regards,
Wiktor
 
P

Peter Demeyer

Thanks a lot.
Now I have the following problem:

objGraphics.DrawString(tekst, objFont, objBrush,x1,y1);

puts my string on (x1,y1), but when I put

objGraphics.RotateTransform(30);
objGraphics.DrawString(tekst, objFont, objBrush,x1,y1);

the string is rotated, but the coördinates don't seem right anymore.

I've tried TranslateTransform with a few different arguments before
RotateTransform because I've seen this in examples, but I don't quite
understand what it does and I can't make it work right.
 
W

Wiktor Zychla

Now I have the following problem:

void DrawRotatedString(Graphics g, string text, Font font, Brush br,
Rectangle rect, StringFormat format, float angle)
{
Point center = new Point(rect.X+rect.Width/2,
rect.Y+rect.Height/2);
g.TranslateTransform(center.X, center.Y);
g.RotateTransform(angle);
rect.Offset(-center.X, -center.Y);
g.DrawString(text, font, br, rect, format);
g.ResetTransform(-angle);
}
 
P

Peter Demeyer

Thank you very much, Wiktor.

Wiktor Zychla said:
void DrawRotatedString(Graphics g, string text, Font font, Brush br,
Rectangle rect, StringFormat format, float angle)
{
Point center = new Point(rect.X+rect.Width/2,
rect.Y+rect.Height/2);
g.TranslateTransform(center.X, center.Y);
g.RotateTransform(angle);
rect.Offset(-center.X, -center.Y);
g.DrawString(text, font, br, rect, format);
g.ResetTransform(-angle);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top