private void button1_Click(object sender, EventArgs e)
{
//画一条直线
//this代表当前窗体
Graphics g = this.CreateGraphics();
Pen pen=new Pen(Color.Red);
Point p_1=new Point(150,150);
Point p_2=new Point(350,350);
g.DrawLine(pen, p_1, p_2);
}
private void button2_Click(object sender, EventArgs e)
{
//画一个矩形
//第一步:需要一个画图的对象
Graphics g = this.CreateGraphics();
Pen pen=new Pen(Color.Red);
Point point=new Point(180,180);
//需要矩形左上角的坐标,还需要这个矩形的大小
Rectangle rec=new Rectangle(point,new Size(200,200));
//一个画笔 一个矩形对象
g.DrawRectangle(pen, rec);
}
private void button3_Click(object sender, EventArgs e)
{
//填充矩形
Graphics g = this.CreateGraphics();
Rectangle rec=new Rectangle(new Point(180,180),new Size(200,200));
g.FillRectangle(Brushes.Yellow, rec);
}
private void button4_Click(object sender, EventArgs e)
{
//画一个文本
Graphics g = this.CreateGraphics();
g.DrawString("好好学习,天天向上", new Font("楷体", 20), Brushes.Red, new Point(268, 300));
}
|