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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Best Way To Convert From Screen Coords To My Own

Best Way To Convert From Screen Coords To My Own

Scheduled Pinned Locked Moved C#
graphicstutorialquestion
3 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.
  • . Offline
    . Offline
    ...---...
    wrote on last edited by
    #1

    Hi I have a simple WinForm I've created. With the following code: ////////////////////////////////////////////////////////////// public void DrawXYAxes(Graphics g) { g.DrawLine(axisPen, xIndent, yIndent + 200, xIndent + 400, yIndent + 200); g.DrawLine(axisPen, xIndent + 200, yIndent, xIndent + 200, yIndent + 400); } This will then draw X Y Axes on the form. Let's say the screen coordinates at the drawn origin are "200, 200". What's the most efficient way to get "200, 200" to display "0, 0"? So now when I move the cursor around the Form it will have both positive and negative axis coortinates? ps--I know how to display the screen coordinates as text on the screen, I just can't seem to get the system to be correct.... Thanks very much......

    C 1 Reply Last reply
    0
    • . ...---...

      Hi I have a simple WinForm I've created. With the following code: ////////////////////////////////////////////////////////////// public void DrawXYAxes(Graphics g) { g.DrawLine(axisPen, xIndent, yIndent + 200, xIndent + 400, yIndent + 200); g.DrawLine(axisPen, xIndent + 200, yIndent, xIndent + 200, yIndent + 400); } This will then draw X Y Axes on the form. Let's say the screen coordinates at the drawn origin are "200, 200". What's the most efficient way to get "200, 200" to display "0, 0"? So now when I move the cursor around the Form it will have both positive and negative axis coortinates? ps--I know how to display the screen coordinates as text on the screen, I just can't seem to get the system to be correct.... Thanks very much......

      C Offline
      C Offline
      Curtis Schlak
      wrote on last edited by
      #2

      I think that you may want to investigate Graphics.TranslateTransform(). If you translate the Graphics object by 200 left and 200 down, you'll have what you need, methinks. To see this in action, you can check out my recently published article Y(et)A(nother)TabControl in which I perform these kinds of transformations to translate the origin all over my control. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

      . 1 Reply Last reply
      0
      • C Curtis Schlak

        I think that you may want to investigate Graphics.TranslateTransform(). If you translate the Graphics object by 200 left and 200 down, you'll have what you need, methinks. To see this in action, you can check out my recently published article Y(et)A(nother)TabControl in which I perform these kinds of transformations to translate the origin all over my control. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

        . Offline
        . Offline
        ...---...
        wrote on last edited by
        #3

        Curtis, Thanks a lot for your help. I'm now at least able to draw a 'translated coordinate' Rect on my form inside the Paint Handler. Now I just need to figure out how to tie this in to OnMouseMove event.

        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