private void draw_area_MouseUp(object sender, MouseEventArgs e) { figure fig; switch (activeTool) { case Tool.Line: graphics.DrawLine(pen, first_p, second_p); fig = new figure(first_p, second_p, "line", pen); figures.Add(fig); break; case Tool.Rectangle: graphics.DrawRectangle(pen, GetRectangle(first_p, second_p)); fig = new figure(first_p, second_p, "rectangle", pen); figures.Add(fig); break; case Tool.Ellipse: graphics.DrawEllipse(pen, first_p.X, first_p.Y, second_p.X - first_p.X, second_p.Y - first_p.Y); fig = new figure(first_p, second_p, "ellipse", pen); figures.Add(fig); break; case Tool.Star: graphics.DrawPolygon(pen, Star(first_p, second_p)); fig = new figure(first_p, second_p, "star", pen); figures.Add(fig); break; case Tool.Triangle: graphics.DrawPolygon(pen, Triangle(first_p, second_p)); fig = new figure(first_p, second_p, "triangle", pen); figures.Add(fig); break; case Tool.Right_Triangle: graphics.DrawPolygon(pen, Right_Triangle(first_p, second_p)); fig = new figure(first_p, second_p, "right-triangle", pen); figures.Add(fig); break; case Tool.Cursor: if (moving.NULL == false) { figures.Add(moving); moving = new figure(); first_p = new Point(); second_p = new Point(); Draw(graphics); } break; default: break; } }
private void draw_area_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { second_p = e.Location; switch (activeTool) { case Tool.Pencil: graphics.DrawLine(pen, first_p, second_p); figure fig = new figure(first_p, second_p, "pencil", pen); figures.Add(fig); first_p = second_p; break; default: break; } draw_area.Refresh(); } }
private void draw_area_Paint(object sender, PaintEventArgs e) { switch (activeTool) { case Tool.Pencil: break; case Tool.Line: e.Graphics.DrawLine(pen, first_p, second_p); break; case Tool.Rectangle: e.Graphics.DrawRectangle(pen, GetRectangle(first_p, second_p)); break; case Tool.Ellipse: e.Graphics.DrawEllipse(pen, first_p.X, first_p.Y, second_p.X - first_p.X, second_p.Y - first_p.Y); break; case Tool.Star: e.Graphics.DrawPolygon(pen, Star(first_p, second_p)); break; case Tool.Triangle: e.Graphics.DrawPolygon(pen, Triangle(first_p, second_p)); break; case Tool.Right_Triangle: e.Graphics.DrawPolygon(pen, Right_Triangle(first_p, second_p)); break; case Tool.Cursor: if (moving.NULL == true) { for (int i = 0; i < figures.Count; i++) { if (figures[i].type != "pencil") { if (first_p.X >= figures[i].first.X && first_p.X <= figures[i].second.X && first_p.Y >= figures[i].first.Y && first_p.Y <= figures[i].second.Y) { moving = new figure(figures[i].first, figures[i].second, figures[i].type, figures[i].pen); figures.RemoveAt(i); break; } } } } else { int h = Math.Abs(moving.second.Y - moving.first.Y); int w = Math.Abs(moving.second.X - moving.first.X); moving.first = second_p; moving.second.X = moving.first.X + w; moving.second.Y = moving.first.Y + h; first_p = second_p; Figure_Draw(moving.first, moving.second, moving.type, e.Graphics, moving.pen); } break; default: break; } }