C#中如何得到Graphics对象

    技术2022-05-11  15

    利用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)