Drawing Stretched Text
here is another question for gdi+ gurus:
I have a rectangle on a screen that I need to fit text into.
The text needs to be centered vertically, and fit horizontally from left to right so that characters will be stretched or shrunk depending on the size of the rectangle.
I tried using ScaleTransform, and it seems to work almost, but the text always starts too far from the beginning.
Here is what I'm doing now:
SizeF size = g.MeasureString(text, font, 4000, format);
float isWidth = size.Width;
float needWidth = Width;
float scale = needWidth / (isWidth > 0 ? isWidth : 1);
g.TranslateTransform(-X, -Y);
g.ScaleTransform(scale, 1);
g.TranslateTransform(X, Y);
g.DrawString(text, font, brush, LayoutRectangle, format);
i think i must do something different with translateTransform to make it work property.
Any ideas?
Thanks.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Mahesh ChandRank #1 · 393.3K reputationPosted Oct 10, 2003, 7:48 AM EDT
andrewRank #6,347 · 269 reputationPosted Oct 10, 2003, 8:51 AM EDT