GraphicsUnit.Point : GraphicsUnit « System.Drawing « C# / C Sharp by API






GraphicsUnit.Point

 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class GraphicUnitPoint : System.Windows.Forms.Form
{
  private System.ComponentModel.Container components = null;

  public GraphicUnitPoint()
  {
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(408, 273);
    this.Name = "GraphicUnitPoint";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "GDI+ Coordinate";
    this.Resize += new System.EventHandler(this.OnResize);
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);

  }

  [STAThread]
  static void Main() 
  {
    Application.Run(new GraphicUnitPoint());
  }
  protected void OnPaint (object sender, System.Windows.Forms.PaintEventArgs e)
  {
      GraphicsUnit gUnit = GraphicsUnit.Pixel;

      Point renderingOrgPt = new Point(0,0);

    Graphics g = e.Graphics;
    g.SmoothingMode = SmoothingMode.AntiAlias;

    
    gUnit = GraphicsUnit.Point;

    
    g.PageUnit = gUnit;
    g.TranslateTransform(renderingOrgPt.X,renderingOrgPt.Y);
    g.DrawRectangle(new Pen(Color.Red, 1), 0, 0, 100, 100);
  
    this.Text = string.Format("PageUnit: {0}, Origin: {1}",  gUnit, renderingOrgPt.ToString());
  }

  protected void OnResize (object sender, System.EventArgs e)
  {
    Invalidate();
  }
}

   
  








Related examples in the same category

1.GraphicsUnit.Display
2.GraphicsUnit.Document
3.GraphicsUnit.Inch
4.GraphicsUnit.Millimeter
5.GraphicsUnit.Pixel