学过C#的请进…
来源:百度知道 编辑:UC知道 时间:2024/06/21 04:05:29
//在窗体上画矩形,鼠标按下拖动就行了,颜色你自己改就可以了
Point p;
public void DrawRect(Rectangle rect)
{
SolidBrush brush = new SolidBrush(Color.FromArgb(20,0,0,255));
Graphics g = this.CreateGraphics();
g.FillRectangle(brush, rect);
brush.Dispose();
g.Dispose();
}
Rectangle[] hasDrawed = new Rectangle[100];
int index = 0;
bool IsDown = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
IsDown = true;
p = e.Location;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
IsDown = false;
hasDrawed[index] = lastRect;
index++;
lastRect = new Rectangle(new Point(0, 0), new Size(0, 0));
}
}
public void ClearRect(Rectangle r)
{
SolidBrus