Changing the origin of the drawing coordinate system in System.Drawing in C#


Changing the origin of the drawing coordinate system in System.Drawing in C#

The origin in System.Drawing.Graphics class is typically the upper-left-hand corner of the drawing surface (0,0) . If you want to change default coordinates(0,0) where rendering begins, use TranslateTransform method() of Graphics class.

It helps to change the coordinates from point (0, 0) to some point (m, n). For example, The following code will draw a line from point (0, 0) to point (120, 80) with origin (50, 40) .


Graphics g = e.Graphics;
g.TranslateTransform(50, 40);
Point A = new Point(0, 0);
Point B = new Point(120, 80);
g.DrawLine(Pens.Black, A, B);


Reference: http://rameshswaminathan.wordpress.com/2010/04/03/changing-the-origin-of-the-drawing-coordinate-system-in-system-drawing-in-c/


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: