public static void DrawHatchStyle(DrawItemEventArgs e) { if (e.Index >= 0) { var g = e.Graphics; var rect = e.Bounds; if ((e.State & DrawItemState.Selected) > 0) { rect.Width--; } var hatchRect = new Rectangle(rect.X + 2, rect.Y + 2, 19, rect.Height - 5); #region Fill StiControlPaint.DrawItem(g, rect, e.State, SystemColors.Window, SystemColors.ControlText); #endregion using (var brush = new HatchBrush(StiBrushes.HatchStyles[e.Index], Color.Black, Color.White)) { g.FillRectangle(brush, hatchRect); } g.DrawRectangle(Pens.Black, hatchRect); #region Paint name using (var font = new Font("Arial", 8)) { using (var stringFormat = new StringFormat()) { stringFormat.LineAlignment = StringAlignment.Center; stringFormat.FormatFlags = StringFormatFlags.NoWrap; stringFormat.Trimming = StringTrimming.EllipsisCharacter; var hatchStyle = StiBrushes.HatchStyles[e.Index]; string name = StiLocalization.Get("PropertyHatchStyle", hatchStyle.ToString()); e.Graphics.DrawString(name, font, Brushes.Black, new Rectangle(25, rect.Top, rect.Width - 18, 16), stringFormat); } } #endregion } }
public static void DrawPenStyle(DrawItemEventArgs e) { Graphics g = e.Graphics; Rectangle rect = e.Bounds; Rectangle borderRect = new Rectangle(rect.X + 2, rect.Y + 2, 52, 14); #region Fill rect.Width--; StiControlPaint.DrawItem(g, rect, e.State, SystemColors.Window, SystemColors.ControlText); #endregion #region Paint border style Array obj = Enum.GetValues(typeof(StiPenStyle)); using (Pen pen = new Pen(Color.Black, 2)) { StiPenStyle penStyle = StiPenStyle.Solid; if (e.Index != -1) { penStyle = (StiPenStyle)obj.GetValue(e.Index); } pen.DashStyle = StiPenUtils.GetPenStyle(penStyle); g.FillRectangle(Brushes.White, borderRect); int center = rect.Top + rect.Height / 2; if (penStyle == StiPenStyle.Double) { pen.Width = 1; g.DrawLine(pen, 2, center - 1, 54, center - 1); g.DrawLine(pen, 2, center + 1, 54, center + 1); } else if (penStyle != StiPenStyle.None) { g.DrawLine(pen, 2, center, 54, center); } } g.DrawRectangle(Pens.Black, borderRect); #endregion #region Paint name using (Font font = new Font("Arial", 8)) { using (StringFormat stringFormat = new StringFormat()) { stringFormat.LineAlignment = StringAlignment.Center; string name = ((StiPenStyle)obj.GetValue(e.Index)).ToString(); string locName = StiLocalization.Get("PropertyEnum", "StiPenStyle" + name); if (locName != null) { name = locName; } e.Graphics.DrawString(name, font, Brushes.Black, new Rectangle(55, rect.Top + 4, rect.Width - 18, 10), stringFormat); } } #endregion }
public static void DrawCapStyle(DrawItemEventArgs e) { Graphics g = e.Graphics; Rectangle rect = e.Bounds; Rectangle borderRect = new Rectangle(rect.X + 2, rect.Y + 2, 52, 14); #region Fill rect.Width--; StiControlPaint.DrawItem(g, rect, e.State, SystemColors.Window, SystemColors.ControlText); #endregion #region Paint border style Array obj = Enum.GetValues(typeof(StiCapStyle)); using (Pen pen = new Pen(Color.DimGray, 1)) { StiCapStyle capStyle = StiCapStyle.None; if (e.Index != -1) { capStyle = (StiCapStyle)obj.GetValue(e.Index); } g.FillRectangle(Brushes.White, borderRect); int yCenter = borderRect.Top + borderRect.Height / 2; int xStep = borderRect.Width / 4; PointF[] points = null; SmoothingMode mode = g.SmoothingMode; g.SmoothingMode = SmoothingMode.AntiAlias; switch (capStyle) { #region None case StiCapStyle.None: g.DrawLine(pen, borderRect.X + xStep, yCenter, borderRect.Right - xStep, yCenter); break; #endregion #region Arrow case StiCapStyle.Arrow: g.DrawLine(pen, borderRect.X + xStep, yCenter, borderRect.Right - xStep, yCenter); Rectangle capArrowRECT = new Rectangle(borderRect.Right - xStep - 4, borderRect.Y + 2, 5, 11); g.SmoothingMode = mode; points = new PointF[] { new PointF(capArrowRECT.Right, capArrowRECT.Y + (float)(capArrowRECT.Height / 2)), new PointF(capArrowRECT.Left, capArrowRECT.Y), new PointF(capArrowRECT.Left, capArrowRECT.Bottom) }; using (Brush capBrush = new SolidBrush(Color.DimGray)) { g.FillPolygon(capBrush, points); } break; #endregion #region Open case StiCapStyle.Open: g.DrawLine(pen, borderRect.X + xStep, yCenter, borderRect.Right - xStep, yCenter); Rectangle capOpenRECT = new Rectangle(borderRect.Right - xStep - 4, borderRect.Y + 4, 5, 7); points = new PointF[] { new PointF(capOpenRECT.X, capOpenRECT.Y), new PointF(capOpenRECT.Right, capOpenRECT.Y + (float)(capOpenRECT.Height / 2)), new PointF(capOpenRECT.X, capOpenRECT.Bottom) }; using (Pen openPen = new Pen(Color.DimGray)) { g.DrawLines(openPen, points); } break; #endregion #region Stealth case StiCapStyle.Stealth: g.DrawLine(pen, borderRect.X + xStep, yCenter, borderRect.Right - xStep, yCenter); Rectangle capStealthRECT = new Rectangle(borderRect.Right - xStep - 9, borderRect.Y + 2, 10, 11); points = new PointF[] { new PointF(capStealthRECT.X, capStealthRECT.Y), new PointF(capStealthRECT.Right, capStealthRECT.Y + (float)(capStealthRECT.Height / 2)), new PointF(capStealthRECT.X, capStealthRECT.Bottom), new PointF(capStealthRECT.X + (float)(capStealthRECT.Width / 3), capStealthRECT.Y + (float)(capStealthRECT.Height / 2)), new PointF(capStealthRECT.X, capStealthRECT.Y) }; using (Brush capBrush = new SolidBrush(Color.DimGray)) { g.FillPolygon(capBrush, points); } break; #endregion #region Diamond case StiCapStyle.Diamond: g.DrawLine(pen, borderRect.X + xStep, yCenter, borderRect.Right - xStep, yCenter); Rectangle capDiamondRECT = new Rectangle(borderRect.Right - xStep - 6, borderRect.Y + 3, 8, 9); points = new PointF[] { new PointF(capDiamondRECT.X, capDiamondRECT.Y + (float)(capDiamondRECT.Height / 2)), new PointF(capDiamondRECT.X + (float)(capDiamondRECT.Width / 2), capDiamondRECT.Y), new PointF(capDiamondRECT.Right, capDiamondRECT.Y + (float)(capDiamondRECT.Height / 2)), new PointF(capDiamondRECT.X + (float)(capDiamondRECT.Width / 2), capDiamondRECT.Bottom) }; using (Brush diamondBrush = new SolidBrush(Color.DimGray)) { g.FillPolygon(diamondBrush, points); } break; #endregion #region Oval case StiCapStyle.Oval: g.DrawLine(pen, borderRect.X + xStep, yCenter, borderRect.Right - xStep, yCenter); Rectangle capOvalRECT = new Rectangle(borderRect.Right - xStep - 4, borderRect.Y + 4, 6, 6); using (Brush ovalBrush = new SolidBrush(Color.DimGray)) { g.FillEllipse(ovalBrush, capOvalRECT); } break; #endregion #region Square case StiCapStyle.Square: g.DrawLine(pen, borderRect.X + xStep, yCenter, borderRect.Right - xStep, yCenter); Rectangle capSquareRECT = new Rectangle(borderRect.Right - xStep - 4, borderRect.Y + 4, 6, 6); g.SmoothingMode = mode; using (Brush squareBrush = new SolidBrush(Color.DimGray)) { g.FillRectangle(squareBrush, capSquareRECT); } break; #endregion } g.SmoothingMode = mode; } g.DrawRectangle(Pens.Black, borderRect); #endregion #region Paint name using (Font font = new Font("Arial", 8)) { using (StringFormat stringFormat = new StringFormat()) { stringFormat.LineAlignment = StringAlignment.Center; object capStyle = obj.GetValue(e.Index); string locName = StiLocalization.Get("PropertyEnum", typeof(StiCapStyle).Name + Enum.GetName(typeof(StiCapStyle), capStyle), false); e.Graphics.DrawString(locName, font, Brushes.Black, new Rectangle(55, rect.Top + 4, rect.Width - 18, 10), stringFormat); } } #endregion }