using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; // a simple line class // Indigo Softworks 2004 namespace Indigo { /// /// A line control that can be either vertically, horizontally or diagonally oriented /// internal class Line : System.Windows.Forms.UserControl { public enum LineOrientation { Horizontal, Vertical, Ascending, Descending }; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; // Color of the line. Color 1 is the main color and color 2 the "shadow" color. private Color color1, color2; // Orientation of the line private LineOrientation orientation; public Line() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // Initialize variables this.color1 = System.Drawing.SystemColors.GrayText; this.color2 = Color.WhiteSmoke; orientation = LineOrientation.Horizontal; } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Component Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { // // Line // this.Name = "Line"; this.Size = new System.Drawing.Size(72, 112); this.Resize += new System.EventHandler(this.Line_Resize); } #endregion [Description("Line orientation."), Category("Appearance")] public LineOrientation Orientation { get { return orientation; } set { orientation = value; Invalidate(); } } [Description("The primary line color."), Category("Appearance")] public Color PrimaryColor { get { return this.color1; } set { this.color1 = value; Invalidate(); } } [Description("The secondary line color."), Category("Appearance")] public Color SecondaryColor { get { return this.color2; } set { this.color2 = value; Invalidate(); } } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; Pen pen = new Pen(color1); Pen pen2 = new Pen(color2); // Draw horizontal line if (orientation == LineOrientation.Horizontal && this.Width > 1) { g.DrawLine(pen, 0, this.Height / 2, this.Width, this.Height / 2); g.DrawLine(pen2, 0, this.Height / 2+1, this.Width, this.Height / 2+1); } // Draw vertical line else if (orientation == LineOrientation.Vertical && this.Height > 1) { g.DrawLine(pen, this.Width / 2, 0, this.Width / 2, this.Height); g.DrawLine(pen2, this.Width / 2+1, 0, this.Width / 2+1, this.Height); } // Draw diagonal line else if (this.Height > 1 && this.Width > 1) { // Descending line if (orientation == LineOrientation.Descending) { g.DrawLine(pen2, 0, 1, this.Width, this.Height-1); g.DrawLine(pen, 0, 0, this.Width, this.Height-2); } // Ascending line else { g.DrawLine(pen2, 0, this.Height-1, this.Width, 1); g.DrawLine(pen, 0, this.Height-2, this.Width, 0); } } pen.Dispose(); } private void Line_Resize(object sender, System.EventArgs e) { Invalidate(); } } }