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();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值