Setting the Coordinate Origin

The coordinate origin identifies the location from which coordinates are measured.

For example, if you create a Graphics object through your application’s main form, the Graphics object’s coordinate system is CoordinateSystem.TEXT and graphical coordinates are measured from the upper-left corner (0,0) of the form.

However, if you use a user-defined coordinate system, such as CoordinateSystem.ANISOTROPIC or CoordinateSystem.ISOTROPIC, you can specify the point from which coordinates are measured (both for the page and the device), using the Graphics object’s setCoordinateOrigin method. Suppose, for example, that you include in your application’s paint event the following code:

   private void Form1_paint(Object source, PaintEvent e)
   {
   // Set the coordinate system.

   e.graphics.setCoordinateSystem(CoordinateSystem.ANISOTROPIC);
   e.graphics.setCoordinateOrigin(new Point(20, 20), new Point(20,20));
   e.graphics.setCoordinateScale(new Point(1,1), new Point(1,1));
   e.graphics.drawLine(new Point(0,0), new Point(100,100));

   }

This code sets the coordinate system to CoordinateSystem.ANISOTROPIC and then sets the coordinate origin for both the page and device at 20,20. The call to drawLine that appears later in the code measures from the coordinate origin. Thus, the line will end at 100,100 from the coordinate origin (10,10).