Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Rotate Text - Problem

Rotate Text - Problem

Scheduled Pinned Locked Moved C#
graphicshelptutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    seq
    wrote on last edited by
    #1

    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 ?

    C 2 Replies Last reply
    0
    • S seq

      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 ?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • S seq

        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 ?

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • C Christian Graus

          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

          S Offline
          S Offline
          seq
          wrote on last edited by
          #4

          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.

          C 1 Reply Last reply
          0
          • S seq

            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.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups