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);

I posted this code to answer someone’s question in MSDN forums.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: