Csharp/CSharp Tutorial/2D/Coordinate

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

Change Renderer Origin

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class RendereringOrigin : System.Windows.Forms.Form
{
  private System.ruponentModel.Container components = null;
  public RendereringOrigin()
  {
    InitializeComponent();
  }
  protected override void Dispose( bool disposing )
  {
    if( disposing )
    {
      if (components != null) 
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }
  private void InitializeComponent()
  {
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(408, 273);
    this.Name = "RendereringOrigin";
    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 RendereringOrigin());
  }
  protected void OnPaint (object sender, System.Windows.Forms.PaintEventArgs e)
  {
      GraphicsUnit gUnit = GraphicsUnit.Pixel;
      Point renderingOrgPt = new Point(0,0);
    renderingOrgPt.X = 100;
    renderingOrgPt.Y = 100;
    Graphics g = e.Graphics;
    g.SmoothingMode = SmoothingMode.AntiAlias;
    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();
  }
}

GDI+ Coordinate

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class GDICooridinate : System.Windows.Forms.Form
{
  private System.ruponentModel.Container components = null;
  public GDICooridinate()
  {
    InitializeComponent();
  }
  protected override void Dispose( bool disposing )
  {
    if( disposing )
    {
      if (components != null) 
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }
  private void InitializeComponent()
  {
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(408, 273);
    this.Name = "GDICooridinate";
    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 GDICooridinate());
  }
  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.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();
  }
}