/// <summary> /// Отрисовка фигуры /// </summary> public void Draw(PaintEventArgs ev) { dc = ev.Graphics; int dx, dy, mu = 5, ddx, ddy; int tx, ty; int x_x = (int)Math.Abs(x1 - x2) / 2; int y_y = (int)Math.Abs(y1 - y2) / 2; int rad = -nodes[0].Radius / 2; if (y2 < y1) { dy = -mu; ty = (int)y2; ddy = rad; } else { dy = 0; ty = (int)y1; ddy = -rad; } if (x2 < x1) { dx = -mu; tx = (int)x2; ddx = rad; } else { dx = 0; tx = (int)x1; ddx = -rad; } if (!directed) { Pen myPen = new Pen(color, mu); System.Drawing.Drawing2D.GraphicsPath hPath = new System.Drawing.Drawing2D.GraphicsPath(); hPath.AddLine(new Point(3, rad), new Point(0, -5)); //магические числа hPath.AddLine(new Point(-3, rad), new Point(0, -5)); System.Drawing.Drawing2D.CustomLineCap hCap = new System.Drawing.Drawing2D.CustomLineCap(null, hPath); myPen.CustomEndCap = hCap; dc.DrawLine(myPen, (int)x1 + dx + ddx, (int)y1 + dy + ddy, (int)x2 + dx - ddx, (int)y2 + dy - ddy); } else { dc.DrawLine(new Pen(color, mu), (int)x1 + dx + ddx, (int)y1 + dy + ddy, (int)x2 + dx - ddx, (int)y2 + dy - ddy); } Font font = new Font("Arial", 16, FontStyle.Regular); dc.DrawString(weight.ToString(), font, new SolidBrush(color2), (int)(tx + x_x), (int)(ty + y_y)); }
public void paint_me(ref Graphics gr0) { if (map_generated == true) { //foreach (map_triangle tri in the_squaregrid.all_triangle) //{ // SolidBrush poly_brush = new SolidBrush(Color.BlueViolet); // PointF pt1 = the_squaregrid.all_nodes[tri.index_0].get_pt; // PointF pt2 = the_squaregrid.all_nodes[tri.index_1].get_pt; // PointF pt3 = the_squaregrid.all_nodes[tri.index_2].get_pt; // PointF[] tri_pt = { pt1, pt2, pt3 }; // gr0.FillPolygon(poly_brush, tri_pt); //} // Paint Border Edges foreach (map_edge edge in the_squaregrid.border_edges) { PointF pt1 = the_squaregrid.all_nodes[edge.index_0].get_pt; PointF pt2 = the_squaregrid.all_nodes[edge.index_1].get_pt; PointF mid_pt = return_mid_pt(pt1, pt2); System.Drawing.Drawing2D.GraphicsPath end_path = new System.Drawing.Drawing2D.GraphicsPath(); end_path.AddLine(0, 0, -2, -2); end_path.AddLine(0, 0, 2, -2); System.Drawing.Drawing2D.CustomLineCap end_cap = new System.Drawing.Drawing2D.CustomLineCap(null, end_path); Pen edge_pen_capped = new Pen(Color.DarkGreen, 2); edge_pen_capped.CustomEndCap = end_cap; gr0.DrawLine(edge_pen_capped, pt1, mid_pt); Pen edge_pen = new Pen(Color.DarkGreen, 2); gr0.DrawLine(edge_pen, mid_pt, pt2); } // Paint Border Nodes foreach (map_node nd in the_squaregrid.border_nodes) { SolidBrush nd_brush = new SolidBrush(Color.DarkOrange); gr0.FillEllipse(nd_brush, nd.get_rectangle(new SizeF(4, 4))); } //for (int x = 0; x < the_squaregrid.the_squares.GetLength(0); x++) //{ // for (int y = 0; y < the_squaregrid.the_squares.GetLength(1); y++) // { // SizeF rect_size = new SizeF((float)(spacing * 0.4), (float)(spacing * 0.4)); // //PointF rect_pt; // Pen rect_pen; // // Paint top left // rect_pen = new Pen(the_squaregrid.the_squares[x, y].topleft.active == true ? Color.Brown : Color.White); // gr0.FillRectangle(rect_pen.Brush, the_squaregrid.the_squares[x, y].topleft.get_rectangle(rect_size)); // // Paint top right // rect_pen = new Pen(the_squaregrid.the_squares[x, y].topright.active == true ? Color.Brown : Color.White); // gr0.FillRectangle(rect_pen.Brush, the_squaregrid.the_squares[x, y].topright.get_rectangle(rect_size)); // // Paint bottom right // rect_pen = new Pen(the_squaregrid.the_squares[x, y].bottomright.active == true ? Color.Brown : Color.White); // gr0.FillRectangle(rect_pen.Brush, the_squaregrid.the_squares[x, y].bottomright.get_rectangle(rect_size)); // // Paint bottom left // rect_pen = new Pen(the_squaregrid.the_squares[x, y].bottomleft.active == true ? Color.Brown : Color.White); // gr0.FillRectangle(rect_pen.Brush, the_squaregrid.the_squares[x, y].bottomleft.get_rectangle(rect_size)); // // Paint centers for reference // rect_size = new SizeF((float)(spacing * 0.15), (float)(spacing * 0.15)); // rect_pen = new Pen(Color.Gray); // gr0.FillRectangle(rect_pen.Brush, the_squaregrid.the_squares[x, y].centretop.get_rectangle(rect_size)); // gr0.FillRectangle(rect_pen.Brush, the_squaregrid.the_squares[x, y].centreright.get_rectangle(rect_size)); // gr0.FillRectangle(rect_pen.Brush, the_squaregrid.the_squares[x, y].centrebottom.get_rectangle(rect_size)); // gr0.FillRectangle(rect_pen.Brush, the_squaregrid.the_squares[x, y].centreleft.get_rectangle(rect_size)); // } //} //for (int x = 0; x < c_width; x++) //{ // for (int y = 0; y < c_height; y++) // { // PointF grid_pt = new PointF((x - (int)(c_width * 0.5)) * spacing, (y - (int)(c_height * 0.5)) * spacing); // SizeF grid_sz = new SizeF(spacing, spacing); // Pen rect_pen = new Pen(map[x, y] == 0 ? Color.White : Color.Brown, 2); // map[x,y == 0 white color // gr0.FillRectangle(rect_pen.Brush, grid_pt.X, -grid_pt.Y, grid_sz.Width, grid_sz.Height); // } //} } }
private CustomLineCap(System.Drawing.Drawing2D.CustomLineCap customLineCap) { WrappedCustomLineCap = customLineCap; }
/// <summary> /// Initializes a new instance of the <see cref="T:Common.Drawing.Drawing2D.CustomLineCap" /> class from the /// specified existing <see cref="T:Common.Drawing.Drawing2D.LineCap" /> enumeration with the specified outline, fill, /// and inset. /// </summary> /// <param name="fillPath"> /// A <see cref="T:Common.Drawing.Drawing2D.GraphicsPath" /> object that defines the fill for the /// custom cap. /// </param> /// <param name="strokePath"> /// A <see cref="T:Common.Drawing.Drawing2D.GraphicsPath" /> object that defines the outline of /// the custom cap. /// </param> /// <param name="baseCap">The line cap from which to create the custom cap. </param> /// <param name="baseInset">The distance between the cap and the line. </param> public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap, float baseInset) { WrappedCustomLineCap = new System.Drawing.Drawing2D.CustomLineCap(fillPath, strokePath, (System.Drawing.Drawing2D.LineCap)baseCap, baseInset); }
/// <summary> /// Initializes a new instance of the <see cref="T:Common.Drawing.Drawing2D.CustomLineCap" /> class with the /// specified outline and fill. /// </summary> /// <param name="fillPath"> /// A <see cref="T:Common.Drawing.Drawing2D.GraphicsPath" /> object that defines the fill for the /// custom cap. /// </param> /// <param name="strokePath"> /// A <see cref="T:Common.Drawing.Drawing2D.GraphicsPath" /> object that defines the outline of /// the custom cap. /// </param> public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath) { WrappedCustomLineCap = new System.Drawing.Drawing2D.CustomLineCap(fillPath, strokePath); }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { switch (listBox1.SelectedIndex) { case 0: { MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Round, System.Drawing. Drawing2D.LineCap.Round, System.Drawing.Drawing2D.DashCap.Round); break; } case 1: { MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.ArrowAnchor, System.Drawing. Drawing2D.LineCap.ArrowAnchor, System.Drawing.Drawing2D.DashCap.Round); break; } case 2: { MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Square, System.Drawing. Drawing2D.LineCap.Square, System.Drawing.Drawing2D.DashCap.Round); break; } case 3: { MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Triangle, System.Drawing. Drawing2D.LineCap.Triangle, System.Drawing.Drawing2D.DashCap.Round); break; } case 4: { MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.DiamondAnchor, System.Drawing. Drawing2D.LineCap.DiamondAnchor, System.Drawing.Drawing2D.DashCap.Round); break; } case 5: { System.Drawing.Drawing2D.GraphicsPath hPath = new System.Drawing.Drawing2D.GraphicsPath(); Rectangle rect = new Rectangle(0,0,(int)MyPen.Width,(int)MyPen.Width); hPath.AddString("O", FontFamily.GenericSansSerif, (int)FontStyle.Italic, (float)0.05, rect, StringFormat.GenericDefault); System.Drawing.Drawing2D.CustomLineCap HookCap = new System.Drawing.Drawing2D.CustomLineCap(null, hPath); HookCap.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round); MyPen.CustomStartCap = HookCap; MyPen.CustomEndCap = HookCap; MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Custom, System.Drawing. Drawing2D.LineCap.Custom, System.Drawing.Drawing2D.DashCap.Round); break; } } }