using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _126_使用GDI绘制简单图形
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnLine_Click(object sender, EventArgs e)
{
//创建GDI对象
Graphics g = this.CreateGraphics(); //new Graphics();没有构造函数
//创建画笔对象
Pen pen = new Pen(Brushes.Black);
//创建两个点
Point p1 = new Point(30, 50);
Point p2 = new Point(250, 250);
//开始画
g.DrawLine(pen, p1, p2);
}
int i = 0;
private void Form1_Paint(object sender, PaintEventArgs e)
{
i++;
lblRefresh.Text = i.ToString();
//创建GDI对象
Graphics g = this.CreateGraphics();
//创建画笔对象
Pen pen = new Pen(Brushes.Black);
//创建两个点
Point p1 = new Point(30, 50);
Point p2 = new Point(250, 250);
//开始画
g.DrawLine(pen, p1, p2);
}
private void btbRectangle_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
//DrawRectangle()需要两个对象,画笔和矩形
Pen pen = new Pen(Brushes.Red);
Size size = new Size(80, 80);
Rectangle rec = new Rectangle(new Point(50, 50), size); //Rectangle rec = new Rectangle(50,50,80,80 );
g.DrawRectangle(pen, rec);
}
private void btnSector_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
//DrawPie()方法需要的四个参数:
//1、画笔
Pen pen = new Pen(Brushes.Blue);
//2、矩形
Size size = new Size(180, 480);
Rectangle rec = new Rectangle(new Point(150, 150), size);
//3、4、两个角度 startAngle,sweepAngle
//画扇形
g.DrawPie(pen, rec, 270, 60);
}
private void btnText_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
//画文本
g.DrawString("韦晓龙牛逼", new Font("宋体", 20, FontStyle.Bold), Brushes.DarkViolet, new Point(300, 300));
}
}
}