Gia dụng
Trả lời 17 năm trước
Bạn thử xem ví dụ này xem, gõ trên web nên có thể sai cú pháp.
using .....
public class TestDraw:Form
{
//Hàm thiết lập chắc em đã biết nó có tác dụng gì
//Thường em đặt trong này để chứ không đặt trong Form_Load
public TestDraw()
{
this.Paint += new PaintEventHandler(Draw_Graphics);
}
//Tạo hàm Draw_Graphics
public void Draw_Graphics(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen penline = new Pen(Color.Red,5);
Pen penellipse = new Pen(Color.Blue,5);
Pen penpie = new Pen(Color.Tomato,3);
Pen penpolygon = new Pen(Color.Maroon,4);
//Vẽ đường thẳng
penline.DashStyle = DashStyle.Dash;
g.DrawLine(penline,50,50,100,200);
//Vẽ một hình ellip
penellipse.DashStyle = DashStyle.DashDotDot;
g.DrawEllipse(penellipse,15,15,50,50);
//Vẽ hình tròn
penpie.DashStyle = DashStyle.Dot;
g.DrawPie(penpie,90,80,140,40,120,100);
//Vẽ đa giác
g.DrawPolygon(penpolygon,new Point[]{
new Point(30,140),
new Point(270,250),
new Point(110,240),
new Point(200,170),
new Point(70,350),
new Point(50,200)});
}
}
Chúc Bạn thành công!