private void fillWPointsToolStripMenuItem_Click(object sender, EventArgs e) { Point p; Random r = new Random(); for (int i = 0; i < 10000; i++) { p = new Point((int)Math.Ceiling(r.NextDouble() * Width), (int)Math.Ceiling(r.NextDouble() * Width), Color.Chartreuse); p.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); } }
private void MainCAD_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && chosenShape == Shapes.Point) { Point p = new Point(e.X, e.Y, chosenColor); p.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); shapeList.Add(p); } else if (e.Button == MouseButtons.Right) { if (colorSelection.ShowDialog() == DialogResult.OK) { chosenColor = colorSelection.Color; } } }
private void btnDrawPoint_Click(object sender, EventArgs e) { Point p = new Point((e as MouseEventArgs).X, (e as MouseEventArgs).Y, Color.Aqua); p.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); }
private void MainCAD_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point start = new Point(xStart, yStart, chosenColor); Point end = new Point(xEnd, yEnd, chosenColor); int deltaX; int deltaY; switch (chosenShape) { case Shapes.Point: end = new Point(e.X, e.Y, chosenColor); end.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); shapeList.Add(end); break; case Shapes.Line: //Cancella la vecchia linea disegnandone una nuova dello stesso colore Line line = new Line(start, end, BackColor); line.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); //Disegna la nuova linea xEnd = e.X; yEnd = e.Y; end = new Point(xEnd, yEnd, chosenColor); line = new Line(start, end, chosenColor); line.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); RenderRefresh(); break; case Shapes.Rectangle: { //Cancella il vecchio rettangolo deltaX = xEnd - xStart; deltaY = yEnd - yStart; Rectangle rectangle = new Rectangle(BackColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY); rectangle.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); //Aggiorna la posizione del mouse xEnd = e.X; yEnd = e.Y; deltaX = xEnd - xStart; deltaY = yEnd - yStart; rectangle = new Rectangle(chosenColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY); rectangle.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); RenderRefresh(); } break; case Shapes.Square: deltaX = xEnd - xStart; Square square = new Square(BackColor, new Point(xStart, yStart), deltaX); square.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); xEnd = e.X; yEnd = e.Y; deltaX = xEnd - xStart; square = new Square(chosenColor, new Point(xStart, yStart, chosenColor), deltaX); square.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); RenderRefresh(); break; case Shapes.Ellipsis: deltaX = xEnd - xStart; deltaY = yEnd - yStart; if (ctrlKeyDown) { deltaX = deltaY = Math.Max(deltaX, deltaY); } Ellipsis ellipsis = new Ellipsis(BackColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY); ellipsis.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); xEnd = e.X; yEnd = e.Y; deltaX = xEnd - xStart; deltaY = yEnd - yStart; if (ctrlKeyDown) { deltaY = deltaX = Math.Max(deltaX, deltaY); } ellipsis = new Ellipsis(chosenColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY); ellipsis.Draw(toolStripContainer1.ContentPanel.CreateGraphics()); RenderRefresh(); break; } } }