using System.Drawing; namespace Microsoft.Drawing { /// /// 平移变换 /// public sealed class TranslateGraphics : DisposableMini { private int m_X; //水平平移 private int m_Y; //垂直平移 private Graphics m_Graphics; //要修改剪切区的绘图对象 /// /// 构造函数 /// /// 绘图对象 /// 水平偏移像素 /// 垂直偏移像素 public TranslateGraphics(Graphics graphics, int x, int y) { this.m_Graphics = graphics; this.m_X = x; this.m_Y = y; this.m_Graphics.TranslateTransform(this.m_X, this.m_Y); } /// /// 构造函数 /// /// 绘图对象 /// 偏移量 public TranslateGraphics(Graphics graphics, Point p) { this.m_Graphics = graphics; this.m_X = p.X; this.m_Y = p.Y; this.m_Graphics.TranslateTransform(this.m_X, this.m_Y); } /// /// 构造函数 /// /// 绘图对象 /// 偏移量 public TranslateGraphics(Graphics graphics, Size s) { this.m_Graphics = graphics; this.m_X = s.Width; this.m_Y = s.Height; this.m_Graphics.TranslateTransform(this.m_X, this.m_Y); } /// /// 释放资源 /// /// 释放托管资源为true,否则为false protected override void Dispose(bool disposing) { if (this.m_Graphics != null) { this.m_Graphics.TranslateTransform(-this.m_X, -this.m_Y); this.m_Graphics = null; } this.m_X = 0; this.m_Y = 0; } } }