/// <summary> /// Draws the border. /// </summary> /// <param name="g">Graphics canvas.</param> /// <param name="bounds">Bounds for border.</param> /// <param name="borderThickness">Border thickness.</param> /// <param name="borderColor">Border color.</param> public static void DrawBorder(Graphics g, RectangleF bounds, Thickness borderThickness, BorderColors borderColor) { if (borderColor.IsEmpty || borderThickness.IsZero) return; bounds.Width -= (float)borderThickness.Right / 2; bounds.Height -= (float)borderThickness.Bottom / 2; if (borderThickness.Left > 0d && !borderColor.Left.IsEmpty) { using (Pen pen = new Pen(borderColor.Left, (float)borderThickness.Left)) { pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset; g.DrawLine(pen, bounds.X, bounds.Y, bounds.X, bounds.Bottom); } } if (borderThickness.Top > 0d && !borderColor.Top.IsEmpty) { using (Pen pen = new Pen(borderColor.Top, (float)borderThickness.Top)) { pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset; g.DrawLine(pen, bounds.X, bounds.Y, bounds.Right, bounds.Y); } } if (borderThickness.Right > 0d && !borderColor.Right.IsEmpty) { using (Pen pen = new Pen(borderColor.Right, (float)borderThickness.Right)) { pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset; g.DrawLine(pen, bounds.Right, bounds.Y, bounds.Right, bounds.Bottom + (float)borderThickness.Bottom / 2); } } if (borderThickness.Bottom > 0d && !borderColor.Bottom.IsEmpty) { using (Pen pen = new Pen(borderColor.Bottom, (float)borderThickness.Bottom)) { pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset; g.DrawLine(pen, bounds.X, bounds.Bottom, bounds.Right, bounds.Bottom); } } }
internal static string ToSerializedValue(this BorderColors value) { switch (value) { case BorderColors.Black: return("black"); case BorderColors.Borderless: return("borderless"); case BorderColors.Gold: return("gold"); case BorderColors.Silver: return("silver"); case BorderColors.White: return("white"); } return(null); }
/// <summary> /// Called when BorderColor property has changed. /// </summary> /// <param name="oldValue">Old property value</param> /// <param name="newValue">New property value</param> protected virtual void OnBorderColorChanged(BorderColors oldValue, BorderColors newValue) { //OnPropertyChanged(new PropertyChangedEventArgs("BorderColor")); this.Invalidate(); }