求高手指点,画几个同心圆,运行不出来,怎么回事呢?
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace demo10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = new Rectangle();
//圆的直径等于绘图区域的最短边
float diameter = Math.Min(rect.Width, rect.Height);
//半径
float radius = diameter / 2;
//圆心
PointF center = new PointF(rect.X + rect.Width / 2, rect.Height / 2);
//画几个圆,先试试5个
int count = 5;
float diameterStep = diameter / count;
float radiusStep = radius / count;
//生成圆的范围
RectangleF cirleRect = new RectangleF();
cirleRect.X = center.X - radius;
cirleRect.Y = center.Y - radius;
cirleRect.Width = cirleRect.Height = diameter;
//画同心圆
for (int i = 0; i < count; i++)
{
g.DrawEllipse(Pens.Gray, cirleRect);
cirleRect.X += radiusStep;
cirleRect.Y += radiusStep;
cirleRect.Width -= diameterStep;
cirleRect.Height -= diameterStep;
}
}
}
}