public static void Initialize(System.Windows.Forms.PictureBox picture_box) { canvas = picture_box.CreateGraphics(); red_pen = new System.Drawing.Pen(System.Drawing.Color.Red); green_pen = new System.Drawing.Pen(System.Drawing.Color.Green); blue_pen = new System.Drawing.Pen(System.Drawing.Color.Cyan); black_pen = new System.Drawing.Pen(System.Drawing.Color.Black); white_pen = new System.Drawing.Pen(System.Drawing.Color.White); gray_pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(255, 20, 20, 20)); red_pen.Width = green_pen.Width = blue_pen.Width = black_pen.Width = white_pen.Width = gray_pen.Width = 3; }
public Rectangle _InkSpaceToPixelRect(System.Windows.Forms.PictureBox pictureBox, InkCollector inkpicture, Rectangle rect) { //Graphics g = inkpicture.CreateGraphics(); Graphics g = pictureBox.CreateGraphics(); Point p1 = rect.Location; Point p2 = new Point(rect.Width, rect.Height); inkpicture.Renderer.InkSpaceToPixel(g, ref p1); inkpicture.Renderer.InkSpaceToPixel(g, ref p2); g.Dispose(); return(new Rectangle(p1.X, p1.Y, p2.X, p2.Y)); }
// PLot the path and create the report public string PrintShortestRouteTo(Vertex destination, System.Windows.Forms.PictureBox pictureBox1) { Vertex previous = destination; float x1, y1, x2, y2; x1 = y1 = x2 = y2 = -1; Pen pen = new Pen(Color.Yellow, 3); Graphics objGraphics = pictureBox1.CreateGraphics(); string output = "Distance from start: " + destination.distanceFromStart + Environment.NewLine; output = output + Environment.NewLine + "Path: " + Environment.NewLine; // For each two vertices draw the line // use x and y variables with -1 to hold while all points are not fullfilled while (previous != null) { // Get the coordinates if (x1 == -1 && y1 == -1) { x1 = previous.x; y1 = previous.y; } if (x2 == -1 && y2 == -1) { x2 = previous.x; y2 = previous.y; } // Path concactation output = output + previous.id; if (previous.previous != null) { output = output + " <- "; } // Trace when we have all points if (x1 != -1 && y1 != -1 && x2 != -1 && y2 != -1) { // Draw objGraphics.DrawLine(pen, x1 + 6, y1 + 6, x2, y2 + 6); // Swap x1 = x2; y1 = y2; x2 = -1; // Set up to get the next point y2 = -1; } previous = previous.previous; } return(output); }
public void KillHeap(System.Drawing.Graphics g, List <int> list, System.Windows.Forms.PictureBox box) { var dell = elements.Where(p => list.Any(i => i == p.Y)); for (int i = 0; i < 2; i++) { drawHeap(g, System.Drawing.Brushes.LawnGreen, dell); drawHeap(box.CreateGraphics(), System.Drawing.Brushes.LawnGreen, dell); System.Threading.Thread.Sleep(100); drawHeap(g, System.Drawing.Brushes.Green, dell); drawHeap(box.CreateGraphics(), System.Drawing.Brushes.Green, dell); System.Threading.Thread.Sleep(100); drawHeap(g, System.Drawing.Brushes.LightGreen, dell); drawHeap(box.CreateGraphics(), System.Drawing.Brushes.LightGreen, dell); System.Threading.Thread.Sleep(100); } elements.RemoveAll(p => list.Any(i => i == p.Y)); DrawHeap(g); DrawHeap(box.CreateGraphics()); System.Threading.Thread.Sleep(200); foreach (var i in list.OrderBy(j => j)) { for (int j = 0; j < elements.Count; j++) { if (elements[j].Y < i) { elements[j] = new System.Drawing.Point(elements[j].X, elements[j].Y + tetris.Properties.Settings.Default.SizeItem); } } } DrawHeap(g); DrawHeap(box.CreateGraphics()); System.Threading.Thread.Sleep(200); chekGame(); }
// Plot the vertices, edges and labels public void PrintVertices(System.Windows.Forms.PictureBox pictureBox1) { Graphics objGraphics = pictureBox1.CreateGraphics(); Brush brush = new SolidBrush(Color.Red); Pen pen = new Pen(Color.DarkBlue, 3); Font font = new Font("Tahoma", 14); // Scan all vetices // Draw lines int size = edges.Count; for (int i = 0; i < size; ++i) { Edge edge = edges.ElementAt(i); objGraphics.DrawLine(pen, edge.Vertex1.x + 6, edge.Vertex1.y + 6, edge.Vertex2.x, edge.Vertex2.y + 6); // Draw the associated cost float meanx, meany; float x, y; meanx = Math.Abs(edge.Vertex2.x - edge.Vertex1.x) / 2; meany = Math.Abs(edge.Vertex2.y - edge.Vertex1.y) / 2; if (edge.Vertex2.x < edge.Vertex1.x) { x = edge.Vertex2.x + meanx; } else { x = edge.Vertex1.x + meanx; } if (edge.Vertex2.y < edge.Vertex1.y) { y = edge.Vertex2.y + meany; } else { y = edge.Vertex1.y + meany; } objGraphics.DrawString(edge.Cost.ToString(), font, Brushes.Goldenrod, x, y); } // Draw points labels size = Vertices.Count; for (int i = 0; i < size; ++i) { Vertex Vertex = Vertices.ElementAt(i); objGraphics.FillEllipse(brush, Vertex.x, Vertex.y, 12, 12); objGraphics.DrawString(Vertex.id, font, Brushes.Black, Vertex.x, Vertex.y + 15); } }
/// <summary> /// Отрисовывает поле в указанную область. /// </summary> static public void DrawField() { if (_pictureBox == null) { return; } var g = _pictureBox.CreateGraphics(); g.Clear(System.Drawing.Color.Black); foreach (var screen in Screens) { g.DrawLine(new Pen(Brushes.Yellow), screen.X1, screen.Y1, screen.X2, screen.Y2); } foreach (var source in Sources) { for (var j = 0; j < 24; j += 6) { g.DrawEllipse(new Pen(source.Turn ? Brushes.White : Brushes.Blue), source.X - j / 2, source.Y - j / 2, j, j); } } }
// Needs to be called once to know associated object public void SetDrawDestination(ref System.Windows.Forms.PictureBox obj) { Video = obj.CreateGraphics(); VBlank(); }