Sends for the fellow dear visitors:welcome to dongpad!


 Welcome to DongPad!

 msn


C#中如何得到Graphics对象

利用Graphics对象,我们可以绘制理想的UI。这里首先介绍C#中如何得到Graphics对象。

//如何得到Graphics对象

//1. Control.CreateGraphics();直接通过Control类的公开方法获取。可以是Form,基础控件,也可以是UC控件

new Form().CreateGraphics();

new Button().CreateGraphics();

new UserControl().CreateGraphics();

//2. new PaintEventArgs().Graphics

//PaintEventArgs参数的Graphics属性

this.Paint += new PaintEventHandler(Form1_Paint);

//3.Graphics类的静态方法,以下示例主要是通过句柄来获取该对象

Graphics.FromHdc(); //Control.Handle可以得到句柄

Graphics.FromHdcInternal();

Graphics.FromHwnd();

Graphics.FromHwndInternal();

//4.通过Graphics的静态方法,从图片获取该对象,主要可以用来设定内存位图对象,进行二级缓存绘图操作。

Graphics.FromImage();



评论: 0 | 引用: 0 | 查看次数: 1999 | 返回顶部
发表评论
昵 称:    
验证码:   
 
内 容:
选 项:  
 
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 500 字 | UBB代码 开启 | [img]标签 开启