c#用graphic里面能用小数画图吗
1个回答

以下是一个最简单的实例:

using System;

using System.Windows.Forms;

using System.Drawing;

public class Hello:Form {

public Hello() {

this.Paint += new PaintEventHandler(f1_paint);

}

private void f1_paint(object sender,PaintEventArgs e) {

Graphics g = e.Graphics;

g.DrawString("你好,C#!",new Font("Verdana",20),

new SolidBrush(Color.Tomato),40,40);

g.DrawRectangle(new Pen(Color.Pink,3),20,20,150,100);

}

public static void Main() {

Application.Run(new Hello());

}

}

在上面的实例中,我们用到了一个方法:DrawString(),它带有5个参数.同时,我们发现在运用DrawString()方法以前,我们先创建了一个Graphics类型的对象g=e.Graphics,这就说明了在运用任何图形类的方法以前我们必须先创建该类的一个实例化对象.在DrawString()方法后,我们用到了DrawRectangle()方法,其实我们还可以运用其他的方法来画椭圆或是多边形等等.