Rotate Text - Problem
-
Hello, I have a problem, my application is drawing a simple text in the middle of a window, but the text is rotated by a user-defined angle. The problem is I cant make the text appear in the middle (the rotating makes the point change its location. My code looks like follows:
graphics.RotateTransform(-rotateAngle); graphics.DrawString(mystring, myfont, myBrush, drawpoint, new StringFormat());
I know I should put a graphics.TransformTranslate(_x,_y) - BUT I HAVE NO IDEA HOW TO FIGURE OUT THE POINTS for that purpose (before the locatin I was simply using X=width/2-measurestring/2, Y=height/2-measurestring/2). Any one know the maths for that ? -
Hello, I have a problem, my application is drawing a simple text in the middle of a window, but the text is rotated by a user-defined angle. The problem is I cant make the text appear in the middle (the rotating makes the point change its location. My code looks like follows:
graphics.RotateTransform(-rotateAngle); graphics.DrawString(mystring, myfont, myBrush, drawpoint, new StringFormat());
I know I should put a graphics.TransformTranslate(_x,_y) - BUT I HAVE NO IDEA HOW TO FIGURE OUT THE POINTS for that purpose (before the locatin I was simply using X=width/2-measurestring/2, Y=height/2-measurestring/2). Any one know the maths for that ?You need to do a TranslateTransform to change the point of rotation.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Hello, I have a problem, my application is drawing a simple text in the middle of a window, but the text is rotated by a user-defined angle. The problem is I cant make the text appear in the middle (the rotating makes the point change its location. My code looks like follows:
graphics.RotateTransform(-rotateAngle); graphics.DrawString(mystring, myfont, myBrush, drawpoint, new StringFormat());
I know I should put a graphics.TransformTranslate(_x,_y) - BUT I HAVE NO IDEA HOW TO FIGURE OUT THE POINTS for that purpose (before the locatin I was simply using X=width/2-measurestring/2, Y=height/2-measurestring/2). Any one know the maths for that ?Sorry - I see you know to translate - use Graphics.MeasureString to get the size of the string you want to draw.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Sorry - I see you know to translate - use Graphics.MeasureString to get the size of the string you want to draw.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
well, I actually use the MeasureString and TranslateTransform, but the problem is that Im drawing the string in that way - Rotate the graphics by an user-specified angle - Draw text - Rotate the graphics back to the previous position After this three steps I got an imaged and a text drawn on it on an angle I specified. The only problem is that I want to draw the text lets say in the middle and Im not sure how to get the coordinates of the point that after the rotating back the text will be at the middle of the image. Its actually a math matter, but Im not sure how to solve it.
-
well, I actually use the MeasureString and TranslateTransform, but the problem is that Im drawing the string in that way - Rotate the graphics by an user-specified angle - Draw text - Rotate the graphics back to the previous position After this three steps I got an imaged and a text drawn on it on an angle I specified. The only problem is that I want to draw the text lets say in the middle and Im not sure how to get the coordinates of the point that after the rotating back the text will be at the middle of the image. Its actually a math matter, but Im not sure how to solve it.
seq- wrote:
- Rotate the graphics by an user-specified angle - Draw text - Rotate the graphics back to the previous position
Where are you using the Translate ? You need to move the image so that 0,0 is the centre of the point of rotation you want to achieve.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog