Csharp/C Sharp/2D Graphics/Graphics Unit — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:31, 26 мая 2010

Graphics Unit: Display

  using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ruponentModel;
  using System.Windows.Forms;
  using System.Data;
  public class Form1 : System.Windows.Forms.Form
  {
    public Form1()
    {
      InitializeComponent();
      SetStyle(ControlStyles.ResizeRedraw, true);
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(400, 400);
      this.Text = "";
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
    static void Main() 
    {
      Application.Run(new Form1());
    }
    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      // Set quality of rendering.
      g.SmoothingMode = SmoothingMode.AntiAlias;
  
      // Configure graphics unit.
      g.PageUnit = GraphicsUnit.Display;
        Point renderingOrgPt = new Point(0,0);
      renderingOrgPt.X = 100;
      renderingOrgPt.Y = 100;
      // Configure origin.
      g.TranslateTransform(renderingOrgPt.X,
        renderingOrgPt.Y);
      g.DrawRectangle(new Pen(Color.Red, 1), 0, 0, 100, 100);
      
      g.Dispose();
    }
  }


Graphics Unit: Document

  using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ruponentModel;
  using System.Windows.Forms;
  using System.Data;
  public class Form1 : System.Windows.Forms.Form
  {
    public Form1()
    {
      InitializeComponent();
      SetStyle(ControlStyles.ResizeRedraw, true);
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(400, 400);
      this.Text = "";
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
    static void Main() 
    {
      Application.Run(new Form1());
    }
    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      // Set quality of rendering.
      g.SmoothingMode = SmoothingMode.AntiAlias;
  
      // Configure graphics unit.
      g.PageUnit = GraphicsUnit.Document;
        Point renderingOrgPt = new Point(0,0);
      renderingOrgPt.X = 100;
      renderingOrgPt.Y = 100;
      // Configure origin.
      g.TranslateTransform(renderingOrgPt.X,
        renderingOrgPt.Y);
      g.DrawRectangle(new Pen(Color.Red, 1), 0, 0, 100, 100);
      
      g.Dispose();
    }
  }


Graphics Unit: Millimeter

  using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ruponentModel;
  using System.Windows.Forms;
  using System.Data;
  public class Form1 : System.Windows.Forms.Form
  {
    public Form1()
    {
      InitializeComponent();
      SetStyle(ControlStyles.ResizeRedraw, true);
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(400, 400);
      this.Text = "";
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
    static void Main() 
    {
      Application.Run(new Form1());
    }
    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      // Set quality of rendering.
      g.SmoothingMode = SmoothingMode.AntiAlias;
  
      // Configure graphics unit.
      g.PageUnit = GraphicsUnit.Millimeter;
        Point renderingOrgPt = new Point(0,0);
      renderingOrgPt.X = 100;
      renderingOrgPt.Y = 100;
      // Configure origin.
      g.TranslateTransform(renderingOrgPt.X,
        renderingOrgPt.Y);
      g.DrawRectangle(new Pen(Color.Red, 1), 0, 0, 100, 100);
      
      g.Dispose();
    }
  }


Graphics Unit: Point

  using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ruponentModel;
  using System.Windows.Forms;
  using System.Data;
  public class Form1 : System.Windows.Forms.Form
  {
    public Form1()
    {
      InitializeComponent();
      SetStyle(ControlStyles.ResizeRedraw, true);
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(400, 400);
      this.Text = "";
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
    static void Main() 
    {
      Application.Run(new Form1());
    }
    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      // Set quality of rendering.
      g.SmoothingMode = SmoothingMode.AntiAlias;
  
      // Configure graphics unit.
      g.PageUnit = GraphicsUnit.Point;
        Point renderingOrgPt = new Point(0,0);
      renderingOrgPt.X = 100;
      renderingOrgPt.Y = 100;
      // Configure origin.
      g.TranslateTransform(renderingOrgPt.X,
        renderingOrgPt.Y);
      g.DrawRectangle(new Pen(Color.Red, 1), 0, 0, 100, 100);
      
      g.Dispose();
    }
  }