public override void Draw(Graphics graphics) { LinePen = new Pen(lineColor); if (isBold) { TextFont = new Font("Arial", fontSize); } FillBrush = fillColor; if (graphics == null) { return; } var box = new Rectangle() { Location = Corner, Size = Size }; graphics.FillRectangle(FillBrush, box); if (IsSelected) { var g = new GraphicsWithSelection() { MyGraphics = graphics }; g.DrawSelectionBox(Corner, Size); } else { graphics.DrawRectangle(LinePen, box); } var minimumSize = graphics.MeasureString("...", TextFont); if (Size.Width < minimumSize.Width - Padding * 2 || Size.Height < minimumSize.Height - Padding * 2) { return; } var formatter = new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter }; var textRectangle = new RectangleF(Corner.X + Padding, Corner.Y + Padding, Size.Width - Padding * 2, Size.Height - Padding * 2); graphics.DrawString(Label, TextFont, TextBrush, textRectangle, formatter); }
public override void Draw(Graphics graphics) { GraphicsPath hPath = new GraphicsPath(); // Create the outline for our custom end cap. /*hPath.AddLine(new Point(0, 0), new Point(0, -5)); * hPath.AddLine(new Point(0, -5), new Point(5, -1)); * hPath.AddLine(new Point(5, -1), new Point(3, -1));*/ ; if (LineType == "Aggregation") { Point p1 = new Point(0, 0); Point p2 = new Point(-capWidth, -capHeight); Point p3 = new Point(0, -(2 * capHeight)); Point p4 = new Point(capWidth, -capHeight); Point[] pD = { p1, p2, p3, p4 }; //FillMode newFillMode = FillMode.Winding; hPath.AddPolygon(pD); } if (LineType == "Composition") { Point p1 = new Point(0, 0); Point p2 = new Point(-capWidth, -capHeight); Point p3 = new Point(0, -(2 * capHeight)); Point p4 = new Point(capWidth, -capHeight); Point[] pD = { p1, p2, p3, p4 }; //FillMode newFillMode = FillMode.Winding; hPath.AddPolygon(pD); } if (LineType == "Genspec") { Point p1 = new Point(0, 0); Point p2 = new Point(-capWidth, -capHeight); //Point p3 = new Point(0, -(2 * capHeight)); Point p4 = new Point(capWidth, -capHeight); Point[] pD = { p1, p2, p4 }; //FillMode newFillMode = FillMode.Winding; hPath.AddPolygon(pD); } if (LineType == "Dependency") { hPath.AddLine(new Point(0, 0), new Point(-capWidth, -capHeight)); hPath.AddLine(new Point(0, 0), new Point(capWidth, -capHeight)); } hPath.FillMode = FillMode.Winding; Pen customCapPen = new Pen(lineColor, lineThickness); CustomLineCap HookCap; if (LineType == "Composition") { HookCap = new CustomLineCap(hPath, null); customCapPen.CustomStartCap = HookCap; } else { HookCap = new CustomLineCap(null, hPath); customCapPen.CustomStartCap = HookCap; } //CustomLineCap HookCap = new CustomLineCap(hPath, hPath); if (LineType == "Dependency") { customCapPen.DashPattern = new float[] { 4.0F, 2.0F, 1.0F, 3.0F }; } LineCap startCap; LineCap endCap; HookCap.GetStrokeCaps(out startCap, out endCap); RegularPen.StartCap = startCap; Point[] points = { new Point(Start.X, Start.Y), new Point(End.X, End.Y) }; //RegularPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Custom, System.Drawing.Drawing2D.LineCap.NoAnchor, System.Drawing.Drawing2D.DashCap.Flat); if (graphics == null) { return; } if (IsSelected) { var g = new GraphicsWithSelection() { MyGraphics = graphics }; g.DrawSelectionLine(Start, End); } else { //graphics.DrawLine(RegularPen, Start, End); graphics.DrawLines(customCapPen, points); if (LineType == "Binary") { graphics.DrawString(label, TextFont, TextBrush, (Start.X + End.X) / 2, (Start.Y + End.Y) / 2); } } }