I’m using scaling and transforming my graphics object when painting a custom control, in order to apply zooming and scrolling. I use the following:
Matrix mx = new Matrix();
mx.Scale(mZoomFactor, mZoomFactor);
mx.Translate(-clip.X + mGraphicsOffsetx, -clip.Y + mGraphicsOffsety);
e.Graphics.Clip = new Region(this.Bounds);
e.Graphics.Transform = mx;
Then when I paint my strings using:
Graphics g = ...
g.DrawString(...)
The scalling and transforming is correctly applied to the strings, they are zoomed out and in and so on.
However if I use the following to paint my strings:
TextRenderer.DrawText(...)
The text is not correctly scaled and transformed.
Do you know how to apply this concepts to the TextRenderer?
The comments above are accurate–
TextRenderer.DrawText, being GDI, has limited support for coordinate transformation given its resolution dependence. As you’ve noticed, coordinate translation is supported but scaling is not (and neither is coordinate rotation).The solution we’ve used (and the only resource I’ve been able to find on the internet) is to manually scale the
FontandRectangleobjects to reflect the scaling applied byMatrix.Scale(float, float)in conjunction withGraphics.Transform:Here is the entire test form: