private void DrawLineCap(Graphics g, Point linePoint, eLineEndType lineCap, Size capSize, bool isStartCap) { if (lineCap == eLineEndType.Arrow) { SmoothingMode sm = g.SmoothingMode; g.SmoothingMode = SmoothingMode.HighQuality; using (GraphicsPath path = new GraphicsPath()) { if (isStartCap) { if (VerticalLine) path.AddLines(new Point[] { new Point(linePoint.X, linePoint.Y), new Point(linePoint.X - capSize.Width/2, linePoint.Y+capSize.Height), new Point(linePoint.X+capSize.Width / 2, linePoint.Y+capSize.Height)}); else path.AddLines(new Point[] { new Point(linePoint.X, linePoint.Y), new Point(linePoint.X + capSize.Width, linePoint.Y-capSize.Height/2), new Point(linePoint.X+capSize.Width, linePoint.Y+ capSize.Height/2)}); } else { if (VerticalLine) path.AddLines(new Point[] { new Point(linePoint.X, linePoint.Y), new Point(linePoint.X + capSize.Width / 2, linePoint.Y - capSize.Height), new Point(linePoint.X - capSize.Width / 2, linePoint.Y - capSize.Height)}); else path.AddLines(new Point[] { new Point(linePoint.X, linePoint.Y), new Point(linePoint.X - capSize.Width, linePoint.Y + capSize.Height / 2), new Point(linePoint.X - capSize.Width, linePoint.Y - capSize.Height/2)}); } path.CloseAllFigures(); using (SolidBrush brush = new SolidBrush(ForeColor)) g.FillPath(brush, path); } g.SmoothingMode = sm; } else if (lineCap == eLineEndType.Circle) { SmoothingMode sm = g.SmoothingMode; g.SmoothingMode = SmoothingMode.HighQuality; using (SolidBrush brush = new SolidBrush(ForeColor)) { if (VerticalLine && isStartCap) g.FillEllipse(brush, new Rectangle(linePoint.X - capSize.Width/2, linePoint.Y , capSize.Width, capSize.Height)); else if (VerticalLine) g.FillEllipse(brush, new Rectangle(linePoint.X - capSize.Width/2, linePoint.Y - capSize.Height - 1, capSize.Width, capSize.Height)); else if (isStartCap) g.FillEllipse(brush, new Rectangle(linePoint.X, linePoint.Y - capSize.Height / 2, capSize.Width, capSize.Height)); else g.FillEllipse(brush, new Rectangle(linePoint.X - capSize.Width - 1, linePoint.Y - capSize.Height / 2, capSize.Width, capSize.Height)); } g.SmoothingMode = sm; } else if (lineCap == eLineEndType.Diamond) { SmoothingMode sm = g.SmoothingMode; g.SmoothingMode = SmoothingMode.HighQuality; using (GraphicsPath path = new GraphicsPath()) { if (isStartCap) { if (VerticalLine) path.AddLines(new Point[] { new Point(linePoint.X, linePoint.Y), new Point(linePoint.X - capSize.Width/2, linePoint.Y+capSize.Height / 2), new Point(linePoint.X, linePoint.Y+capSize.Height), new Point(linePoint.X+capSize.Width / 2, linePoint.Y+capSize.Height / 2)}); else path.AddLines(new Point[] { new Point(linePoint.X, linePoint.Y), new Point(linePoint.X + capSize.Width/2, linePoint.Y-capSize.Height/2), new Point(linePoint.X + capSize.Width, linePoint.Y), new Point(linePoint.X+capSize.Width / 2, linePoint.Y+ capSize.Height/2)}); } else { if (VerticalLine) { linePoint.Y--; path.AddLines(new Point[] { new Point(linePoint.X, linePoint.Y), new Point(linePoint.X + capSize.Width / 2, linePoint.Y - capSize.Height / 2), new Point(linePoint.X, linePoint.Y - capSize.Height), new Point(linePoint.X - capSize.Width / 2, linePoint.Y - capSize.Height / 2)}); } else { linePoint.X--; path.AddLines(new Point[] { new Point(linePoint.X, linePoint.Y), new Point(linePoint.X - capSize.Width / 2, linePoint.Y - capSize.Height / 2), new Point(linePoint.X - capSize.Width, linePoint.Y), new Point(linePoint.X - capSize.Width / 2, linePoint.Y + capSize.Height/2)}); } } path.CloseAllFigures(); using (SolidBrush brush = new SolidBrush(ForeColor)) g.FillPath(brush, path); } g.SmoothingMode = sm; } else if (lineCap == eLineEndType.Rectangle) { SmoothingMode sm = g.SmoothingMode; g.SmoothingMode = SmoothingMode.HighQuality; using (SolidBrush brush = new SolidBrush(ForeColor)) { if (VerticalLine && isStartCap) g.FillRectangle(brush, new Rectangle(linePoint.X - capSize.Width / 2, linePoint.Y, capSize.Width, capSize.Height)); else if (VerticalLine) g.FillRectangle(brush, new Rectangle(linePoint.X - capSize.Width / 2, linePoint.Y - capSize.Height - 1, capSize.Width, capSize.Height)); else if (isStartCap) g.FillRectangle(brush, new Rectangle(linePoint.X, linePoint.Y - capSize.Height / 2, capSize.Width, capSize.Height)); else g.FillRectangle(brush, new Rectangle(linePoint.X - capSize.Width - 1, linePoint.Y - capSize.Height / 2, capSize.Width, capSize.Height)); } g.SmoothingMode = sm; } }
/// <summary> /// Called when EndLineCap property has changed. /// </summary> /// <param name="oldValue">Old property value</param> /// <param name="newValue">New property value</param> protected virtual void OnEndLineCapChanged(eLineEndType oldValue, eLineEndType newValue) { //OnPropertyChanged(new PropertyChangedEventArgs("EndLineCap")); this.Refresh(); }