Graphics --- 学习笔记

Graphics 类提供将对象绘制到显示设备的方法。 Graphics 与特定的设备上下文关联

1, 获取 Graphics 对象 :

http://www.csharpwin.com/csharpspace/10742r4084.shtml

http://msdn.microsoft.com/zh-cn/library/5y289054.aspx

   A, 通过处理控件的 Control.Paint 事件并访问 System.Windows.Forms.PaintEventArgs 类的 Graphics 属性, - e.Graphics

  B, 调用继承自 System.Windows.Forms.Control 的对象上的 Control.CreateGraphics 方法,- this.CreateGraphics()

  C, 使用 FromImage 方法从图像创建 Graphics 对象, - Graphics.FromImage(myImage)

 

2, 对象的删除:

http://rzshengyuan.blog.163.com/blog/static/13649348320109298421901/

【 如果是从OnPaint()事件中获得的Graphics对象,而不是创建了该对象,就不应调用Dispose(),但如果调用了CreateGraphics(),就必须调用Dispose()。

    提示: 只有在调用CreateGraphics()获得Graphics对象时,调用Dispose()才是重要的。 】

 

3, 用法示例:

  a.绘制图片:

private void DrawImagePointF(PaintEventArgs e)
{

    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");

    // Create point for upper-left corner of image.
    PointF ulCorner = new PointF(100.0F, 100.0F);

    // Draw image to screen.
    e.Graphics.DrawImage(newImage, ulCorner);
}

   b.绘制直线:

g.DrawLine(Pens.Black, new Point(10, 10), new Point(20, 20));

  c.绘制文本:

g.DrawString("Hello", new Font("Arial", 16), new SolidBrush(Color.Blue), new PointF(60, 60));

  d.绘制圆角矩形:

http://www.cnblogs.com/xujh/archive/2007/04/17/717433.html  -- 貌似不容易,待续

posted @ 2013-03-28 23:37  goto13  阅读(612)  评论(0编辑  收藏  举报