andrew

andrew

  • NA
  • 155
  • 0

Drawing Stretched Text

Oct 10 2003 11:25 AM
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.

Answers (2)