Hello,
In my GDI+ application I create graphics (rectangles, circles and text) on the panel pnl. For graphical object I need to move the origin from top-left to bottom-left corner.
The solution is to apply consequently 2 transforms ScaleTransform and TranslateTransform to the Graphics object.
Graphics dc = pnl.CreateGraphics();
dc.ScaleTransform(1.0f, -1.0f);
dc.TranslateTransform(0.0f, -pnl.Height);
But in this way the text is mirrored !!!
Is there a simple way to resolve a problem?
Thanks in advance.
Pavel.
Loading


VulpesRank #55 · 29.2K reputationPosted Sep 13, 2012, 8:10 AM EDT
I don't know of any solution to this except to stick with the origin at the top left corner and then draw the text at the appropriate location. So:
Graphics dc = pnl.CreateGraphics();
// draw string from top left
dc.DrawString("Pavel", drawFont, drawBrush, 0, 0);
// draw string from bottom left
dc.DrawString("Pavel", drawFont, drawBrush, 0, pnl.Height - drawFont.Height);
Pavel106 reputationPosted Sep 13, 2012, 10:07 AM EDT
If I understood in right way, you propose to reject at all the using of transforms.
If it is only solution, Ok ... I will proceed in this way. But I have plenty "geometric" graphics (rectangles, circles, etc.), that are correctly displayed with transforms, and only few "text" graphics.
So, in order to consider bottom-left as origin, I should replace all "y" to "pnl.Height-y" ?
Thanks.
Pavel.
VulpesRank #55 · 29.2K reputationPosted Sep 13, 2012, 10:23 AM EDT
For text, you'd need to do what you said and also subtract the height of the font being used.
Pavel106 reputationPosted Sep 13, 2012, 10:35 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 13, 2012, 10:41 AM EDT
However, if you only have a few strings to draw, I'd suggest you draw them first before you change the origin to draw the shapes.
Pavel106 reputationPosted Sep 13, 2012, 10:43 PM EDT
Probably I will decide to reject transforms and replace every y to pnl.Height - y.
It's a pity, that such behaviour wasn't remarked by Microsoft engineers.
Thank you once more for your assistance.
Regards.
Pavel.
Nuno Pinto17 reputationPosted Nov 6, 2017, 4:07 AM EST