using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace EAK.Usercontrols { public class SevenSegmentLed : Control { #region Properties/variables private System.ComponentModel.IContainer components; #region Appearance private System.Drawing.Color _LightBrush; [Category("Appearance")] [Description("basically the color of the LED segments")] [DefaultValue(typeof(Color), "Lime")] public System.Drawing.Color LightBrush { get { return _LightBrush; } set { _LightBrush = value; } } private int _LightWidth; [Category("Appearance")] [Description("basically the width of the LED segments")] [DefaultValue(10)] public int LightWidth { get { return _LightWidth; } set { _LightWidth = value; } } private int _LedMargin; [Category("Appearance")] [Description("basically the margin around the LED digit")] [DefaultValue(5)] public int LedMargin { get { return _LedMargin; } set { _LedMargin = value; } } private int _Gap; [Category("Appearance")] [Description("basically the gap between the segments")] [DefaultValue(1)] public int Gap { get { return _Gap; } set { _Gap = value; } } #endregion Appearance #region Segments private bool _HorizontalTop; [Category("Segments")] [Description("Horizontal Top Segment")] [DefaultValue(true)] public bool HorizontalTop { get { return _HorizontalTop; } set { this._HorizontalTop = value; } } private bool _HorizontalMiddle; [Category("Segments")] [Description("Horizontal Middle Segment")] [DefaultValue(true)] public bool HorizontalMiddle { get { return _HorizontalMiddle; } set { this._HorizontalMiddle = value; } } private bool _HorizontalBottom; [Category("Segments")] [Description("Horizontal Bottom Segment")] [DefaultValue(true)] public bool HorizontalBottom { get { return _HorizontalBottom; } set { this._HorizontalBottom = value; } } private bool _VerticalTopLeft; [Category("Segments")] [Description("Vertical Top Left Segment")] [DefaultValue(true)] public bool VerticalTopLeft { get { return _VerticalTopLeft; } set { this._VerticalTopLeft = value; } } private bool _VerticalTopRight; [Category("Segments")] [Description("Vertical Top Right Segment")] [DefaultValue(true)] public bool VerticalTopRight { get { return _VerticalTopRight; } set { this._VerticalTopRight = value; } } private bool _VerticalBottomLeft; [Category("Segments")] [Description("Vertical Bottom Left Segment")] [DefaultValue(true)] public bool VerticalBottomLeft { get { return _VerticalBottomLeft; } set { this._VerticalBottomLeft = value; } } private bool _VerticalBottomRight; [Category("Segments")] [Description("Vertical Bottom Right Segment")] [DefaultValue(true)] public bool VerticalBottomRight { get { return _VerticalBottomRight; } set { this._VerticalBottomRight = value; } } #endregion Segments #endregion Properties/variables #region Constructor/Destructor public SevenSegmentLed() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); this._LightBrush = Color.Lime; this._LedMargin = 5; this._LightWidth = 10; this._Gap = 1; this._HorizontalBottom = true; this._HorizontalMiddle = true; this._HorizontalTop = true; this._VerticalBottomLeft = true; this._VerticalBottomRight = true; this._VerticalTopLeft = true; this._VerticalTopRight = true; this.Size = new Size(60, 90); } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) components.Dispose(); } base.Dispose(disposing); } #endregion Constructor/Destructor #region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); } #endregion #region OnPaint() protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); System.Drawing.SolidBrush myBrush = new SolidBrush(this.LightBrush); float fBegX; float fBegY; float fWidth; float fHeight; #region Horizontal Segments // Horizontals fBegX = this.LedMargin + this.LightWidth + this.Gap; fWidth = this.Width - (this.LedMargin * 2) - (this.LightWidth * 2) - (this.Gap * 2); fHeight = this.LightWidth; //Top Horizontal fBegY = this.LedMargin; if (this.HorizontalTop) { pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathLeft(fBegX, fBegY, this.LightWidth))); pe.Graphics.FillRectangle(myBrush, fBegX, fBegY, fWidth, fHeight); pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathRight(fBegX + fWidth, fBegY, this.LightWidth))); } //Middle Horizontal fBegY = (this.Height / 2) - (this.LightWidth / 2); if (this.HorizontalMiddle) { pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathLeft(fBegX, fBegY, this.LightWidth))); pe.Graphics.FillRectangle(myBrush, fBegX, fBegY, fWidth, fHeight); pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathRight(fBegX + fWidth, fBegY, this.LightWidth))); } //Bottom Horizontal fBegY = this.Height - this.LedMargin - this.LightWidth; if (this.HorizontalBottom) { pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathLeft(fBegX, fBegY, this.LightWidth))); pe.Graphics.FillRectangle(myBrush, fBegX, fBegY, fWidth, fHeight); pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathRight(fBegX + fWidth, fBegY, this.LightWidth))); } #endregion Horizontal Segments #region Vertical Segments //Both Verticals fHeight = (this.Height / 2) - (this.LedMargin) - (this.LightWidth * 3 / 2) - (this.Gap * 2); fWidth = this.LightWidth; //Left Verticals fBegX = this.LedMargin; //Top Left Vertical fBegY = this.LedMargin + this.LightWidth / 2 * 2 + (this.Gap); if (this.VerticalTopLeft) { pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathUp(fBegX, fBegY, this.LightWidth))); pe.Graphics.FillRectangle(myBrush, fBegX, fBegY, fWidth, fHeight); pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathDown(fBegX, fBegY + fHeight, this.LightWidth))); } //Bottom Left Vertical fBegY = (this.Height / 2) + (this.LightWidth / 2) + (this.Gap); if (this.VerticalBottomLeft) { pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathUp(fBegX, fBegY, this.LightWidth))); pe.Graphics.FillRectangle(myBrush, fBegX, fBegY, fWidth, fHeight); pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathDown(fBegX, fBegY + fHeight, this.LightWidth))); } //Right Verticals fBegX = this.Width - (this.LedMargin + this.LightWidth); //Top Right Vertical fBegY = this.LedMargin + this.LightWidth / 2 * 2 + (this.Gap); if (this.VerticalTopRight) { pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathUp(fBegX, fBegY, this.LightWidth))); pe.Graphics.FillRectangle(myBrush, fBegX, fBegY, fWidth, fHeight); pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathDown(fBegX, fBegY + fHeight, this.LightWidth))); } //Bottom Right Vertical fBegY = (this.Height / 2) + (this.LightWidth / 2) + (this.Gap); if (this.VerticalBottomRight) { pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathUp(fBegX, fBegY, this.LightWidth))); pe.Graphics.FillRectangle(myBrush, fBegX, fBegY, fWidth, fHeight); pe.Graphics.FillRegion(myBrush, new Region(this.ArrowPathDown(fBegX, fBegY + fHeight, this.LightWidth))); } #endregion Vertical Segments myBrush.Dispose(); } #endregion OnPaint() #region Drawing Methods private System.Drawing.Drawing2D.GraphicsPath ArrowPathRight(float paraX, float paraY, float paraWidth) { // Right arrow System.Drawing.Drawing2D.GraphicsPath myPath = new GraphicsPath(); myPath.AddLine( paraX, paraY, paraX + (paraWidth / 2), paraY + (paraWidth / 2)); myPath.AddLine( paraX + (paraWidth / 2), paraY + (paraWidth / 2), paraX, paraY + paraWidth); myPath.AddLine( paraX, paraY + paraWidth, paraX, paraY); return myPath; } private System.Drawing.Drawing2D.GraphicsPath ArrowPathLeft(float paraX, float paraY, float paraWidth) { // Left arrow System.Drawing.Drawing2D.GraphicsPath myPath = new GraphicsPath(); myPath.AddLine( paraX, paraY, paraX - (paraWidth / 2), paraY + (paraWidth / 2)); myPath.AddLine( paraX - (paraWidth / 2), paraY + (paraWidth / 2), paraX, paraY + paraWidth); myPath.AddLine( paraX, paraY + paraWidth, paraX, paraY); return myPath; } private System.Drawing.Drawing2D.GraphicsPath ArrowPathUp(float paraX, float paraY, float paraWidth) { // Up arrow System.Drawing.Drawing2D.GraphicsPath myPath = new GraphicsPath(); myPath.AddLine( paraX, paraY, paraX + (paraWidth / 2), paraY - (paraWidth / 2)); myPath.AddLine( paraX + (paraWidth / 2), paraY - (paraWidth / 2), paraX + paraWidth, paraY); myPath.AddLine( paraX + paraWidth, paraY, paraX, paraY); return myPath; } private System.Drawing.Drawing2D.GraphicsPath ArrowPathDown(float paraX, float paraY, float paraWidth) { // Down arrow System.Drawing.Drawing2D.GraphicsPath myPath = new GraphicsPath(); myPath.AddLine( paraX, paraY, paraX + (paraWidth / 2), paraY + (paraWidth / 2)); myPath.AddLine( paraX + (paraWidth / 2), paraY + (paraWidth / 2), paraX + paraWidth, paraY); myPath.AddLine( paraX + paraWidth, paraY, paraX, paraY); return myPath; } #endregion Drawing Methods } }