private void Form1_Paint(object sender, PaintEventArgs e)
        {

            String theString = "A";
            SizeF sz = e.Graphics.VisibleClipBounds.Size;

            e.Graphics.TranslateTransform(sz.Width / 2 ,sz.Height / 2);

            e.Graphics.RotateTransform(angle);
            angle++;
            sz = e.Graphics.MeasureString(theString, this.Font);


            e.Graphics.DrawString(theString, this.Font, Brushes.Black,-(sz.Width/2),-(sz.Height/2));

        }

I dont understand the last part with the DrawString(). The 2 last arguments of the method specify the location where the string HAS TO BE drawn and when i debug i get this 2 values: {Width = 11.2202139 Height = 13.8251934}. But the string is drawn in the center because of the translatetransform() method listed above. So basically i do not understand the last two arguments whatsoever. Please clear that for me.
BTW. Everything works fine the string rotates as it should be but i simply do not understand i do not want to go further without understanding it.

Recommended Answers

All 4 Replies

As shown here; the TranslateTransform sets the new zero point of the drawing.

When you call this you are setting the new zero point to the center of the screen. (1/2 sz.Width, 1/2 sz.Height).

Therefore, when you tell it to draw the string at 5,6 it will draw using the new zero.

commented: Nice. +14

Thank Sir i should have read about Translatetransform i wasn t aware that this method set s it up from zero. I more thing . How come

-(sz.Width/2),-(sz.Height/2)

results in a positive value not negative as it shoudl be? Otherwise you ve solved my problem

If you think of your screen as a quadrant, it would have the y axis reversed.
(X,Y)
0,0 | 1,0 | 2,0 | 3,0 |
0,1 | 1,1 | 2,1 | 3,1 |
0,2 | 1,2 | 2,2 | 3,2 |

This being said, you see a positive value in debug because you are viewing the values before the interpreter sees the '-'

hah, youre unbeliveable , cheers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.