在winform窗体中,可以使用Graphics画出各种形状.
1.画直线
private void zbtnsteep_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
Pen mypen = new Pen(Color.Blue, 1);
for (int i = 1; i < 9; i++)
{
mypen = new Pen(Color.Blue, i);
graphics.DrawLine(mypen, 30, i * 60, 150, i * 60);
}
}
2.画矩形(长方形)
private void zbtnrectangle_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
Pen mypen = new Pen(Color.Blue, 1);
for (int i = 1; i < 8; i++)
{
mypen = new Pen(Color.Blue, i);
graphics.DrawRectangle(mypen, 200, i * 60, 120, 50);
}
}
3.画椭圆形
private void zbtnoval_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
Pen mypen = new Pen(Color.Blue, 1);
for (int i = 1; i < 8; i++)
{
mypen = new Pen(Color.Blue, i);
Rectangle myRectangle = new Rectangle(400, i * 60, 100, 50);
graphics.DrawEllipse(mypen, myRectangle);
}
}
4.画圆形
private void zbtnyuan_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
Pen mypen = new Pen(Color.Blue, 1);
for (int i = 1; i < 5; i++)
{
mypen = new Pen(Color.Blue, i);
Rectangle myRectangle = new Rectangle(600, (i) * 60+(i-1)*60, 100, 100);
graphics.DrawEllipse(mypen, myRectangle);
}
}
效果如下