Advertisement
modernaesthetics

Net Seal Theme - C# (PR Blue)

Jul 6th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 93.36 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Drawing.Text;
  6. using System.ComponentModel;
  7. using System.Text;
  8. using System.Collections.Generic;
  9.  
  10. //IMPORTANT:
  11. //Please leave these comments in place as they help protect intellectual rights and allow
  12. //developers to determine the version of the theme they are using. The preffered method
  13. //of distributing this theme is through the Nimoru Software home page at nimoru.com.
  14.  
  15. //Name: Net Seal Theme
  16. //Created: 6/21/2013
  17. //Version: 1.0.0.2 beta
  18. //Site: http://nimoru.com/
  19.  
  20. //This work is licensed under a Creative Commons Attribution 3.0 Unported License.
  21. //To view a copy of this license, please visit http://creativecommons.org/licenses/by/3.0/
  22.  
  23. //Copyright © 2013 Nimoru Software
  24.  
  25. static class ThemeModule
  26. {
  27.  
  28.     static ThemeModule()
  29.     {
  30.         TextBitmap = new Bitmap(1, 1);
  31.         TextGraphics = Graphics.FromImage(TextBitmap);
  32.     }
  33.  
  34.     private static Bitmap TextBitmap;
  35.  
  36.     private static Graphics TextGraphics;
  37.     static internal SizeF MeasureString(string text, Font font)
  38.     {
  39.         return TextGraphics.MeasureString(text, font);
  40.     }
  41.  
  42.     static internal SizeF MeasureString(string text, Font font, int width)
  43.     {
  44.         return TextGraphics.MeasureString(text, font, width, StringFormat.GenericTypographic);
  45.     }
  46.  
  47.     private static GraphicsPath CreateRoundPath;
  48.  
  49.     private static Rectangle CreateRoundRectangle;
  50.     static internal GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
  51.     {
  52.         CreateRoundRectangle = new Rectangle(x, y, width, height);
  53.         return CreateRound(CreateRoundRectangle, slope);
  54.     }
  55.  
  56.     static internal GraphicsPath CreateRound(Rectangle r, int slope)
  57.     {
  58.         CreateRoundPath = new GraphicsPath(FillMode.Winding);
  59.         CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
  60.         CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
  61.         CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
  62.         CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
  63.         CreateRoundPath.CloseFigure();
  64.         return CreateRoundPath;
  65.     }
  66.  
  67. }
  68.  
  69. class NSTheme : ThemeContainer154
  70. {
  71.  
  72.     private int _AccentOffset = 0;
  73.     public int AccentOffset
  74.     {
  75.         get { return _AccentOffset; }
  76.         set
  77.         {
  78.             _AccentOffset = value;
  79.             Invalidate();
  80.         }
  81.     }
  82.  
  83.     public NSTheme()
  84.     {
  85.         Header = 30;
  86.         BackColor = Color.FromArgb(50, 50, 50);
  87.  
  88.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  89.         P2 = new Pen(Color.FromArgb(60, 60, 60));
  90.  
  91.         B1 = new SolidBrush(Color.FromArgb(50, 50, 50));
  92.     }
  93.  
  94.  
  95.     protected override void ColorHook()
  96.     {
  97.     }
  98.  
  99.  
  100.     private Rectangle R1;
  101.     private Pen P1;
  102.     private Pen P2;
  103.  
  104.     private SolidBrush B1;
  105.  
  106.     private int Pad;
  107.     protected override void PaintHook()
  108.     {
  109.         G.Clear(BackColor);
  110.         DrawBorders(P2, 1);
  111.  
  112.         G.DrawLine(P1, 0, 26, Width, 26);
  113.         G.DrawLine(P2, 0, 25, Width, 25);
  114.  
  115.         Pad = Math.Max(Measure().Width + 20, 80);
  116.         R1 = new Rectangle(Pad, 17, Width - (Pad * 2) + _AccentOffset, 8);
  117.  
  118.         G.DrawRectangle(P2, R1);
  119.         G.DrawRectangle(P1, R1.X + 1, R1.Y + 1, R1.Width - 2, R1.Height);
  120.  
  121.         G.DrawLine(P1, 0, 29, Width, 29);
  122.         G.DrawLine(P2, 0, 30, Width, 30);
  123.  
  124.         DrawText(Brushes.Black, HorizontalAlignment.Left, 8, 1);
  125.         DrawText(Brushes.White, HorizontalAlignment.Left, 7, 0);
  126.  
  127.         G.FillRectangle(B1, 0, 27, Width, 2);
  128.         DrawBorders(Pens.Black);
  129.     }
  130.  
  131. }
  132.  
  133. class NSButton : Control
  134. {
  135.  
  136.     public NSButton()
  137.     {
  138.         SetStyle((ControlStyles)139286, true);
  139.         SetStyle(ControlStyles.Selectable, false);
  140.  
  141.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  142.         P2 = new Pen(Color.FromArgb(65, 65, 65));
  143.     }
  144.  
  145.  
  146.     private bool IsMouseDown;
  147.     private GraphicsPath GP1;
  148.  
  149.     private GraphicsPath GP2;
  150.     private SizeF SZ1;
  151.  
  152.     private PointF PT1;
  153.     private Pen P1;
  154.  
  155.     private Pen P2;
  156.     private PathGradientBrush PB1;
  157.  
  158.     private LinearGradientBrush GB1;
  159.  
  160.     private Graphics G;
  161.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  162.     {
  163.         G = e.Graphics;
  164.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  165.  
  166.         G.Clear(BackColor);
  167.         G.SmoothingMode = SmoothingMode.AntiAlias;
  168.  
  169.         GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  170.         GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  171.  
  172.         if (IsMouseDown) {
  173.             PB1 = new PathGradientBrush(GP1);
  174.             PB1.CenterColor = Color.FromArgb(60, 60, 60);
  175.             PB1.SurroundColors = new Color[] { Color.FromArgb(55, 55, 55) };
  176.             PB1.FocusScales = new PointF(0.8f, 0.5f);
  177.  
  178.             G.FillPath(PB1, GP1);
  179.         } else {
  180.             GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  181.             G.FillPath(GB1, GP1);
  182.         }
  183.  
  184.         G.DrawPath(P1, GP1);
  185.         G.DrawPath(P2, GP2);
  186.  
  187.         SZ1 = G.MeasureString(Text, Font);
  188.  
  189.         PT1 = new PointF((Width - (int)SZ1.Width) / 2, Height / 2 - SZ1.Height / 2);
  190.  
  191.         if (IsMouseDown) {
  192.             PT1.X += 1f;
  193.             PT1.Y += 1f;
  194.         }
  195.  
  196.         G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  197.         G.DrawString(Text, Font, Brushes.White, PT1);
  198.     }
  199.  
  200.     protected override void OnMouseDown(MouseEventArgs e)
  201.     {
  202.         IsMouseDown = true;
  203.         Invalidate();
  204.     }
  205.  
  206.     protected override void OnMouseUp(MouseEventArgs e)
  207.     {
  208.         IsMouseDown = false;
  209.         Invalidate();
  210.     }
  211.  
  212. }
  213.  
  214. class NSProgressBar : Control
  215. {
  216.  
  217.     private int _Minimum;
  218.     public int Minimum
  219.     {
  220.         get { return _Minimum; }
  221.         set
  222.         {
  223.             if (value < 0)
  224.             {
  225.                 throw new Exception("Property value is not valid.");
  226.             }
  227.  
  228.             _Minimum = value;
  229.             if (value > _Value)
  230.                 _Value = value;
  231.             if (value > _Maximum)
  232.                 _Maximum = value;
  233.             Invalidate();
  234.         }
  235.     }
  236.  
  237.     private int _Maximum = 100;
  238.     public int Maximum
  239.     {
  240.         get { return _Maximum; }
  241.         set
  242.         {
  243.             if (value < 0)
  244.             {
  245.                 throw new Exception("Property value is not valid.");
  246.             }
  247.  
  248.             _Maximum = value;
  249.             if (value < _Value)
  250.                 _Value = value;
  251.             if (value < _Minimum)
  252.                 _Minimum = value;
  253.             Invalidate();
  254.         }
  255.     }
  256.  
  257.     private int _Value;
  258.     public int Value
  259.     {
  260.         get { return _Value; }
  261.         set
  262.         {
  263.             if (value > _Maximum || value < _Minimum)
  264.             {
  265.                 throw new Exception("Property value is not valid.");
  266.             }
  267.  
  268.             _Value = value;
  269.             Invalidate();
  270.         }
  271.     }
  272.  
  273.     private void Increment(int amount)
  274.     {
  275.         Value += amount;
  276.     }
  277.  
  278.     public NSProgressBar()
  279.     {
  280.         SetStyle((ControlStyles)139286, true);
  281.         SetStyle(ControlStyles.Selectable, false);
  282.  
  283.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  284.         P2 = new Pen(Color.FromArgb(55, 55, 55));
  285.         B1 = new SolidBrush(Color.FromArgb(200, 160, 0));
  286.     }
  287.  
  288.     private GraphicsPath GP1;
  289.     private GraphicsPath GP2;
  290.  
  291.     private GraphicsPath GP3;
  292.     private Rectangle R1;
  293.  
  294.     private Rectangle R2;
  295.     private Pen P1;
  296.     private Pen P2;
  297.     private SolidBrush B1;
  298.     private LinearGradientBrush GB1;
  299.  
  300.     private LinearGradientBrush GB2;
  301.  
  302.     private int I1;
  303.     private Graphics G;
  304.  
  305.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  306.     {
  307.         G = e.Graphics;
  308.  
  309.         G.Clear(BackColor);
  310.         G.SmoothingMode = SmoothingMode.AntiAlias;
  311.  
  312.         GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  313.         GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  314.  
  315.         R1 = new Rectangle(0, 2, Width - 1, Height - 1);
  316.         GB1 = new LinearGradientBrush(R1, Color.FromArgb(45, 45, 45), Color.FromArgb(50, 50, 50), 90f);
  317.  
  318.         G.SetClip(GP1);
  319.         G.FillRectangle(GB1, R1);
  320.  
  321.         I1 = Convert.ToInt32((_Value - _Minimum) / (_Maximum - _Minimum) * (Width - 3));
  322.  
  323.         if (I1 > 1)
  324.         {
  325.             GP3 = ThemeModule.CreateRound(1, 1, I1, Height - 3, 7);
  326.  
  327.             R2 = new Rectangle(1, 1, I1, Height - 3);
  328.             GB2 = new LinearGradientBrush(R2, Color.FromArgb(52, 152, 219), Color.FromArgb(150, 110, 0), 90f);
  329.  
  330.             G.FillPath(GB2, GP3);
  331.             G.DrawPath(P1, GP3);
  332.  
  333.             G.SetClip(GP3);
  334.             G.SmoothingMode = SmoothingMode.None;
  335.  
  336.             G.FillRectangle(B1, R2.X, R2.Y + 1, R2.Width, R2.Height / 2);
  337.  
  338.             G.SmoothingMode = SmoothingMode.AntiAlias;
  339.             G.ResetClip();
  340.         }
  341.  
  342.         G.DrawPath(P2, GP1);
  343.         G.DrawPath(P1, GP2);
  344.     }
  345.  
  346. }
  347.  
  348. class NSLabel : Control
  349. {
  350.  
  351.     public NSLabel()
  352.     {
  353.         SetStyle((ControlStyles)139286, true);
  354.         SetStyle(ControlStyles.Selectable, false);
  355.  
  356.         Font = new Font("Segoe UI", 11.25f, FontStyle.Bold);
  357.  
  358.         B1 = new SolidBrush(Color.FromArgb(52, 152, 219));
  359.     }
  360.  
  361.     private string _Value1 = "NET";
  362.     public string Value1
  363.     {
  364.         get { return _Value1; }
  365.         set
  366.         {
  367.             _Value1 = value;
  368.             Invalidate();
  369.         }
  370.     }
  371.  
  372.     private string _Value2 = "SEAL";
  373.     public string Value2
  374.     {
  375.         get { return _Value2; }
  376.         set
  377.         {
  378.             _Value2 = value;
  379.             Invalidate();
  380.         }
  381.     }
  382.  
  383.  
  384.     private SolidBrush B1;
  385.     private PointF PT1;
  386.     private PointF PT2;
  387.     private SizeF SZ1;
  388.  
  389.     private SizeF SZ2;
  390.     private Graphics G;
  391.  
  392.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  393.     {
  394.         G = e.Graphics;
  395.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  396.  
  397.         G.Clear(BackColor);
  398.  
  399.         SZ1 = G.MeasureString(Value1, Font, Width, StringFormat.GenericTypographic);
  400.         SZ2 = G.MeasureString(Value2, Font, Width, StringFormat.GenericTypographic);
  401.  
  402.         PT1 = new PointF(0, Height / 2 - SZ1.Height / 2);
  403.         PT2 = new PointF(SZ1.Width + 1, Height / 2 - SZ1.Height / 2);
  404.  
  405.         G.DrawString(Value1, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  406.         G.DrawString(Value1, Font, Brushes.White, PT1);
  407.  
  408.         G.DrawString(Value2, Font, Brushes.Black, PT2.X + 1, PT2.Y + 1);
  409.         G.DrawString(Value2, Font, B1, PT2);
  410.     }
  411.  
  412. }
  413.  
  414. [DefaultEvent("TextChanged")]
  415. class NSTextBox : Control
  416. {
  417.  
  418.     private HorizontalAlignment _TextAlign = HorizontalAlignment.Left;
  419.  
  420.     public delegate void OnMouseUpFix(object sender, MouseEventArgs e);
  421.     public event OnMouseUpFix MouseUpFix;
  422.  
  423.     public HorizontalAlignment TextAlign
  424.     {
  425.         get { return _TextAlign; }
  426.         set
  427.         {
  428.             _TextAlign = value;
  429.             if (Base != null)
  430.             {
  431.                 Base.TextAlign = value;
  432.             }
  433.         }
  434.     }
  435.  
  436.     private int _MaxLength = 32767;
  437.     public int MaxLength
  438.     {
  439.         get { return _MaxLength; }
  440.         set
  441.         {
  442.             _MaxLength = value;
  443.             if (Base != null)
  444.             {
  445.                 Base.MaxLength = value;
  446.             }
  447.         }
  448.     }
  449.  
  450.     public bool AutoScroll { get; set; }
  451.  
  452.     public bool NumbersOnly { get; set; }
  453.  
  454.     public Point NumberBounds { get; set; }
  455.  
  456.     private bool _ReadOnly;
  457.     public bool ReadOnly
  458.     {
  459.         get { return _ReadOnly; }
  460.         set
  461.         {
  462.             _ReadOnly = value;
  463.             if (Base != null)
  464.             {
  465.                 Base.ReadOnly = value;
  466.             }
  467.         }
  468.     }
  469.  
  470.     private bool _UseSystemPasswordChar;
  471.     public bool UseSystemPasswordChar
  472.     {
  473.         get { return _UseSystemPasswordChar; }
  474.         set
  475.         {
  476.             _UseSystemPasswordChar = value;
  477.             if (Base != null)
  478.             {
  479.                 Base.UseSystemPasswordChar = value;
  480.             }
  481.         }
  482.     }
  483.  
  484.     private bool _Multiline;
  485.     public bool Multiline
  486.     {
  487.         get { return _Multiline; }
  488.         set
  489.         {
  490.             _Multiline = value;
  491.             if (Base != null)
  492.             {
  493.                 Base.Multiline = value;
  494.  
  495.                 if (value)
  496.                 {
  497.                     Base.Height = Height - 11;
  498.                 }
  499.                 else
  500.                 {
  501.                     Height = Base.Height + 11;
  502.                 }
  503.             }
  504.         }
  505.     }
  506.  
  507.     public override string Text
  508.     {
  509.         get { return base.Text; }
  510.         set
  511.         {
  512.             base.Text = value;
  513.             if (Base != null)
  514.             {
  515.                 Base.Text = value;
  516.             }
  517.         }
  518.     }
  519.  
  520.     public override Font Font
  521.     {
  522.         get { return base.Font; }
  523.         set
  524.         {
  525.             base.Font = value;
  526.             if (Base != null)
  527.             {
  528.                 Base.Font = value;
  529.                 Base.Location = new Point(5, 5);
  530.                 Base.Width = Width - 8;
  531.  
  532.                 if (!_Multiline)
  533.                 {
  534.                     Height = Base.Height + 11;
  535.                 }
  536.             }
  537.         }
  538.     }
  539.  
  540.     protected override void OnHandleCreated(EventArgs e)
  541.     {
  542.         if (!Controls.Contains(Base))
  543.         {
  544.             Controls.Add(Base);
  545.         }
  546.  
  547.         base.OnHandleCreated(e);
  548.     }
  549.  
  550.     private TextBox Base;
  551.     public NSTextBox()
  552.     {
  553.         SetStyle((ControlStyles)139286, true);
  554.         SetStyle(ControlStyles.Selectable, true);
  555.  
  556.         Cursor = Cursors.IBeam;
  557.  
  558.         Base = new TextBox();
  559.         Base.Font = Font;
  560.         Base.Text = Text;
  561.         Base.MaxLength = _MaxLength;
  562.         Base.Multiline = _Multiline;
  563.         Base.ReadOnly = _ReadOnly;
  564.         Base.ContextMenu = new ContextMenu();
  565.         Base.UseSystemPasswordChar = _UseSystemPasswordChar;
  566.  
  567.         Base.ForeColor = Color.White;
  568.         Base.BackColor = Color.FromArgb(50, 50, 50);
  569.  
  570.         Base.BorderStyle = BorderStyle.None;
  571.  
  572.         Base.Location = new Point(5, 5);
  573.         Base.Width = Width - 14;
  574.  
  575.         if (_Multiline)
  576.         {
  577.             Base.Height = Height - 11;
  578.         }
  579.         else
  580.         {
  581.             Height = Base.Height + 11;
  582.         }
  583.  
  584.         Base.TextChanged += OnBaseTextChanged;
  585.         Base.KeyDown += OnBaseKeyDown;
  586.         Base.MouseUp += Base_MouseUp;
  587.  
  588.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  589.         P2 = new Pen(Color.FromArgb(55, 55, 55));
  590.     }
  591.  
  592.     public void scrollToEnd()
  593.     {
  594.         Base.SelectionStart = Base.Text.Length;
  595.         Base.ScrollToCaret();
  596.     }
  597.  
  598.     void Base_MouseUp(object sender, MouseEventArgs e)
  599.     {
  600.         if (MouseUpFix != null)
  601.             MouseUpFix(sender, e);
  602.     }
  603.  
  604.     private GraphicsPath GP1;
  605.  
  606.     private GraphicsPath GP2;
  607.     private Pen P1;
  608.     private Pen P2;
  609.  
  610.     private PathGradientBrush PB1;
  611.     private Graphics G;
  612.  
  613.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  614.     {
  615.         G = e.Graphics;
  616.  
  617.         G.Clear(BackColor);
  618.         G.SmoothingMode = SmoothingMode.AntiAlias;
  619.  
  620.         GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  621.         GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  622.  
  623.         PB1 = new PathGradientBrush(GP1);
  624.         PB1.CenterColor = Color.FromArgb(50, 50, 50);
  625.         PB1.SurroundColors = new Color[] { Color.FromArgb(45, 45, 45) };
  626.         PB1.FocusScales = new PointF(0.9f, 0.5f);
  627.  
  628.         G.FillPath(PB1, GP1);
  629.  
  630.         G.DrawPath(P2, GP1);
  631.         G.DrawPath(P1, GP2);
  632.     }
  633.  
  634.     // Crude hack
  635.     private bool fired = false;
  636.  
  637.     private void OnBaseTextChanged(object s, EventArgs e)
  638.     {
  639.         if (AutoScroll && Base.Multiline)
  640.             scrollToEnd();
  641.  
  642.         if (fired)
  643.         {
  644.             fired = false;
  645.             return;
  646.         }
  647.  
  648.         int n;
  649.  
  650.         if (NumbersOnly && Base.Text != "" && (!int.TryParse(Base.Text, out n) || n < NumberBounds.X || n > NumberBounds.Y))
  651.         {
  652.             int selectionStart = Base.SelectionStart - 1;
  653.             fired = true;
  654.             Base.Text = Base.Text.Remove(selectionStart, 1);
  655.             Base.SelectionStart = selectionStart;
  656.         }
  657.  
  658.         Text = Base.Text;
  659.     }
  660.  
  661.     private void OnBaseKeyDown(object s, KeyEventArgs e)
  662.     {
  663.         if (e.Control && e.KeyCode == Keys.A)
  664.         {
  665.             Base.SelectAll();
  666.             e.SuppressKeyPress = true;
  667.         }
  668.     }
  669.  
  670.     protected override void OnResize(EventArgs e)
  671.     {
  672.         Base.Location = new Point(5, 5);
  673.  
  674.         Base.Width = Width - 10;
  675.         Base.Height = Height - 11;
  676.  
  677.         base.OnResize(e);
  678.     }
  679.  
  680.     protected override void OnMouseDown(MouseEventArgs e)
  681.     {
  682.         Base.Focus();
  683.         base.OnMouseDown(e);
  684.     }
  685.  
  686.     protected override void OnEnter(EventArgs e)
  687.     {
  688.         Base.Focus();
  689.         Invalidate();
  690.         base.OnEnter(e);
  691.     }
  692.  
  693.     protected override void OnLeave(EventArgs e)
  694.     {
  695.         Invalidate();
  696.         base.OnLeave(e);
  697.     }
  698.  
  699. }
  700.  
  701.  
  702. [DefaultEvent("CheckedChanged")]
  703. class NSCheckBox : Control
  704. {
  705.  
  706.     public event CheckedChangedEventHandler CheckedChanged;
  707.     public delegate void CheckedChangedEventHandler(object sender);
  708.  
  709.     public NSCheckBox()
  710.     {
  711.         SetStyle((ControlStyles)139286, true);
  712.         SetStyle(ControlStyles.Selectable, false);
  713.  
  714.         P11 = new Pen(Color.FromArgb(55, 55, 55));
  715.         P22 = new Pen(Color.FromArgb(35, 35, 35));
  716.         P3 = new Pen(Color.Black, 2f);
  717.         P4 = new Pen(Color.White, 2f);
  718.     }
  719.  
  720.     private bool _Checked;
  721.     public bool Checked
  722.     {
  723.         get { return _Checked; }
  724.         set
  725.         {
  726.             _Checked = value;
  727.             if (CheckedChanged != null)
  728.             {
  729.                 CheckedChanged(this);
  730.             }
  731.  
  732.             Invalidate();
  733.         }
  734.     }
  735.  
  736.     private GraphicsPath GP1;
  737.  
  738.     private GraphicsPath GP2;
  739.     private SizeF SZ1;
  740.  
  741.     private PointF PT1;
  742.     private Pen P11;
  743.     private Pen P22;
  744.     private Pen P3;
  745.  
  746.     private Pen P4;
  747.  
  748.     private PathGradientBrush PB1;
  749.     private Graphics G;
  750.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  751.     {
  752.         G = e.Graphics;
  753.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  754.  
  755.         G.Clear(BackColor);
  756.         G.SmoothingMode = SmoothingMode.AntiAlias;
  757.  
  758.         GP1 = ThemeModule.CreateRound(0, 2, Height - 5, Height - 5, 5);
  759.         GP2 = ThemeModule.CreateRound(1, 3, Height - 7, Height - 7, 5);
  760.  
  761.         PB1 = new PathGradientBrush(GP1);
  762.         PB1.CenterColor = Color.FromArgb(50, 50, 50);
  763.         PB1.SurroundColors =new Color[] { Color.FromArgb(45, 45, 45) };
  764.         PB1.FocusScales = new PointF(0.3f, 0.3f);
  765.  
  766.         G.FillPath(PB1, GP1);
  767.         G.DrawPath(P11, GP1);
  768.         G.DrawPath(P22, GP2);
  769.  
  770.         if (_Checked) {
  771.             G.DrawLine(P3, 5, Height - 9, 8, Height - 7);
  772.             G.DrawLine(P3, 7, Height - 7, Height - 8, 7);
  773.  
  774.             G.DrawLine(P4, 4, Height - 10, 7, Height - 8);
  775.             G.DrawLine(P4, 6, Height - 8, Height - 9, 6);
  776.         }
  777.  
  778.         SZ1 = G.MeasureString(Text, Font);
  779.         PT1 = new PointF(Height - 3, Height / 2 - SZ1.Height / 2);
  780.  
  781.         G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  782.         G.DrawString(Text, Font, Brushes.White, PT1);
  783.     }
  784.  
  785.     protected override void OnMouseDown(MouseEventArgs e)
  786.     {
  787.         Checked = !Checked;
  788.     }
  789.  
  790. }
  791.  
  792. [DefaultEvent("CheckedChanged")]
  793. class NSRadioButton : Control
  794. {
  795.  
  796.     public event CheckedChangedEventHandler CheckedChanged;
  797.     public delegate void CheckedChangedEventHandler(object sender);
  798.  
  799.     public NSRadioButton()
  800.     {
  801.         SetStyle((ControlStyles)139286, true);
  802.         SetStyle(ControlStyles.Selectable, false);
  803.  
  804.         P1 = new Pen(Color.FromArgb(55, 55, 55));
  805.         P2 = new Pen(Color.FromArgb(35, 35, 35));
  806.     }
  807.  
  808.     private bool _Checked;
  809.     public bool Checked
  810.     {
  811.         get { return _Checked; }
  812.         set
  813.         {
  814.             _Checked = value;
  815.  
  816.             if (_Checked)
  817.             {
  818.                 InvalidateParent();
  819.             }
  820.  
  821.             if (CheckedChanged != null)
  822.             {
  823.                 CheckedChanged(this);
  824.             }
  825.             Invalidate();
  826.         }
  827.     }
  828.  
  829.     private void InvalidateParent()
  830.     {
  831.         if (Parent == null)
  832.             return;
  833.  
  834.         foreach (Control C in Parent.Controls)
  835.         {
  836.             if ((!object.ReferenceEquals(C, this)) && (C is NSRadioButton))
  837.             {
  838.                 ((NSRadioButton)C).Checked = false;
  839.             }
  840.         }
  841.     }
  842.  
  843.  
  844.     private GraphicsPath GP1;
  845.     private SizeF SZ1;
  846.  
  847.     private PointF PT1;
  848.     private Pen P1;
  849.  
  850.     private Pen P2;
  851.  
  852.     private PathGradientBrush PB1;
  853.     private Graphics G;
  854.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  855.     {
  856.         G = e.Graphics;
  857.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  858.  
  859.         G.Clear(BackColor);
  860.         G.SmoothingMode = SmoothingMode.AntiAlias;
  861.  
  862.         GP1 = new GraphicsPath();
  863.         GP1.AddEllipse(0, 2, Height - 5, Height - 5);
  864.  
  865.         PB1 = new PathGradientBrush(GP1);
  866.         PB1.CenterColor = Color.FromArgb(50, 50, 50);
  867.         PB1.SurroundColors = new Color[]{ Color.FromArgb(45, 45, 45) };
  868.         PB1.FocusScales = new PointF(0.3f, 0.3f);
  869.  
  870.         G.FillPath(PB1, GP1);
  871.  
  872.         G.DrawEllipse(P1, 0, 2, Height - 5, Height - 5);
  873.         G.DrawEllipse(P2, 1, 3, Height - 7, Height - 7);
  874.  
  875.         if (_Checked) {
  876.             G.FillEllipse(Brushes.Black, 6, 8, Height - 15, Height - 15);
  877.             G.FillEllipse(Brushes.White, 5, 7, Height - 15, Height - 15);
  878.         }
  879.  
  880.         SZ1 = G.MeasureString(Text, Font);
  881.         PT1 = new PointF(Height - 3, Height / 2 - SZ1.Height / 2);
  882.  
  883.         G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  884.         G.DrawString(Text, Font, Brushes.White, PT1);
  885.     }
  886.  
  887.     protected override void OnMouseDown(MouseEventArgs e)
  888.     {
  889.         Checked = true;
  890.         base.OnMouseDown(e);
  891.     }
  892.  
  893. }
  894.  
  895. class NSComboBox : ComboBox
  896. {
  897.  
  898.     public NSComboBox()
  899.     {
  900.         SetStyle((ControlStyles)139286, true);
  901.         SetStyle(ControlStyles.Selectable, false);
  902.  
  903.         DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
  904.         DropDownStyle = ComboBoxStyle.DropDownList;
  905.  
  906.         BackColor = Color.FromArgb(50, 50, 50);
  907.         ForeColor = Color.White;
  908.  
  909.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  910.         P2 = new Pen(Color.White, 2f);
  911.         P3 = new Pen(Brushes.Black, 2f);
  912.         P4 = new Pen(Color.FromArgb(65, 65, 65));
  913.  
  914.         B1 = new SolidBrush(Color.FromArgb(65, 65, 65));
  915.         B2 = new SolidBrush(Color.FromArgb(55, 55, 55));
  916.     }
  917.  
  918.     private GraphicsPath GP1;
  919.  
  920.     private GraphicsPath GP2;
  921.     private SizeF SZ1;
  922.  
  923.     private PointF PT1;
  924.     private Pen P1;
  925.     private Pen P2;
  926.     private Pen P3;
  927.     private Pen P4;
  928.     private SolidBrush B1;
  929.  
  930.     private SolidBrush B2;
  931.  
  932.     private LinearGradientBrush GB1;
  933.     private Graphics G;
  934.     protected override void OnPaint(PaintEventArgs e)
  935.     {
  936.         G = e.Graphics;
  937.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  938.  
  939.         G.Clear(BackColor);
  940.         G.SmoothingMode = SmoothingMode.AntiAlias;
  941.  
  942.         GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  943.         GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  944.  
  945.         GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  946.         G.SetClip(GP1);
  947.         G.FillRectangle(GB1, ClientRectangle);
  948.         G.ResetClip();
  949.  
  950.         G.DrawPath(P1, GP1);
  951.         G.DrawPath(P4, GP2);
  952.  
  953.         SZ1 = G.MeasureString(Text, Font);
  954.         PT1 = new PointF(5, Height / 2 - SZ1.Height / 2);
  955.  
  956.         G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  957.         G.DrawString(Text, Font, Brushes.White, PT1);
  958.  
  959.         G.DrawLine(P3, Width - 15, 10, Width - 11, 13);
  960.         G.DrawLine(P3, Width - 7, 10, Width - 11, 13);
  961.         G.DrawLine(Pens.Black, Width - 11, 13, Width - 11, 14);
  962.  
  963.         G.DrawLine(P2, Width - 16, 9, Width - 12, 12);
  964.         G.DrawLine(P2, Width - 8, 9, Width - 12, 12);
  965.         G.DrawLine(Pens.White, Width - 12, 12, Width - 12, 13);
  966.  
  967.         G.DrawLine(P1, Width - 22, 0, Width - 22, Height);
  968.         G.DrawLine(P4, Width - 23, 1, Width - 23, Height - 2);
  969.         G.DrawLine(P4, Width - 21, 1, Width - 21, Height - 2);
  970.     }
  971.  
  972.     protected override void OnDrawItem(DrawItemEventArgs e)
  973.     {
  974.         e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  975.  
  976.         if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
  977.         {
  978.             e.Graphics.FillRectangle(B1, e.Bounds);
  979.         }
  980.         else
  981.         {
  982.             e.Graphics.FillRectangle(B2, e.Bounds);
  983.         }
  984.  
  985.         if (!(e.Index == -1))
  986.         {
  987.             e.Graphics.DrawString(GetItemText(Items[e.Index]), e.Font, Brushes.White, e.Bounds);
  988.         }
  989.     }
  990.  
  991. }
  992.  
  993. class NSTabControl : TabControl
  994. {
  995.  
  996.     public NSTabControl()
  997.     {
  998.         SetStyle((ControlStyles)139286, true);
  999.         SetStyle(ControlStyles.Selectable, false);
  1000.  
  1001.         SizeMode = TabSizeMode.Fixed;
  1002.         Alignment = TabAlignment.Left;
  1003.         ItemSize = new Size(28, 115);
  1004.  
  1005.         DrawMode = TabDrawMode.OwnerDrawFixed;
  1006.  
  1007.         P1 = new Pen(Color.FromArgb(55, 55, 55));
  1008.         P2 = new Pen(Color.FromArgb(35, 35, 35));
  1009.         P3 = new Pen(Color.FromArgb(45, 45, 45), 2);
  1010.  
  1011.         B1 = new SolidBrush(Color.FromArgb(50, 50, 50));
  1012.         B2 = new SolidBrush(Color.FromArgb(35, 35, 35));
  1013.         B3 = new SolidBrush(Color.FromArgb(52, 152, 219));
  1014.         B4 = new SolidBrush(Color.FromArgb(65, 65, 65));
  1015.  
  1016.         SF1 = new StringFormat();
  1017.         SF1.LineAlignment = StringAlignment.Center;
  1018.     }
  1019.  
  1020.     protected override void OnControlAdded(ControlEventArgs e)
  1021.     {
  1022.         if (e.Control is TabPage)
  1023.         {
  1024.             e.Control.BackColor = Color.FromArgb(50, 50, 50);
  1025.         }
  1026.  
  1027.         base.OnControlAdded(e);
  1028.     }
  1029.  
  1030.     private GraphicsPath GP1;
  1031.     private GraphicsPath GP2;
  1032.     private GraphicsPath GP3;
  1033.  
  1034.     private GraphicsPath GP4;
  1035.     private Rectangle R1;
  1036.  
  1037.     private Rectangle R2;
  1038.     private Pen P1;
  1039.     private Pen P2;
  1040.     private Pen P3;
  1041.     private SolidBrush B1;
  1042.     private SolidBrush B2;
  1043.     private SolidBrush B3;
  1044.  
  1045.     private SolidBrush B4;
  1046.  
  1047.     private PathGradientBrush PB1;
  1048.     private TabPage TP1;
  1049.  
  1050.     private StringFormat SF1;
  1051.     private int Offset;
  1052.  
  1053.     private int ItemHeight;
  1054.     private Graphics G;
  1055.  
  1056.     protected override void OnPaint(PaintEventArgs e)
  1057.     {
  1058.         G = e.Graphics;
  1059.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  1060.  
  1061.         G.Clear(Color.FromArgb(50, 50, 50));
  1062.         G.SmoothingMode = SmoothingMode.AntiAlias;
  1063.  
  1064.         ItemHeight = ItemSize.Height + 2;
  1065.  
  1066.         GP1 = ThemeModule.CreateRound(0, 0, ItemHeight + 3, Height - 1, 7);
  1067.         GP2 = ThemeModule.CreateRound(1, 1, ItemHeight + 3, Height - 3, 7);
  1068.  
  1069.         PB1 = new PathGradientBrush(GP1);
  1070.         PB1.CenterColor = Color.FromArgb(50, 50, 50);
  1071.         PB1.SurroundColors = new Color[] { Color.FromArgb(45, 45, 45) };
  1072.         PB1.FocusScales = new PointF(0.8f, 0.95f);
  1073.  
  1074.         G.FillPath(PB1, GP1);
  1075.  
  1076.         G.DrawPath(P1, GP1);
  1077.         G.DrawPath(P2, GP2);
  1078.  
  1079.         for (int I = 0; I <= TabCount - 1; I++) {
  1080.             R1 = GetTabRect(I);
  1081.             R1.Y += 2;
  1082.             R1.Height -= 3;
  1083.             R1.Width += 1;
  1084.             R1.X -= 1;
  1085.  
  1086.             TP1 = TabPages[I];
  1087.             Offset = 0;
  1088.  
  1089.             if (SelectedIndex == I) {
  1090.                 G.FillRectangle(B1, R1);
  1091.  
  1092.                 for (int J = 0; J <= 1; J++) {
  1093.                     G.FillRectangle(B2, R1.X + 5 + (J * 5), R1.Y + 6, 2, R1.Height - 9);
  1094.  
  1095.                     G.SmoothingMode = SmoothingMode.None;
  1096.                     G.FillRectangle(B3, R1.X + 5 + (J * 5), R1.Y + 5, 2, R1.Height - 9);
  1097.                     G.SmoothingMode = SmoothingMode.AntiAlias;
  1098.  
  1099.                     Offset += 5;
  1100.                 }
  1101.  
  1102.                 G.DrawRectangle(P3, R1.X + 1, R1.Y - 1, R1.Width, R1.Height + 2);
  1103.                 G.DrawRectangle(P1, R1.X + 1, R1.Y + 1, R1.Width - 2, R1.Height - 2);
  1104.                 G.DrawRectangle(P2, R1);
  1105.             } else {
  1106.                 for (int J = 0; J <= 1; J++) {
  1107.                     G.FillRectangle(B2, R1.X + 5 + (J * 5), R1.Y + 6, 2, R1.Height - 9);
  1108.  
  1109.                     G.SmoothingMode = SmoothingMode.None;
  1110.                     G.FillRectangle(B4, R1.X + 5 + (J * 5), R1.Y + 5, 2, R1.Height - 9);
  1111.                     G.SmoothingMode = SmoothingMode.AntiAlias;
  1112.  
  1113.                     Offset += 5;
  1114.                 }
  1115.             }
  1116.  
  1117.             R1.X += 5 + Offset;
  1118.  
  1119.             R2 = R1;
  1120.             R2.Y += 1;
  1121.             R2.X += 1;
  1122.  
  1123.             G.DrawString(TP1.Text, Font, Brushes.Black, R2, SF1);
  1124.             G.DrawString(TP1.Text, Font, Brushes.White, R1, SF1);
  1125.         }
  1126.  
  1127.         GP3 = ThemeModule.CreateRound(ItemHeight, 0, Width - ItemHeight - 1, Height - 1, 7);
  1128.         GP4 = ThemeModule.CreateRound(ItemHeight + 1, 1, Width - ItemHeight - 3, Height - 3, 7);
  1129.  
  1130.         G.DrawPath(P2, GP3);
  1131.         G.DrawPath(P1, GP4);
  1132.     }
  1133.  
  1134. }
  1135.  
  1136. [DefaultEvent("CheckedChanged")]
  1137. class NSOnOffBox : Control
  1138. {
  1139.  
  1140.     public event CheckedChangedEventHandler CheckedChanged;
  1141.     public delegate void CheckedChangedEventHandler(object sender);
  1142.  
  1143.     public NSOnOffBox()
  1144.     {
  1145.         SetStyle((ControlStyles)139286, true);
  1146.         SetStyle(ControlStyles.Selectable, false);
  1147.  
  1148.         P1 = new Pen(Color.FromArgb(55, 55, 55));
  1149.         P2 = new Pen(Color.FromArgb(35, 35, 35));
  1150.         P3 = new Pen(Color.FromArgb(65, 65, 65));
  1151.  
  1152.         B1 = new SolidBrush(Color.FromArgb(35, 35, 35));
  1153.         B2 = new SolidBrush(Color.FromArgb(85, 85, 85));
  1154.         B3 = new SolidBrush(Color.FromArgb(65, 65, 65));
  1155.         B4 = new SolidBrush(Color.FromArgb(52, 152, 219));
  1156.         B5 = new SolidBrush(Color.FromArgb(40, 40, 40));
  1157.  
  1158.         SF1 = new StringFormat();
  1159.         SF1.LineAlignment = StringAlignment.Center;
  1160.         SF1.Alignment = StringAlignment.Near;
  1161.  
  1162.         SF2 = new StringFormat();
  1163.         SF2.LineAlignment = StringAlignment.Center;
  1164.         SF2.Alignment = StringAlignment.Far;
  1165.  
  1166.         Size = new Size(56, 24);
  1167.         MinimumSize = Size;
  1168.         MaximumSize = Size;
  1169.     }
  1170.  
  1171.     private bool _Checked;
  1172.     public bool Checked
  1173.     {
  1174.         get { return _Checked; }
  1175.         set
  1176.         {
  1177.             _Checked = value;
  1178.             if (CheckedChanged != null)
  1179.             {
  1180.                 CheckedChanged(this);
  1181.             }
  1182.  
  1183.             Invalidate();
  1184.         }
  1185.     }
  1186.  
  1187.     private GraphicsPath GP1;
  1188.     private GraphicsPath GP2;
  1189.     private GraphicsPath GP3;
  1190.  
  1191.     private GraphicsPath GP4;
  1192.     private Pen P1;
  1193.     private Pen P2;
  1194.     private Pen P3;
  1195.     private SolidBrush B1;
  1196.     private SolidBrush B2;
  1197.     private SolidBrush B3;
  1198.     private SolidBrush B4;
  1199.  
  1200.     private SolidBrush B5;
  1201.     private PathGradientBrush PB1;
  1202.  
  1203.     private LinearGradientBrush GB1;
  1204.     private Rectangle R1;
  1205.     private Rectangle R2;
  1206.     private Rectangle R3;
  1207.     private StringFormat SF1;
  1208.  
  1209.     private StringFormat SF2;
  1210.  
  1211.     private int Offset;
  1212.     private Graphics G;
  1213.  
  1214.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  1215.     {
  1216.         G = e.Graphics;
  1217.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  1218.  
  1219.         G.Clear(BackColor);
  1220.         G.SmoothingMode = SmoothingMode.AntiAlias;
  1221.  
  1222.         GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  1223.         GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  1224.  
  1225.         PB1 = new PathGradientBrush(GP1);
  1226.         PB1.CenterColor = Color.FromArgb(50, 50, 50);
  1227.         PB1.SurroundColors = new Color[]{ Color.FromArgb(45, 45, 45) };
  1228.         PB1.FocusScales = new PointF(0.3f, 0.3f);
  1229.  
  1230.         G.FillPath(PB1, GP1);
  1231.         G.DrawPath(P1, GP1);
  1232.         G.DrawPath(P2, GP2);
  1233.  
  1234.         R1 = new Rectangle(5, 0, Width - 10, Height + 2);
  1235.         R2 = new Rectangle(6, 1, Width - 10, Height + 2);
  1236.  
  1237.         R3 = new Rectangle(1, 1, (Width / 2) - 1, Height - 3);
  1238.  
  1239.         if (_Checked) {
  1240.             G.DrawString("On", Font, Brushes.Black, R2, SF1);
  1241.             G.DrawString("On", Font, Brushes.White, R1, SF1);
  1242.  
  1243.             R3.X += (Width / 2) - 1;
  1244.         } else {
  1245.             G.DrawString("Off", Font, B1, R2, SF2);
  1246.             G.DrawString("Off", Font, B2, R1, SF2);
  1247.         }
  1248.  
  1249.         GP3 = ThemeModule.CreateRound(R3, 7);
  1250.         GP4 = ThemeModule.CreateRound(R3.X + 1, R3.Y + 1, R3.Width - 2, R3.Height - 2, 7);
  1251.  
  1252.         GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  1253.  
  1254.         G.FillPath(GB1, GP3);
  1255.         G.DrawPath(P2, GP3);
  1256.         G.DrawPath(P3, GP4);
  1257.  
  1258.         Offset = R3.X + (R3.Width / 2) - 3;
  1259.  
  1260.         for (int I = 0; I <= 1; I++) {
  1261.             if (_Checked) {
  1262.                 G.FillRectangle(B1, Offset + (I * 5), 7, 2, Height - 14);
  1263.             } else {
  1264.                 G.FillRectangle(B3, Offset + (I * 5), 7, 2, Height - 14);
  1265.             }
  1266.  
  1267.             G.SmoothingMode = SmoothingMode.None;
  1268.  
  1269.             if (_Checked) {
  1270.                 G.FillRectangle(B4, Offset + (I * 5), 7, 2, Height - 14);
  1271.             } else {
  1272.                 G.FillRectangle(B5, Offset + (I * 5), 7, 2, Height - 14);
  1273.             }
  1274.  
  1275.             G.SmoothingMode = SmoothingMode.AntiAlias;
  1276.         }
  1277.     }
  1278.  
  1279.     protected override void OnMouseDown(MouseEventArgs e)
  1280.     {
  1281.         Checked = !Checked;
  1282.         base.OnMouseDown(e);
  1283.     }
  1284.  
  1285. }
  1286.  
  1287. class NSControlButton : Control
  1288. {
  1289.  
  1290.     public enum Button : byte
  1291.     {
  1292.         None = 0,
  1293.         Minimize = 1,
  1294.         MaximizeRestore = 2,
  1295.         Close = 3
  1296.     }
  1297.  
  1298.     private Button _ControlButton = Button.Close;
  1299.     public Button ControlButton
  1300.     {
  1301.         get { return _ControlButton; }
  1302.         set
  1303.         {
  1304.             _ControlButton = value;
  1305.             Invalidate();
  1306.         }
  1307.     }
  1308.  
  1309.     public NSControlButton()
  1310.     {
  1311.         SetStyle((ControlStyles)139286, true);
  1312.         SetStyle(ControlStyles.Selectable, false);
  1313.  
  1314.         Anchor = AnchorStyles.Top | AnchorStyles.Right;
  1315.  
  1316.         Width = 18;
  1317.         Height = 20;
  1318.  
  1319.         MinimumSize = Size;
  1320.         MaximumSize = Size;
  1321.  
  1322.         Margin = new Padding(0);
  1323.     }
  1324.  
  1325.     private Graphics G;
  1326.     protected override void OnPaint(PaintEventArgs e)
  1327.     {
  1328.         G = e.Graphics;
  1329.         G.Clear(BackColor);
  1330.  
  1331.         switch (_ControlButton)
  1332.         {
  1333.             case Button.Minimize:
  1334.                 DrawMinimize(3, 10);
  1335.                 break;
  1336.             case Button.MaximizeRestore:
  1337.                 if (FindForm().WindowState == FormWindowState.Normal)
  1338.                 {
  1339.                     DrawMaximize(3, 5);
  1340.                 }
  1341.                 else
  1342.                 {
  1343.                     DrawRestore(3, 4);
  1344.                 }
  1345.                 break;
  1346.             case Button.Close:
  1347.                 DrawClose(4, 5);
  1348.                 break;
  1349.         }
  1350.     }
  1351.  
  1352.     private void DrawMinimize(int x, int y)
  1353.     {
  1354.         G.FillRectangle(Brushes.White, x, y, 12, 5);
  1355.         G.DrawRectangle(Pens.Black, x, y, 11, 4);
  1356.     }
  1357.  
  1358.     private void DrawMaximize(int x, int y)
  1359.     {
  1360.         G.DrawRectangle(new Pen(Color.White, 2), x + 2, y + 2, 8, 6);
  1361.         G.DrawRectangle(Pens.Black, x, y, 11, 9);
  1362.         G.DrawRectangle(Pens.Black, x + 3, y + 3, 5, 3);
  1363.     }
  1364.  
  1365.     private void DrawRestore(int x, int y)
  1366.     {
  1367.         G.FillRectangle(Brushes.White, x + 3, y + 1, 8, 4);
  1368.         G.FillRectangle(Brushes.White, x + 7, y + 5, 4, 4);
  1369.         G.DrawRectangle(Pens.Black, x + 2, y + 0, 9, 9);
  1370.  
  1371.         G.FillRectangle(Brushes.White, x + 1, y + 3, 2, 6);
  1372.         G.FillRectangle(Brushes.White, x + 1, y + 9, 8, 2);
  1373.         G.DrawRectangle(Pens.Black, x, y + 2, 9, 9);
  1374.         G.DrawRectangle(Pens.Black, x + 3, y + 5, 3, 3);
  1375.     }
  1376.  
  1377.     private GraphicsPath ClosePath;
  1378.     private void DrawClose(int x, int y)
  1379.     {
  1380.         if (ClosePath == null)
  1381.         {
  1382.             ClosePath = new GraphicsPath();
  1383.             ClosePath.AddLine(x + 1, y, x + 3, y);
  1384.             ClosePath.AddLine(x + 5, y + 2, x + 7, y);
  1385.             ClosePath.AddLine(x + 9, y, x + 10, y + 1);
  1386.             ClosePath.AddLine(x + 7, y + 4, x + 7, y + 5);
  1387.             ClosePath.AddLine(x + 10, y + 8, x + 9, y + 9);
  1388.             ClosePath.AddLine(x + 7, y + 9, x + 5, y + 7);
  1389.             ClosePath.AddLine(x + 3, y + 9, x + 1, y + 9);
  1390.             ClosePath.AddLine(x + 0, y + 8, x + 3, y + 5);
  1391.             ClosePath.AddLine(x + 3, y + 4, x + 0, y + 1);
  1392.         }
  1393.  
  1394.         G.FillPath(Brushes.White, ClosePath);
  1395.         G.DrawPath(Pens.Black, ClosePath);
  1396.     }
  1397.  
  1398.     protected override void OnMouseClick(MouseEventArgs e)
  1399.     {
  1400.  
  1401.         if (e.Button == System.Windows.Forms.MouseButtons.Left)
  1402.         {
  1403.             Form F = FindForm();
  1404.  
  1405.             switch (_ControlButton)
  1406.             {
  1407.                 case Button.Minimize:
  1408.                     F.WindowState = FormWindowState.Minimized;
  1409.                     break;
  1410.                 case Button.MaximizeRestore:
  1411.                     if (F.WindowState == FormWindowState.Normal)
  1412.                     {
  1413.                         F.WindowState = FormWindowState.Maximized;
  1414.                     }
  1415.                     else
  1416.                     {
  1417.                         F.WindowState = FormWindowState.Normal;
  1418.                     }
  1419.                     break;
  1420.                 case Button.Close:
  1421.                     F.Close();
  1422.                     break;
  1423.             }
  1424.  
  1425.         }
  1426.  
  1427.         Invalidate();
  1428.         base.OnMouseClick(e);
  1429.     }
  1430.  
  1431. }
  1432.  
  1433. class NSGroupBox : ContainerControl
  1434. {
  1435.  
  1436.     private bool _DrawSeperator;
  1437.     public bool DrawSeperator
  1438.     {
  1439.         get { return _DrawSeperator; }
  1440.         set
  1441.         {
  1442.             _DrawSeperator = value;
  1443.             Invalidate();
  1444.         }
  1445.     }
  1446.  
  1447.     private string _Title = "GroupBox";
  1448.     public string Title
  1449.     {
  1450.         get { return _Title; }
  1451.         set
  1452.         {
  1453.             _Title = value;
  1454.             Invalidate();
  1455.         }
  1456.     }
  1457.  
  1458.     private string _SubTitle = "Details";
  1459.     public string SubTitle
  1460.     {
  1461.         get { return _SubTitle; }
  1462.         set
  1463.         {
  1464.             _SubTitle = value;
  1465.             Invalidate();
  1466.         }
  1467.     }
  1468.  
  1469.     private Font _TitleFont;
  1470.  
  1471.     private Font _SubTitleFont;
  1472.     public NSGroupBox()
  1473.     {
  1474.         SetStyle((ControlStyles)139286, true);
  1475.         SetStyle(ControlStyles.Selectable, false);
  1476.  
  1477.         _TitleFont = new Font("Verdana", 10f);
  1478.         _SubTitleFont = new Font("Verdana", 6.5f);
  1479.  
  1480.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  1481.         P2 = new Pen(Color.FromArgb(55, 55, 55));
  1482.  
  1483.         B1 = new SolidBrush(Color.FromArgb(52, 152, 219));
  1484.     }
  1485.  
  1486.     private GraphicsPath GP1;
  1487.  
  1488.     private GraphicsPath GP2;
  1489.     private PointF PT1;
  1490.     private SizeF SZ1;
  1491.  
  1492.     private SizeF SZ2;
  1493.     private Pen P1;
  1494.     private Pen P2;
  1495.  
  1496.     private SolidBrush B1;
  1497.     private Graphics G;
  1498.  
  1499.     protected override void OnPaint(PaintEventArgs e)
  1500.     {
  1501.         G = e.Graphics;
  1502.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  1503.  
  1504.         G.Clear(BackColor);
  1505.         G.SmoothingMode = SmoothingMode.AntiAlias;
  1506.  
  1507.         GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  1508.         GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  1509.  
  1510.         G.DrawPath(P1, GP1);
  1511.         G.DrawPath(P2, GP2);
  1512.  
  1513.         SZ1 = G.MeasureString(_Title, _TitleFont, Width, StringFormat.GenericTypographic);
  1514.         SZ2 = G.MeasureString(_SubTitle, _SubTitleFont, Width, StringFormat.GenericTypographic);
  1515.  
  1516.         G.DrawString(_Title, _TitleFont, Brushes.Black, 6, 6);
  1517.         G.DrawString(_Title, _TitleFont, B1, 5, 5);
  1518.  
  1519.         PT1 = new PointF(6f, SZ1.Height + 4f);
  1520.  
  1521.         G.DrawString(_SubTitle, _SubTitleFont, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  1522.         G.DrawString(_SubTitle, _SubTitleFont, Brushes.White, PT1.X, PT1.Y);
  1523.  
  1524.         if (_DrawSeperator)
  1525.         {
  1526.             int Y = Convert.ToInt32(PT1.Y + SZ2.Height) + 8;
  1527.  
  1528.             G.DrawLine(P1, 4, Y, Width - 5, Y);
  1529.             G.DrawLine(P2, 4, Y + 1, Width - 5, Y + 1);
  1530.         }
  1531.     }
  1532.  
  1533. }
  1534.  
  1535. class NSSeperator : Control
  1536. {
  1537.  
  1538.     public NSSeperator()
  1539.     {
  1540.         SetStyle((ControlStyles)139286, true);
  1541.         SetStyle(ControlStyles.Selectable, false);
  1542.  
  1543.         Height = 10;
  1544.  
  1545.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  1546.         P2 = new Pen(Color.FromArgb(55, 55, 55));
  1547.     }
  1548.  
  1549.     private Pen P1;
  1550.  
  1551.     private Pen P2;
  1552.     private Graphics G;
  1553.  
  1554.     protected override void OnPaint(PaintEventArgs e)
  1555.     {
  1556.         G = e.Graphics;
  1557.         G.Clear(BackColor);
  1558.  
  1559.         G.DrawLine(P1, 0, 5, Width, 5);
  1560.         G.DrawLine(P2, 0, 6, Width, 6);
  1561.     }
  1562.  
  1563. }
  1564.  
  1565. [DefaultEvent("Scroll")]
  1566. class NSTrackBar : Control
  1567. {
  1568.  
  1569.     public event ScrollEventHandler Scroll;
  1570.     public delegate void ScrollEventHandler(object sender);
  1571.  
  1572.     private int _Minimum;
  1573.     public int Minimum
  1574.     {
  1575.         get { return _Minimum; }
  1576.         set
  1577.         {
  1578.             if (value < 0)
  1579.             {
  1580.                 throw new Exception("Property value is not valid.");
  1581.             }
  1582.  
  1583.             _Minimum = value;
  1584.             if (value > _Value)
  1585.                 _Value = value;
  1586.             if (value > _Maximum)
  1587.                 _Maximum = value;
  1588.             Invalidate();
  1589.         }
  1590.     }
  1591.  
  1592.     private int _Maximum = 10;
  1593.     public int Maximum
  1594.     {
  1595.         get { return _Maximum; }
  1596.         set
  1597.         {
  1598.             if (value < 0)
  1599.             {
  1600.                 throw new Exception("Property value is not valid.");
  1601.             }
  1602.  
  1603.             _Maximum = value;
  1604.             if (value < _Value)
  1605.                 _Value = value;
  1606.             if (value < _Minimum)
  1607.                 _Minimum = value;
  1608.             Invalidate();
  1609.         }
  1610.     }
  1611.  
  1612.     private int _Value;
  1613.     public int Value
  1614.     {
  1615.         get { return _Value; }
  1616.         set
  1617.         {
  1618.             if (value == _Value)
  1619.                 return;
  1620.  
  1621.             if (value > _Maximum || value < _Minimum)
  1622.             {
  1623.                 throw new Exception("Property value is not valid.");
  1624.             }
  1625.  
  1626.             _Value = value;
  1627.             Invalidate();
  1628.  
  1629.             if (Scroll != null)
  1630.             {
  1631.                 Scroll(this);
  1632.             }
  1633.         }
  1634.     }
  1635.  
  1636.     public NSTrackBar()
  1637.     {
  1638.         SetStyle((ControlStyles)139286, true);
  1639.         SetStyle(ControlStyles.Selectable, false);
  1640.  
  1641.         Height = 17;
  1642.  
  1643.         P1 = new Pen(Color.FromArgb(150, 110, 0), 2);
  1644.         P2 = new Pen(Color.FromArgb(55, 55, 55));
  1645.         P3 = new Pen(Color.FromArgb(35, 35, 35));
  1646.         P4 = new Pen(Color.FromArgb(65, 65, 65));
  1647.     }
  1648.  
  1649.     private GraphicsPath GP1;
  1650.     private GraphicsPath GP2;
  1651.     private GraphicsPath GP3;
  1652.  
  1653.     private GraphicsPath GP4;
  1654.     private Rectangle R1;
  1655.     private Rectangle R2;
  1656.     private Rectangle R3;
  1657.  
  1658.     private int I1;
  1659.     private Pen P1;
  1660.     private Pen P2;
  1661.     private Pen P3;
  1662.  
  1663.     private Pen P4;
  1664.     private LinearGradientBrush GB1;
  1665.     private LinearGradientBrush GB2;
  1666.  
  1667.     private LinearGradientBrush GB3;
  1668.     private Graphics G;
  1669.  
  1670.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  1671.     {
  1672.         G = e.Graphics;
  1673.  
  1674.         G.Clear(BackColor);
  1675.         G.SmoothingMode = SmoothingMode.AntiAlias;
  1676.  
  1677.         GP1 = ThemeModule.CreateRound(0, 5, Width - 1, 10, 5);
  1678.         GP2 = ThemeModule.CreateRound(1, 6, Width - 3, 8, 5);
  1679.  
  1680.         R1 = new Rectangle(0, 7, Width - 1, 5);
  1681.         GB1 = new LinearGradientBrush(R1, Color.FromArgb(45, 45, 45), Color.FromArgb(50, 50, 50), 90f);
  1682.  
  1683.         I1 = Convert.ToInt32((double)(_Value - _Minimum) / (double)(_Maximum - _Minimum) * (Width - 11));
  1684.         R2 = new Rectangle(I1, 0, 10, 20);
  1685.  
  1686.         G.SetClip(GP2);
  1687.         G.FillRectangle(GB1, R1);
  1688.  
  1689.         R3 = new Rectangle(1, 7, R2.X + R2.Width - 2, 8);
  1690.         GB2 = new LinearGradientBrush(R3, Color.FromArgb(52, 152, 219), Color.FromArgb(150, 110, 0), 90f);
  1691.  
  1692.         G.SmoothingMode = SmoothingMode.None;
  1693.         G.FillRectangle(GB2, R3);
  1694.         G.SmoothingMode = SmoothingMode.AntiAlias;
  1695.  
  1696.         for (int I = 0; I <= R3.Width - 15; I += 5)
  1697.         {
  1698.             G.DrawLine(P1, I, 0, I + 15, Height);
  1699.         }
  1700.  
  1701.         G.ResetClip();
  1702.  
  1703.         G.DrawPath(P2, GP1);
  1704.         G.DrawPath(P3, GP2);
  1705.  
  1706.         GP3 = ThemeModule.CreateRound(R2, 5);
  1707.         GP4 = ThemeModule.CreateRound(R2.X + 1, R2.Y + 1, R2.Width - 2, R2.Height - 2, 5);
  1708.         GB3 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  1709.  
  1710.         G.FillPath(GB3, GP3);
  1711.         G.DrawPath(P3, GP3);
  1712.         G.DrawPath(P4, GP4);
  1713.     }
  1714.  
  1715.     private bool TrackDown;
  1716.     protected override void OnMouseDown(MouseEventArgs e)
  1717.     {
  1718.         if (e.Button == System.Windows.Forms.MouseButtons.Left)
  1719.         {
  1720.             I1 = Convert.ToInt32((double)(_Value - _Minimum) / (double)(_Maximum - _Minimum) * (Width - 11));
  1721.             R2 = new Rectangle(I1, 0, 10, 20);
  1722.  
  1723.             TrackDown = R2.Contains(e.Location);
  1724.         }
  1725.  
  1726.         base.OnMouseDown(e);
  1727.     }
  1728.  
  1729.     protected override void OnMouseMove(MouseEventArgs e)
  1730.     {
  1731.         if (TrackDown && e.X > -1 && e.X < (Width + 1))
  1732.         {
  1733.             Value = _Minimum + Convert.ToInt32((_Maximum - _Minimum) * ((double)e.X / (double)Width));
  1734.         }
  1735.  
  1736.         base.OnMouseMove(e);
  1737.     }
  1738.  
  1739.     protected override void OnMouseUp(MouseEventArgs e)
  1740.     {
  1741.         TrackDown = false;
  1742.         base.OnMouseUp(e);
  1743.     }
  1744.  
  1745. }
  1746.  
  1747. [DefaultEvent("ValueChanged")]
  1748. class NSRandomPool : Control
  1749. {
  1750.  
  1751.     public event ValueChangedEventHandler ValueChanged;
  1752.     public delegate void ValueChangedEventHandler(object sender);
  1753.  
  1754.     private StringBuilder _Value = new StringBuilder();
  1755.     public string Value
  1756.     {
  1757.         get { return _Value.ToString(); }
  1758.     }
  1759.  
  1760.     public string FullValue
  1761.     {
  1762.         get { return BitConverter.ToString(Table).Replace("-", ""); }
  1763.     }
  1764.  
  1765.  
  1766.     private Random RNG = new Random();
  1767.     private int ItemSize = 9;
  1768.  
  1769.     private int DrawSize = 8;
  1770.  
  1771.     private Rectangle WA;
  1772.     private int RowSize;
  1773.  
  1774.     private int ColumnSize;
  1775.     public NSRandomPool()
  1776.     {
  1777.         SetStyle((ControlStyles)139286, true);
  1778.         SetStyle(ControlStyles.Selectable, false);
  1779.  
  1780.         P1 = new Pen(Color.FromArgb(55, 55, 55));
  1781.         P2 = new Pen(Color.FromArgb(35, 35, 35));
  1782.  
  1783.         B1 = new SolidBrush(Color.FromArgb(30, 30, 30));
  1784.     }
  1785.  
  1786.     protected override void OnHandleCreated(EventArgs e)
  1787.     {
  1788.         UpdateTable();
  1789.         base.OnHandleCreated(e);
  1790.     }
  1791.  
  1792.     private byte[] Table;
  1793.     private void UpdateTable()
  1794.     {
  1795.         WA = new Rectangle(5, 5, Width - 10, Height - 10);
  1796.  
  1797.         RowSize = WA.Width / ItemSize;
  1798.         ColumnSize = WA.Height / ItemSize;
  1799.  
  1800.         WA.Width = RowSize * ItemSize;
  1801.         WA.Height = ColumnSize * ItemSize;
  1802.  
  1803.         WA.X = (Width / 2) - (WA.Width / 2);
  1804.         WA.Y = (Height / 2) - (WA.Height / 2);
  1805.  
  1806.         Table = new byte[(RowSize * ColumnSize)];
  1807.  
  1808.         for (int I = 0; I <= Table.Length - 1; I++)
  1809.         {
  1810.             Table[I] = Convert.ToByte(RNG.Next(100));
  1811.         }
  1812.  
  1813.         Invalidate();
  1814.     }
  1815.  
  1816.     protected override void OnSizeChanged(EventArgs e)
  1817.     {
  1818.         UpdateTable();
  1819.     }
  1820.  
  1821.     private int Index1 = -1;
  1822.  
  1823.     private int Index2;
  1824.  
  1825.     private bool InvertColors;
  1826.     protected override void OnMouseMove(MouseEventArgs e)
  1827.     {
  1828.         HandleDraw(e);
  1829.     }
  1830.  
  1831.     protected override void OnMouseDown(MouseEventArgs e)
  1832.     {
  1833.         HandleDraw(e);
  1834.         base.OnMouseDown(e);
  1835.     }
  1836.  
  1837.     private void HandleDraw(MouseEventArgs e)
  1838.     {
  1839.         if (e.Button == System.Windows.Forms.MouseButtons.Left || e.Button == System.Windows.Forms.MouseButtons.Right)
  1840.         {
  1841.             if (!WA.Contains(e.Location))
  1842.                 return;
  1843.  
  1844.             InvertColors = (e.Button == System.Windows.Forms.MouseButtons.Right);
  1845.  
  1846.             Index1 = GetIndex(e.X, e.Y);
  1847.             if (Index1 == Index2)
  1848.                 return;
  1849.  
  1850.             bool L = !(Index1 % RowSize == 0);
  1851.             bool R = !(Index1 % RowSize == (RowSize - 1));
  1852.  
  1853.             Randomize(Index1 - RowSize);
  1854.             if (L)
  1855.                 Randomize(Index1 - 1);
  1856.             Randomize(Index1);
  1857.             if (R)
  1858.                 Randomize(Index1 + 1);
  1859.             Randomize(Index1 + RowSize);
  1860.  
  1861.             _Value.Append(Table[Index1].ToString("X"));
  1862.             if (_Value.Length > 32)
  1863.                 _Value.Remove(0, 2);
  1864.  
  1865.             if (ValueChanged != null)
  1866.             {
  1867.                 ValueChanged(this);
  1868.             }
  1869.  
  1870.             Index2 = Index1;
  1871.             Invalidate();
  1872.         }
  1873.     }
  1874.  
  1875.     private GraphicsPath GP1;
  1876.  
  1877.     private GraphicsPath GP2;
  1878.     private Pen P1;
  1879.     private Pen P2;
  1880.     private SolidBrush B1;
  1881.  
  1882.     private SolidBrush B2;
  1883.  
  1884.     private PathGradientBrush PB1;
  1885.     private Graphics G;
  1886.  
  1887.     protected override void OnPaint(PaintEventArgs e)
  1888.     {
  1889.         G = e.Graphics;
  1890.  
  1891.         G.Clear(BackColor);
  1892.         G.SmoothingMode = SmoothingMode.AntiAlias;
  1893.  
  1894.         GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  1895.         GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  1896.  
  1897.         PB1 = new PathGradientBrush(GP1);
  1898.         PB1.CenterColor = Color.FromArgb(50, 50, 50);
  1899.         PB1.SurroundColors = new Color[]{ Color.FromArgb(45, 45, 45) };
  1900.         PB1.FocusScales = new PointF(0.9f, 0.5f);
  1901.  
  1902.         G.FillPath(PB1, GP1);
  1903.  
  1904.         G.DrawPath(P1, GP1);
  1905.         G.DrawPath(P2, GP2);
  1906.  
  1907.         G.SmoothingMode = SmoothingMode.None;
  1908.  
  1909.         for (int I = 0; I <= Table.Length - 1; I++) {
  1910.             int C = Math.Max(Table[I], (byte)75);
  1911.  
  1912.             int X = ((I % RowSize) * ItemSize) + WA.X;
  1913.             int Y = ((I / RowSize) * ItemSize) + WA.Y;
  1914.  
  1915.             B2 = new SolidBrush(Color.FromArgb(C, C, C));
  1916.  
  1917.             G.FillRectangle(B1, X + 1, Y + 1, DrawSize, DrawSize);
  1918.             G.FillRectangle(B2, X, Y, DrawSize, DrawSize);
  1919.  
  1920.             B2.Dispose();
  1921.         }
  1922.  
  1923.     }
  1924.  
  1925.     private int GetIndex(int x, int y)
  1926.     {
  1927.         return (((y - WA.Y) / ItemSize) * RowSize) + ((x - WA.X) / ItemSize);
  1928.     }
  1929.  
  1930.     private void Randomize(int index)
  1931.     {
  1932.         if (index > -1 && index < Table.Length)
  1933.         {
  1934.             if (InvertColors)
  1935.             {
  1936.                 Table[index] = Convert.ToByte(RNG.Next(100));
  1937.             }
  1938.             else
  1939.             {
  1940.                 Table[index] = Convert.ToByte(RNG.Next(100, 256));
  1941.             }
  1942.         }
  1943.     }
  1944.  
  1945. }
  1946.  
  1947. class NSKeyboard : Control
  1948. {
  1949.  
  1950.     private Bitmap TextBitmap;
  1951.  
  1952.     private Graphics TextGraphics;
  1953.     const string LowerKeys = "1234567890-=qwertyuiop[]asdfghjkl\\;'zxcvbnm,./`";
  1954.  
  1955.     const string UpperKeys = "!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL|:\"ZXCVBNM<>?~";
  1956.     public NSKeyboard()
  1957.     {
  1958.         SetStyle((ControlStyles)139286, true);
  1959.         SetStyle(ControlStyles.Selectable, false);
  1960.  
  1961.         Font = new Font("Verdana", 8.25f);
  1962.  
  1963.         TextBitmap = new Bitmap(1, 1);
  1964.         TextGraphics = Graphics.FromImage(TextBitmap);
  1965.  
  1966.         MinimumSize = new Size(386, 162);
  1967.         MaximumSize = new Size(386, 162);
  1968.  
  1969.         Lower = LowerKeys.ToCharArray();
  1970.         Upper = UpperKeys.ToCharArray();
  1971.  
  1972.         PrepareCache();
  1973.  
  1974.         P1 = new Pen(Color.FromArgb(45, 45, 45));
  1975.         P2 = new Pen(Color.FromArgb(65, 65, 65));
  1976.         P3 = new Pen(Color.FromArgb(35, 35, 35));
  1977.  
  1978.         B1 = new SolidBrush(Color.FromArgb(100, 100, 100));
  1979.     }
  1980.  
  1981.     private Control _Target;
  1982.     public Control Target
  1983.     {
  1984.         get { return _Target; }
  1985.         set { _Target = value; }
  1986.     }
  1987.  
  1988.  
  1989.     private bool Shift;
  1990.     private int Pressed = -1;
  1991.  
  1992.     private Rectangle[] Buttons;
  1993.     private char[] Lower;
  1994.     private char[] Upper;
  1995.     private string[] Other = {
  1996.         "Shift",
  1997.         "Space",
  1998.         "Back"
  1999.  
  2000.     };
  2001.     private PointF[] UpperCache;
  2002.  
  2003.     private PointF[] LowerCache;
  2004.     private void PrepareCache()
  2005.     {
  2006.         Buttons = new Rectangle[51];
  2007.         UpperCache = new PointF[Upper.Length];
  2008.         LowerCache = new PointF[Lower.Length];
  2009.  
  2010.         int I = 0;
  2011.  
  2012.         SizeF S = default(SizeF);
  2013.         Rectangle R = default(Rectangle);
  2014.  
  2015.         for (int Y = 0; Y <= 3; Y++)
  2016.         {
  2017.             for (int X = 0; X <= 11; X++)
  2018.             {
  2019.                 I = (Y * 12) + X;
  2020.                 R = new Rectangle(X * 32, Y * 32, 32, 32);
  2021.  
  2022.                 Buttons[I] = R;
  2023.  
  2024.                 if (!(I == 47) && !char.IsLetter(Upper[I]))
  2025.                 {
  2026.                     S = TextGraphics.MeasureString(Upper[I].ToString(), Font);
  2027.                     UpperCache[I] = new PointF(R.X + (R.Width / 2 - S.Width / 2), R.Y + R.Height - S.Height - 2);
  2028.  
  2029.                     S = TextGraphics.MeasureString(Lower[I].ToString(), Font);
  2030.                     LowerCache[I] = new PointF(R.X + (R.Width / 2 - S.Width / 2), R.Y + R.Height - S.Height - 2);
  2031.                 }
  2032.             }
  2033.         }
  2034.  
  2035.         Buttons[48] = new Rectangle(0, 4 * 32, 2 * 32, 32);
  2036.         Buttons[49] = new Rectangle(Buttons[48].Right, 4 * 32, 8 * 32, 32);
  2037.         Buttons[50] = new Rectangle(Buttons[49].Right, 4 * 32, 2 * 32, 32);
  2038.     }
  2039.  
  2040.  
  2041.     private GraphicsPath GP1;
  2042.     private SizeF SZ1;
  2043.  
  2044.     private PointF PT1;
  2045.     private Pen P1;
  2046.     private Pen P2;
  2047.     private Pen P3;
  2048.  
  2049.     private SolidBrush B1;
  2050.     private PathGradientBrush PB1;
  2051.  
  2052.     private LinearGradientBrush GB1;
  2053.     private Graphics G;
  2054.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2055.     {
  2056.         G = e.Graphics;
  2057.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  2058.  
  2059.         G.Clear(BackColor);
  2060.  
  2061.         Rectangle R = default(Rectangle);
  2062.  
  2063.         int Offset = 0;
  2064.         G.DrawRectangle(P1, 0, 0, (12 * 32) + 1, (5 * 32) + 1);
  2065.  
  2066.         for (int I = 0; I <= Buttons.Length - 1; I++) {
  2067.             R = Buttons[I];
  2068.  
  2069.             Offset = 0;
  2070.             if (I == Pressed) {
  2071.                 Offset = 1;
  2072.  
  2073.                 GP1 = new GraphicsPath();
  2074.                 GP1.AddRectangle(R);
  2075.  
  2076.                 PB1 = new PathGradientBrush(GP1);
  2077.                 PB1.CenterColor = Color.FromArgb(60, 60, 60);
  2078.                 PB1.SurroundColors = new Color[]{ Color.FromArgb(55, 55, 55) };
  2079.                 PB1.FocusScales = new PointF(0.8f, 0.5f);
  2080.  
  2081.                 G.FillPath(PB1, GP1);
  2082.             } else {
  2083.                 GB1 = new LinearGradientBrush(R, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  2084.                 G.FillRectangle(GB1, R);
  2085.             }
  2086.  
  2087.             switch (I) {
  2088.                 case 48:
  2089.                 case 49:
  2090.                 case 50:
  2091.                     SZ1 = G.MeasureString(Other[I - 48], Font);
  2092.                     G.DrawString(Other[I - 48], Font, Brushes.Black, R.X + (R.Width / 2 - SZ1.Width / 2) + Offset + 1, R.Y + (R.Height / 2 - SZ1.Height / 2) + Offset + 1);
  2093.                     G.DrawString(Other[I - 48], Font, Brushes.White, R.X + (R.Width / 2 - SZ1.Width / 2) + Offset, R.Y + (R.Height / 2 - SZ1.Height / 2) + Offset);
  2094.                     break;
  2095.                 case 47:
  2096.                     DrawArrow(Color.Black, R.X + Offset + 1, R.Y + Offset + 1);
  2097.                     DrawArrow(Color.White, R.X + Offset, R.Y + Offset);
  2098.                     break;
  2099.                 default:
  2100.                     if (Shift) {
  2101.                         G.DrawString(Upper[I].ToString(), Font, Brushes.Black, R.X + 3 + Offset + 1, R.Y + 2 + Offset + 1);
  2102.                         G.DrawString(Upper[I].ToString(), Font, Brushes.White, R.X + 3 + Offset, R.Y + 2 + Offset);
  2103.  
  2104.                         if (!char.IsLetter(Lower[I])) {
  2105.                             PT1 = LowerCache[I];
  2106.                             G.DrawString(Lower[I].ToString(), Font, B1, PT1.X + Offset, PT1.Y + Offset);
  2107.                         }
  2108.                     } else {
  2109.                         G.DrawString(Lower[I].ToString(), Font, Brushes.Black, R.X + 3 + Offset + 1, R.Y + 2 + Offset + 1);
  2110.                         G.DrawString(Lower[I].ToString(), Font, Brushes.White, R.X + 3 + Offset, R.Y + 2 + Offset);
  2111.  
  2112.                         if (!char.IsLetter(Upper[I])) {
  2113.                             PT1 = UpperCache[I];
  2114.                             G.DrawString(Upper[I].ToString(), Font, B1, PT1.X + Offset, PT1.Y + Offset);
  2115.                         }
  2116.                     }
  2117.                     break;
  2118.             }
  2119.  
  2120.             G.DrawRectangle(P2, R.X + 1 + Offset, R.Y + 1 + Offset, R.Width - 2, R.Height - 2);
  2121.             G.DrawRectangle(P3, R.X + Offset, R.Y + Offset, R.Width, R.Height);
  2122.  
  2123.             if (I == Pressed) {
  2124.                 G.DrawLine(P1, R.X, R.Y, R.Right, R.Y);
  2125.                 G.DrawLine(P1, R.X, R.Y, R.X, R.Bottom);
  2126.             }
  2127.         }
  2128.     }
  2129.  
  2130.     private void DrawArrow(Color color, int rx, int ry)
  2131.     {
  2132.         Rectangle R = new Rectangle(rx + 8, ry + 8, 16, 16);
  2133.         G.SmoothingMode = SmoothingMode.AntiAlias;
  2134.  
  2135.         Pen P = new Pen(color, 1);
  2136.         AdjustableArrowCap C = new AdjustableArrowCap(3, 2);
  2137.         P.CustomEndCap = C;
  2138.  
  2139.         G.DrawArc(P, R, 0f, 290f);
  2140.  
  2141.         P.Dispose();
  2142.         C.Dispose();
  2143.         G.SmoothingMode = SmoothingMode.None;
  2144.     }
  2145.  
  2146.     protected override void OnMouseDown(MouseEventArgs e)
  2147.     {
  2148.         int Index = ((e.Y / 32) * 12) + (e.X / 32);
  2149.  
  2150.         if (Index > 47)
  2151.         {
  2152.             for (int I = 48; I <= Buttons.Length - 1; I++)
  2153.             {
  2154.                 if (Buttons[I].Contains(e.X, e.Y))
  2155.                 {
  2156.                     Pressed = I;
  2157.                     break; // TODO: might not be correct. Was : Exit For
  2158.                 }
  2159.             }
  2160.         }
  2161.         else
  2162.         {
  2163.             Pressed = Index;
  2164.         }
  2165.  
  2166.         HandleKey();
  2167.         Invalidate();
  2168.     }
  2169.  
  2170.     protected override void OnMouseUp(MouseEventArgs e)
  2171.     {
  2172.         Pressed = -1;
  2173.         Invalidate();
  2174.     }
  2175.  
  2176.     private void HandleKey()
  2177.     {
  2178.         if (_Target == null)
  2179.             return;
  2180.         if (Pressed == -1)
  2181.             return;
  2182.  
  2183.         switch (Pressed)
  2184.         {
  2185.             case 47:
  2186.                 _Target.Text = string.Empty;
  2187.                 break;
  2188.             case 48:
  2189.                 Shift = !Shift;
  2190.                 break;
  2191.             case 49:
  2192.                 _Target.Text += " ";
  2193.                 break;
  2194.             case 50:
  2195.                 if (!(_Target.Text.Length == 0))
  2196.                 {
  2197.                     _Target.Text = _Target.Text.Remove(_Target.Text.Length - 1);
  2198.                 }
  2199.                 break;
  2200.             default:
  2201.                 if (Shift)
  2202.                 {
  2203.                     _Target.Text += Upper[Pressed];
  2204.                 }
  2205.                 else
  2206.                 {
  2207.                     _Target.Text += Lower[Pressed];
  2208.                 }
  2209.                 break;
  2210.         }
  2211.     }
  2212.  
  2213. }
  2214.  
  2215. [DefaultEvent("SelectedIndexChanged")]
  2216. class NSPaginator : Control
  2217. {
  2218.  
  2219.     public event SelectedIndexChangedEventHandler SelectedIndexChanged;
  2220.     public delegate void SelectedIndexChangedEventHandler(object sender, EventArgs e);
  2221.  
  2222.     private Bitmap TextBitmap;
  2223.  
  2224.     private Graphics TextGraphics;
  2225.     public NSPaginator()
  2226.     {
  2227.         SetStyle((ControlStyles)139286, true);
  2228.         SetStyle(ControlStyles.Selectable, false);
  2229.  
  2230.         Size = new Size(202, 26);
  2231.  
  2232.         TextBitmap = new Bitmap(1, 1);
  2233.         TextGraphics = Graphics.FromImage(TextBitmap);
  2234.  
  2235.         InvalidateItems();
  2236.  
  2237.         B1 = new SolidBrush(Color.FromArgb(50, 50, 50));
  2238.         B2 = new SolidBrush(Color.FromArgb(55, 55, 55));
  2239.  
  2240.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  2241.         P2 = new Pen(Color.FromArgb(55, 55, 55));
  2242.         P3 = new Pen(Color.FromArgb(65, 65, 65));
  2243.     }
  2244.  
  2245.     private int _SelectedIndex;
  2246.     public int SelectedIndex
  2247.     {
  2248.         get { return _SelectedIndex; }
  2249.         set
  2250.         {
  2251.             _SelectedIndex = Math.Max(Math.Min(value, MaximumIndex), 0);
  2252.             Invalidate();
  2253.         }
  2254.     }
  2255.  
  2256.     private int _NumberOfPages;
  2257.     public int NumberOfPages
  2258.     {
  2259.         get { return _NumberOfPages; }
  2260.         set
  2261.         {
  2262.             _NumberOfPages = value;
  2263.             _SelectedIndex = Math.Max(Math.Min(_SelectedIndex, MaximumIndex), 0);
  2264.             Invalidate();
  2265.         }
  2266.     }
  2267.  
  2268.     public int MaximumIndex
  2269.     {
  2270.         get { return NumberOfPages - 1; }
  2271.     }
  2272.  
  2273.  
  2274.     private int ItemWidth;
  2275.     public override Font Font
  2276.     {
  2277.         get { return base.Font; }
  2278.         set
  2279.         {
  2280.             base.Font = value;
  2281.  
  2282.             InvalidateItems();
  2283.             Invalidate();
  2284.         }
  2285.     }
  2286.  
  2287.     private void InvalidateItems()
  2288.     {
  2289.         Size S = TextGraphics.MeasureString("000 ..", Font).ToSize();
  2290.         ItemWidth = S.Width + 10;
  2291.     }
  2292.  
  2293.     private GraphicsPath GP1;
  2294.  
  2295.     private GraphicsPath GP2;
  2296.  
  2297.     private Rectangle R1;
  2298.     private Size SZ1;
  2299.  
  2300.     private Point PT1;
  2301.     private Pen P1;
  2302.     private Pen P2;
  2303.     private Pen P3;
  2304.     private SolidBrush B1;
  2305.  
  2306.     private SolidBrush B2;
  2307.     private Graphics G;
  2308.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2309.     {
  2310.         G = e.Graphics;
  2311.         G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
  2312.  
  2313.         G.Clear(BackColor);
  2314.         G.SmoothingMode = SmoothingMode.AntiAlias;
  2315.  
  2316.         bool LeftEllipse = false;
  2317.         bool RightEllipse = false;
  2318.  
  2319.         if (_SelectedIndex < 4)
  2320.         {
  2321.             for (int I = 0; I <= Math.Min(MaximumIndex, 4); I++)
  2322.             {
  2323.                 RightEllipse = (I == 4) && (MaximumIndex > 4);
  2324.                 DrawBox(I * ItemWidth, I, false, RightEllipse);
  2325.             }
  2326.         }
  2327.         else if (_SelectedIndex > 3 && _SelectedIndex < (MaximumIndex - 3))
  2328.         {
  2329.             for (int I = 0; I <= 4; I++)
  2330.             {
  2331.                 LeftEllipse = (I == 0);
  2332.                 RightEllipse = (I == 4);
  2333.                 DrawBox(I * ItemWidth, _SelectedIndex + I - 2, LeftEllipse, RightEllipse);
  2334.             }
  2335.         }
  2336.         else
  2337.         {
  2338.             for (int I = 0; I <= 4; I++)
  2339.             {
  2340.                 LeftEllipse = (I == 0) && (MaximumIndex > 4);
  2341.                 DrawBox(I * ItemWidth, MaximumIndex - (4 - I), LeftEllipse, false);
  2342.             }
  2343.         }
  2344.     }
  2345.  
  2346.     private void DrawBox(int x, int index, bool leftEllipse, bool rightEllipse)
  2347.     {
  2348.         R1 = new Rectangle(x, 0, ItemWidth - 4, Height - 1);
  2349.  
  2350.         GP1 = ThemeModule.CreateRound(R1, 7);
  2351.         GP2 = ThemeModule.CreateRound(R1.X + 1, R1.Y + 1, R1.Width - 2, R1.Height - 2, 7);
  2352.  
  2353.         string T = Convert.ToString(index + 1);
  2354.  
  2355.         if (leftEllipse)
  2356.             T = ".. " + T;
  2357.         if (rightEllipse)
  2358.             T = T + " ..";
  2359.  
  2360.         SZ1 = G.MeasureString(T, Font).ToSize();
  2361.         PT1 = new Point(R1.X + (R1.Width / 2 - SZ1.Width / 2), R1.Y + (R1.Height / 2 - SZ1.Height / 2));
  2362.  
  2363.         if (index == _SelectedIndex)
  2364.         {
  2365.             G.FillPath(B1, GP1);
  2366.  
  2367.             Font F = new Font(Font, FontStyle.Underline);
  2368.             G.DrawString(T, F, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  2369.             G.DrawString(T, F, Brushes.White, PT1);
  2370.             F.Dispose();
  2371.  
  2372.             G.DrawPath(P1, GP2);
  2373.             G.DrawPath(P2, GP1);
  2374.         }
  2375.         else
  2376.         {
  2377.             G.FillPath(B2, GP1);
  2378.  
  2379.             G.DrawString(T, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  2380.             G.DrawString(T, Font, Brushes.White, PT1);
  2381.  
  2382.             G.DrawPath(P3, GP2);
  2383.             G.DrawPath(P1, GP1);
  2384.         }
  2385.     }
  2386.  
  2387.     protected override void OnMouseDown(MouseEventArgs e)
  2388.     {
  2389.         if (e.Button == System.Windows.Forms.MouseButtons.Left)
  2390.         {
  2391.             int NewIndex = 0;
  2392.             int OldIndex = _SelectedIndex;
  2393.  
  2394.             if (_SelectedIndex < 4)
  2395.             {
  2396.                 NewIndex = (e.X / ItemWidth);
  2397.             }
  2398.             else if (_SelectedIndex > 3 && _SelectedIndex < (MaximumIndex - 3))
  2399.             {
  2400.                 NewIndex = (e.X / ItemWidth);
  2401.  
  2402.                 if (NewIndex == 2)
  2403.                 {
  2404.                     NewIndex = OldIndex;
  2405.                 }
  2406.                 else if (NewIndex < 2)
  2407.                 {
  2408.                     NewIndex = OldIndex - (2 - NewIndex);
  2409.                 }
  2410.                 else if (NewIndex > 2)
  2411.                 {
  2412.                     NewIndex = OldIndex + (NewIndex - 2);
  2413.                 }
  2414.             }
  2415.             else
  2416.             {
  2417.                 NewIndex = MaximumIndex - (4 - (e.X / ItemWidth));
  2418.             }
  2419.  
  2420.             if ((NewIndex < _NumberOfPages) && (!(NewIndex == OldIndex)))
  2421.             {
  2422.                 SelectedIndex = NewIndex;
  2423.                 if (SelectedIndexChanged != null)
  2424.                 {
  2425.                     SelectedIndexChanged(this, null);
  2426.                 }
  2427.             }
  2428.         }
  2429.  
  2430.         base.OnMouseDown(e);
  2431.     }
  2432.  
  2433. }
  2434.  
  2435. [DefaultEvent("Scroll")]
  2436. class NSVScrollBar : Control
  2437. {
  2438.  
  2439.     public event ScrollEventHandler Scroll;
  2440.     public delegate void ScrollEventHandler(object sender);
  2441.  
  2442.     private int _Minimum;
  2443.     public int Minimum
  2444.     {
  2445.         get { return _Minimum; }
  2446.         set
  2447.         {
  2448.             if (value < 0)
  2449.             {
  2450.                 throw new Exception("Property value is not valid.");
  2451.             }
  2452.  
  2453.             _Minimum = value;
  2454.             if (value > _Value)
  2455.                 _Value = value;
  2456.             if (value > _Maximum)
  2457.                 _Maximum = value;
  2458.  
  2459.             InvalidateLayout();
  2460.         }
  2461.     }
  2462.  
  2463.     private int _Maximum = 100;
  2464.     public int Maximum
  2465.     {
  2466.         get { return _Maximum; }
  2467.         set
  2468.         {
  2469.             if (value < 1)
  2470.                 value = 1;
  2471.  
  2472.             _Maximum = value;
  2473.             if (value < _Value)
  2474.                 _Value = value;
  2475.             if (value < _Minimum)
  2476.                 _Minimum = value;
  2477.  
  2478.             InvalidateLayout();
  2479.         }
  2480.     }
  2481.  
  2482.     private int _Value;
  2483.     public int Value
  2484.     {
  2485.         get
  2486.         {
  2487.             if (!ShowThumb)
  2488.                 return _Minimum;
  2489.             return _Value;
  2490.         }
  2491.         set
  2492.         {
  2493.             if (value == _Value)
  2494.                 return;
  2495.  
  2496.             if (value > _Maximum || value < _Minimum)
  2497.             {
  2498.                 throw new Exception("Property value is not valid.");
  2499.             }
  2500.  
  2501.             _Value = value;
  2502.             InvalidatePosition();
  2503.  
  2504.             if (Scroll != null)
  2505.             {
  2506.                 Scroll(this);
  2507.             }
  2508.         }
  2509.     }
  2510.  
  2511.     public double _Percent { get; set; }
  2512.     public double Percent
  2513.     {
  2514.         get
  2515.         {
  2516.             if (!ShowThumb)
  2517.                 return 0;
  2518.             return GetProgress();
  2519.         }
  2520.     }
  2521.  
  2522.     private int _SmallChange = 1;
  2523.     public int SmallChange
  2524.     {
  2525.         get { return _SmallChange; }
  2526.         set
  2527.         {
  2528.             if (value < 1)
  2529.             {
  2530.                 throw new Exception("Property value is not valid.");
  2531.             }
  2532.  
  2533.             _SmallChange = value;
  2534.         }
  2535.     }
  2536.  
  2537.     private int _LargeChange = 10;
  2538.     public int LargeChange
  2539.     {
  2540.         get { return _LargeChange; }
  2541.         set
  2542.         {
  2543.             if (value < 1)
  2544.             {
  2545.                 throw new Exception("Property value is not valid.");
  2546.             }
  2547.  
  2548.             _LargeChange = value;
  2549.         }
  2550.     }
  2551.  
  2552.     private int ButtonSize = 16;
  2553.     // 14 minimum
  2554.     private int ThumbSize = 24;
  2555.  
  2556.     private Rectangle TSA;
  2557.     private Rectangle BSA;
  2558.     private Rectangle Shaft;
  2559.  
  2560.     private Rectangle Thumb;
  2561.     private bool ShowThumb;
  2562.  
  2563.     private bool ThumbDown;
  2564.     public NSVScrollBar()
  2565.     {
  2566.         SetStyle((ControlStyles)139286, true);
  2567.         SetStyle(ControlStyles.Selectable, false);
  2568.  
  2569.         Width = 18;
  2570.  
  2571.         B1 = new SolidBrush(Color.FromArgb(55, 55, 55));
  2572.         B2 = new SolidBrush(Color.FromArgb(35, 35, 35));
  2573.  
  2574.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  2575.         P2 = new Pen(Color.FromArgb(65, 65, 65));
  2576.         P3 = new Pen(Color.FromArgb(55, 55, 55));
  2577.         P4 = new Pen(Color.FromArgb(40, 40, 40));
  2578.     }
  2579.  
  2580.     private GraphicsPath GP1;
  2581.     private GraphicsPath GP2;
  2582.     private GraphicsPath GP3;
  2583.  
  2584.     private GraphicsPath GP4;
  2585.     private Pen P1;
  2586.     private Pen P2;
  2587.     private Pen P3;
  2588.     private Pen P4;
  2589.     private SolidBrush B1;
  2590.  
  2591.     private SolidBrush B2;
  2592.  
  2593.     int I1;
  2594.     private Graphics G;
  2595.  
  2596.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2597.     {
  2598.         G = e.Graphics;
  2599.         G.Clear(BackColor);
  2600.  
  2601.         GP1 = DrawArrow(4, 6, false);
  2602.         GP2 = DrawArrow(5, 7, false);
  2603.  
  2604.         G.FillPath(B1, GP2);
  2605.         G.FillPath(B2, GP1);
  2606.  
  2607.         GP3 = DrawArrow(4, Height - 11, true);
  2608.         GP4 = DrawArrow(5, Height - 10, true);
  2609.  
  2610.         G.FillPath(B1, GP4);
  2611.         G.FillPath(B2, GP3);
  2612.  
  2613.         if (ShowThumb)
  2614.         {
  2615.             G.FillRectangle(B1, Thumb);
  2616.             G.DrawRectangle(P1, Thumb);
  2617.             G.DrawRectangle(P2, Thumb.X + 1, Thumb.Y + 1, Thumb.Width - 2, Thumb.Height - 2);
  2618.  
  2619.             int Y = 0;
  2620.             int LY = Thumb.Y + (Thumb.Height / 2) - 3;
  2621.  
  2622.             for (int I = 0; I <= 2; I++)
  2623.             {
  2624.                 Y = LY + (I * 3);
  2625.  
  2626.                 G.DrawLine(P1, Thumb.X + 5, Y, Thumb.Right - 5, Y);
  2627.                 G.DrawLine(P2, Thumb.X + 5, Y + 1, Thumb.Right - 5, Y + 1);
  2628.             }
  2629.         }
  2630.  
  2631.         G.DrawRectangle(P3, 0, 0, Width - 1, Height - 1);
  2632.         G.DrawRectangle(P4, 1, 1, Width - 3, Height - 3);
  2633.     }
  2634.  
  2635.     private GraphicsPath DrawArrow(int x, int y, bool flip)
  2636.     {
  2637.         GraphicsPath GP = new GraphicsPath();
  2638.  
  2639.         int W = 9;
  2640.         int H = 5;
  2641.  
  2642.         if (flip)
  2643.         {
  2644.             GP.AddLine(x + 1, y, x + W + 1, y);
  2645.             GP.AddLine(x + W, y, x + H, y + H - 1);
  2646.         }
  2647.         else
  2648.         {
  2649.             GP.AddLine(x, y + H, x + W, y + H);
  2650.             GP.AddLine(x + W, y + H, x + H, y);
  2651.         }
  2652.  
  2653.         GP.CloseFigure();
  2654.         return GP;
  2655.     }
  2656.  
  2657.     protected override void OnSizeChanged(EventArgs e)
  2658.     {
  2659.         InvalidateLayout();
  2660.     }
  2661.  
  2662.     private void InvalidateLayout()
  2663.     {
  2664.         TSA = new Rectangle(0, 0, Width, ButtonSize);
  2665.         BSA = new Rectangle(0, Height - ButtonSize, Width, ButtonSize);
  2666.         Shaft = new Rectangle(0, TSA.Bottom + 1, Width, Height - (ButtonSize * 2) - 1);
  2667.  
  2668.         ShowThumb = ((_Maximum - _Minimum) > Shaft.Height);
  2669.  
  2670.         if (ShowThumb)
  2671.         {
  2672.             //ThumbSize = Math.Max(0, 14) 'TODO: Implement this.
  2673.             Thumb = new Rectangle(1, 0, Width - 3, ThumbSize);
  2674.         }
  2675.  
  2676.         if (Scroll != null)
  2677.         {
  2678.             Scroll(this);
  2679.         }
  2680.         InvalidatePosition();
  2681.     }
  2682.  
  2683.     private void InvalidatePosition()
  2684.     {
  2685.         Thumb.Y = Convert.ToInt32(GetProgress() * (Shaft.Height - ThumbSize)) + TSA.Height;
  2686.         Invalidate();
  2687.     }
  2688.  
  2689.     protected override void OnMouseDown(MouseEventArgs e)
  2690.     {
  2691.         if (e.Button == System.Windows.Forms.MouseButtons.Left && ShowThumb)
  2692.         {
  2693.             if (TSA.Contains(e.Location))
  2694.             {
  2695.                 I1 = _Value - _SmallChange;
  2696.             }
  2697.             else if (BSA.Contains(e.Location))
  2698.             {
  2699.                 I1 = _Value + _SmallChange;
  2700.             }
  2701.             else
  2702.             {
  2703.                 if (Thumb.Contains(e.Location))
  2704.                 {
  2705.                     ThumbDown = true;
  2706.                     base.OnMouseDown(e);
  2707.                     return;
  2708.                 }
  2709.                 else
  2710.                 {
  2711.                     if (e.Y < Thumb.Y)
  2712.                     {
  2713.                         I1 = _Value - _LargeChange;
  2714.                     }
  2715.                     else
  2716.                     {
  2717.                         I1 = _Value + _LargeChange;
  2718.                     }
  2719.                 }
  2720.             }
  2721.  
  2722.             Value = Math.Min(Math.Max(I1, _Minimum), _Maximum);
  2723.             InvalidatePosition();
  2724.         }
  2725.  
  2726.         base.OnMouseDown(e);
  2727.     }
  2728.  
  2729.     protected override void OnMouseMove(MouseEventArgs e)
  2730.     {
  2731.         if (ThumbDown && ShowThumb)
  2732.         {
  2733.             int ThumbPosition = e.Y - TSA.Height - (ThumbSize / 2);
  2734.             int ThumbBounds = Shaft.Height - ThumbSize;
  2735.  
  2736.             I1 = Convert.ToInt32(((double)ThumbPosition / (double)ThumbBounds) * (_Maximum - _Minimum)) + _Minimum;
  2737.  
  2738.             Value = Math.Min(Math.Max(I1, _Minimum), _Maximum);
  2739.             InvalidatePosition();
  2740.         }
  2741.  
  2742.         base.OnMouseMove(e);
  2743.     }
  2744.  
  2745.     protected override void OnMouseUp(MouseEventArgs e)
  2746.     {
  2747.         ThumbDown = false;
  2748.         base.OnMouseUp(e);
  2749.     }
  2750.  
  2751.     private double GetProgress()
  2752.     {
  2753.         return (double)(_Value - _Minimum) / (double)(_Maximum - _Minimum);
  2754.     }
  2755.  
  2756. }
  2757.  
  2758. [DefaultEvent("Scroll")]
  2759. class NSHScrollBar : Control
  2760. {
  2761.  
  2762.     public event ScrollEventHandler Scroll;
  2763.     public delegate void ScrollEventHandler(object sender);
  2764.  
  2765.     private int _Minimum;
  2766.     public int Minimum
  2767.     {
  2768.         get { return _Minimum; }
  2769.         set
  2770.         {
  2771.             if (value < 0)
  2772.             {
  2773.                 throw new Exception("Property value is not valid.");
  2774.             }
  2775.  
  2776.             _Minimum = value;
  2777.             if (value > _Value)
  2778.                 _Value = value;
  2779.             if (value > _Maximum)
  2780.                 _Maximum = value;
  2781.  
  2782.             InvalidateLayout();
  2783.         }
  2784.     }
  2785.  
  2786.     private int _Maximum = 100;
  2787.     public int Maximum
  2788.     {
  2789.         get { return _Maximum; }
  2790.         set
  2791.         {
  2792.             if (value < 0)
  2793.             {
  2794.                 throw new Exception("Property value is not valid.");
  2795.             }
  2796.  
  2797.             _Maximum = value;
  2798.             if (value < _Value)
  2799.                 _Value = value;
  2800.             if (value < _Minimum)
  2801.                 _Minimum = value;
  2802.  
  2803.             InvalidateLayout();
  2804.         }
  2805.     }
  2806.  
  2807.     private int _Value;
  2808.     public int Value
  2809.     {
  2810.         get
  2811.         {
  2812.             if (!ShowThumb)
  2813.                 return _Minimum;
  2814.             return _Value;
  2815.         }
  2816.         set
  2817.         {
  2818.             if (value == _Value)
  2819.                 return;
  2820.  
  2821.             if (value > _Maximum || value < _Minimum)
  2822.             {
  2823.                 throw new Exception("Property value is not valid.");
  2824.             }
  2825.  
  2826.             _Value = value;
  2827.             InvalidatePosition();
  2828.  
  2829.             if (Scroll != null)
  2830.             {
  2831.                 Scroll(this);
  2832.             }
  2833.         }
  2834.     }
  2835.  
  2836.     private int _SmallChange = 1;
  2837.     public int SmallChange
  2838.     {
  2839.         get { return _SmallChange; }
  2840.         set
  2841.         {
  2842.             if (value < 1)
  2843.             {
  2844.                 throw new Exception("Property value is not valid.");
  2845.             }
  2846.  
  2847.             _SmallChange = value;
  2848.         }
  2849.     }
  2850.  
  2851.     private int _LargeChange = 10;
  2852.     public int LargeChange
  2853.     {
  2854.         get { return _LargeChange; }
  2855.         set
  2856.         {
  2857.             if (value < 1)
  2858.             {
  2859.                 throw new Exception("Property value is not valid.");
  2860.             }
  2861.  
  2862.             _LargeChange = value;
  2863.         }
  2864.     }
  2865.  
  2866.     private int ButtonSize = 16;
  2867.     // 14 minimum
  2868.     private int ThumbSize = 24;
  2869.  
  2870.     private Rectangle LSA;
  2871.     private Rectangle RSA;
  2872.     private Rectangle Shaft;
  2873.  
  2874.     private Rectangle Thumb;
  2875.     private bool ShowThumb;
  2876.  
  2877.     private bool ThumbDown;
  2878.     public NSHScrollBar()
  2879.     {
  2880.         SetStyle((ControlStyles)139286, true);
  2881.         SetStyle(ControlStyles.Selectable, false);
  2882.  
  2883.         Height = 18;
  2884.  
  2885.         B1 = new SolidBrush(Color.FromArgb(55, 55, 55));
  2886.         B2 = new SolidBrush(Color.FromArgb(35, 35, 35));
  2887.  
  2888.         P1 = new Pen(Color.FromArgb(35, 35, 35));
  2889.         P2 = new Pen(Color.FromArgb(65, 65, 65));
  2890.         P3 = new Pen(Color.FromArgb(55, 55, 55));
  2891.         P4 = new Pen(Color.FromArgb(40, 40, 40));
  2892.     }
  2893.  
  2894.     private GraphicsPath GP1;
  2895.     private GraphicsPath GP2;
  2896.     private GraphicsPath GP3;
  2897.  
  2898.     private GraphicsPath GP4;
  2899.     private Pen P1;
  2900.     private Pen P2;
  2901.     private Pen P3;
  2902.     private Pen P4;
  2903.     private SolidBrush B1;
  2904.  
  2905.     private SolidBrush B2;
  2906.  
  2907.     int I1;
  2908.     private Graphics G;
  2909.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2910.     {
  2911.         G = e.Graphics;
  2912.         G.Clear(BackColor);
  2913.  
  2914.         GP1 = DrawArrow(6, 4, false);
  2915.         GP2 = DrawArrow(7, 5, false);
  2916.  
  2917.         G.FillPath(B1, GP2);
  2918.         G.FillPath(B2, GP1);
  2919.  
  2920.         GP3 = DrawArrow(Width - 11, 4, true);
  2921.         GP4 = DrawArrow(Width - 10, 5, true);
  2922.  
  2923.         G.FillPath(B1, GP4);
  2924.         G.FillPath(B2, GP3);
  2925.  
  2926.         if (ShowThumb)
  2927.         {
  2928.             G.FillRectangle(B1, Thumb);
  2929.             G.DrawRectangle(P1, Thumb);
  2930.             G.DrawRectangle(P2, Thumb.X + 1, Thumb.Y + 1, Thumb.Width - 2, Thumb.Height - 2);
  2931.  
  2932.             int X = 0;
  2933.             int LX = Thumb.X + (Thumb.Width / 2) - 3;
  2934.  
  2935.             for (int I = 0; I <= 2; I++)
  2936.             {
  2937.                 X = LX + (I * 3);
  2938.  
  2939.                 G.DrawLine(P1, X, Thumb.Y + 5, X, Thumb.Bottom - 5);
  2940.                 G.DrawLine(P2, X + 1, Thumb.Y + 5, X + 1, Thumb.Bottom - 5);
  2941.             }
  2942.         }
  2943.  
  2944.         G.DrawRectangle(P3, 0, 0, Width - 1, Height - 1);
  2945.         G.DrawRectangle(P4, 1, 1, Width - 3, Height - 3);
  2946.     }
  2947.  
  2948.     private GraphicsPath DrawArrow(int x, int y, bool flip)
  2949.     {
  2950.         GraphicsPath GP = new GraphicsPath();
  2951.  
  2952.         int W = 5;
  2953.         int H = 9;
  2954.  
  2955.         if (flip)
  2956.         {
  2957.             GP.AddLine(x, y + 1, x, y + H + 1);
  2958.             GP.AddLine(x, y + H, x + W - 1, y + W);
  2959.         }
  2960.         else
  2961.         {
  2962.             GP.AddLine(x + W, y, x + W, y + H);
  2963.             GP.AddLine(x + W, y + H, x + 1, y + W);
  2964.         }
  2965.  
  2966.         GP.CloseFigure();
  2967.         return GP;
  2968.     }
  2969.  
  2970.     protected override void OnSizeChanged(EventArgs e)
  2971.     {
  2972.         InvalidateLayout();
  2973.     }
  2974.  
  2975.     private void InvalidateLayout()
  2976.     {
  2977.         LSA = new Rectangle(0, 0, ButtonSize, Height);
  2978.         RSA = new Rectangle(Width - ButtonSize, 0, ButtonSize, Height);
  2979.         Shaft = new Rectangle(LSA.Right + 1, 0, Width - (ButtonSize * 2) - 1, Height);
  2980.  
  2981.         ShowThumb = ((_Maximum - _Minimum) > Shaft.Width);
  2982.  
  2983.         if (ShowThumb)
  2984.         {
  2985.             //ThumbSize = Math.Max(0, 14) 'TODO: Implement this.
  2986.             Thumb = new Rectangle(0, 1, ThumbSize, Height - 3);
  2987.         }
  2988.  
  2989.         if (Scroll != null)
  2990.         {
  2991.             Scroll(this);
  2992.         }
  2993.         InvalidatePosition();
  2994.     }
  2995.  
  2996.     private void InvalidatePosition()
  2997.     {
  2998.         Thumb.X = Convert.ToInt32(GetProgress() * (Shaft.Width - ThumbSize)) + LSA.Width;
  2999.         Invalidate();
  3000.     }
  3001.  
  3002.     protected override void OnMouseDown(MouseEventArgs e)
  3003.     {
  3004.         if (e.Button == System.Windows.Forms.MouseButtons.Left && ShowThumb)
  3005.         {
  3006.             if (LSA.Contains(e.Location))
  3007.             {
  3008.                 I1 = _Value - _SmallChange;
  3009.             }
  3010.             else if (RSA.Contains(e.Location))
  3011.             {
  3012.                 I1 = _Value + _SmallChange;
  3013.             }
  3014.             else
  3015.             {
  3016.                 if (Thumb.Contains(e.Location))
  3017.                 {
  3018.                     ThumbDown = true;
  3019.                     base.OnMouseDown(e);
  3020.                     return;
  3021.                 }
  3022.                 else
  3023.                 {
  3024.                     if (e.X < Thumb.X)
  3025.                     {
  3026.                         I1 = _Value - _LargeChange;
  3027.                     }
  3028.                     else
  3029.                     {
  3030.                         I1 = _Value + _LargeChange;
  3031.                     }
  3032.                 }
  3033.             }
  3034.  
  3035.             Value = Math.Min(Math.Max(I1, _Minimum), _Maximum);
  3036.             InvalidatePosition();
  3037.         }
  3038.  
  3039.         base.OnMouseDown(e);
  3040.     }
  3041.  
  3042.     protected override void OnMouseMove(MouseEventArgs e)
  3043.     {
  3044.         if (ThumbDown && ShowThumb)
  3045.         {
  3046.             int ThumbPosition = e.X - LSA.Width - (ThumbSize / 2);
  3047.             int ThumbBounds = Shaft.Width - ThumbSize;
  3048.  
  3049.             I1 = Convert.ToInt32(((double)ThumbPosition / (double)ThumbBounds) * (_Maximum - _Minimum)) + _Minimum;
  3050.  
  3051.             Value = Math.Min(Math.Max(I1, _Minimum), _Maximum);
  3052.             InvalidatePosition();
  3053.         }
  3054.  
  3055.         base.OnMouseMove(e);
  3056.     }
  3057.  
  3058.     protected override void OnMouseUp(MouseEventArgs e)
  3059.     {
  3060.         ThumbDown = false;
  3061.         base.OnMouseUp(e);
  3062.     }
  3063.  
  3064.     private double GetProgress()
  3065.     {
  3066.         return (double)(_Value - _Minimum) / (double)(_Maximum - _Minimum);
  3067.     }
  3068.  
  3069. }
  3070.  
  3071. class NSContextMenu : ContextMenuStrip
  3072. {
  3073.  
  3074.     public NSContextMenu()
  3075.     {
  3076.         Renderer = new ToolStripProfessionalRenderer(new NSColorTable());
  3077.         ForeColor = Color.White;
  3078.     }
  3079.  
  3080.     protected override void OnPaint(PaintEventArgs e)
  3081.     {
  3082.         e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  3083.         base.OnPaint(e);
  3084.     }
  3085.  
  3086. }
  3087.  
  3088. class NSColorTable : ProfessionalColorTable
  3089. {
  3090.  
  3091.  
  3092.     private Color BackColor = Color.FromArgb(55, 55, 55);
  3093.     public override Color ButtonSelectedBorder
  3094.     {
  3095.         get { return BackColor; }
  3096.     }
  3097.  
  3098.     public override Color CheckBackground
  3099.     {
  3100.         get { return BackColor; }
  3101.     }
  3102.  
  3103.     public override Color CheckPressedBackground
  3104.     {
  3105.         get { return BackColor; }
  3106.     }
  3107.  
  3108.     public override Color CheckSelectedBackground
  3109.     {
  3110.         get { return BackColor; }
  3111.     }
  3112.  
  3113.     public override Color ImageMarginGradientBegin
  3114.     {
  3115.         get { return BackColor; }
  3116.     }
  3117.  
  3118.     public override Color ImageMarginGradientEnd
  3119.     {
  3120.         get { return BackColor; }
  3121.     }
  3122.  
  3123.     public override Color ImageMarginGradientMiddle
  3124.     {
  3125.         get { return BackColor; }
  3126.     }
  3127.  
  3128.     public override Color MenuBorder
  3129.     {
  3130.         get { return Color.FromArgb(25, 25, 25); }
  3131.     }
  3132.  
  3133.     public override Color MenuItemBorder
  3134.     {
  3135.         get { return BackColor; }
  3136.     }
  3137.  
  3138.     public override Color MenuItemSelected
  3139.     {
  3140.         get { return Color.FromArgb(65, 65, 65); }
  3141.     }
  3142.  
  3143.     public override Color SeparatorDark
  3144.     {
  3145.         get { return Color.FromArgb(35, 35, 35); }
  3146.     }
  3147.  
  3148.     public override Color ToolStripDropDownBackground
  3149.     {
  3150.         get { return BackColor; }
  3151.     }
  3152.  
  3153. }
  3154.  
  3155. //If you have made it this far it's not too late to turn back, you must not continue on! If you are trying to fullfill some
  3156. //sick act of masochism by studying the source of the ListView then, may god have mercy on your soul.
  3157. public class NSListView : Control
  3158. {
  3159.  
  3160.     public class NSListViewItem
  3161.     {
  3162.         public string Text { get; set; }
  3163.  
  3164.         public Image Icon { get; set; }
  3165.  
  3166.         public object Tag { get; set; }
  3167.  
  3168.         [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  3169.         public List<NSListViewSubItem> SubItems { get; set; }
  3170.  
  3171.         protected Guid UniqueId;
  3172.  
  3173.         private NSListView parent;
  3174.  
  3175.         public NSListViewItem(NSListView parent)
  3176.         {
  3177.             UniqueId = Guid.NewGuid();
  3178.             this.parent = parent;
  3179.         }
  3180.  
  3181.         public void setSubitem(int index, string value)
  3182.         {
  3183.             SubItems[index].Text = value;
  3184.             parent.Invalidate();
  3185.         }
  3186.  
  3187.         public override string ToString()
  3188.         {
  3189.             return Text;
  3190.         }
  3191.  
  3192.         public override bool Equals(object obj)
  3193.         {
  3194.             if (obj is NSListViewItem)
  3195.             {
  3196.                 return (((NSListViewItem)obj).UniqueId == UniqueId);
  3197.             }
  3198.  
  3199.             return false;
  3200.         }
  3201.  
  3202.         public override int GetHashCode()
  3203.         {
  3204.             return base.GetHashCode();
  3205.         }
  3206.  
  3207.     }
  3208.  
  3209.     public class NSListViewSubItem
  3210.     {
  3211.         public string Text { get; set; }
  3212.  
  3213.         public override string ToString()
  3214.         {
  3215.             return Text;
  3216.         }
  3217.     }
  3218.  
  3219.     public class NSListViewColumnHeader
  3220.     {
  3221.         public string Text { get; set; }
  3222.        
  3223.         public int Width { get; set; }
  3224.  
  3225.         public override string ToString()
  3226.         {
  3227.             return Text;
  3228.         }
  3229.     }
  3230.  
  3231.     private List<NSListViewItem> _Items = new List<NSListViewItem>();
  3232.     [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  3233.     public NSListViewItem[] Items
  3234.     {
  3235.         get { return _Items.ToArray(); }
  3236.         set
  3237.         {
  3238.             _Items = new List<NSListViewItem>(value);
  3239.             InvalidateScroll();
  3240.         }
  3241.     }
  3242.  
  3243.     private List<NSListViewItem> _SelectedItems = new List<NSListViewItem>();
  3244.     public NSListViewItem[] SelectedItems
  3245.     {
  3246.         get { return _SelectedItems.ToArray(); }
  3247.     }
  3248.  
  3249.     public List<int> SelectedIndices { get; private set; }
  3250.  
  3251.     public delegate void OnSelectedIndexChanged();
  3252.     public event OnSelectedIndexChanged SelectedIndexChanged;
  3253.  
  3254.     private List<NSListViewColumnHeader> _Columns = new List<NSListViewColumnHeader>();
  3255.     [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  3256.     public NSListViewColumnHeader[] Columns
  3257.     {
  3258.         get { return _Columns.ToArray(); }
  3259.         set
  3260.         {
  3261.             _Columns = new List<NSListViewColumnHeader>(value);
  3262.             InvalidateColumns();
  3263.         }
  3264.     }
  3265.  
  3266.     private bool _MultiSelect = true;
  3267.     public bool MultiSelect
  3268.     {
  3269.         get { return _MultiSelect; }
  3270.         set
  3271.         {
  3272.             _MultiSelect = value;
  3273.  
  3274.             if (_SelectedItems.Count > 1)
  3275.             {
  3276.                 _SelectedItems.RemoveRange(1, _SelectedItems.Count - 1);
  3277.             }
  3278.  
  3279.             Invalidate();
  3280.         }
  3281.     }
  3282.  
  3283.     private int ItemHeight = 24;
  3284.     public override Font Font
  3285.     {
  3286.         get { return base.Font; }
  3287.         set
  3288.         {
  3289.             ItemHeight = Convert.ToInt32(Graphics.FromHwnd(Handle).MeasureString("@", Font).Height) + 6;
  3290.  
  3291.             if (VS != null)
  3292.             {
  3293.                 VS.SmallChange = ItemHeight;
  3294.                 VS.LargeChange = ItemHeight;
  3295.             }
  3296.  
  3297.             base.Font = value;
  3298.             InvalidateLayout();
  3299.         }
  3300.     }
  3301.  
  3302.     #region " Item Helper Methods "
  3303.  
  3304.     //Ok, you've seen everything of importance at this point; I am begging you to spare yourself. You must not read any further!
  3305.  
  3306.     public void AddItem(string text, params string[] subItems)
  3307.     {
  3308.         AddItem(text, null, null, subItems);
  3309.     }
  3310.  
  3311.     public void AddItem(string text, Image icon, params string[] subItems)
  3312.     {
  3313.         AddItem(text, icon, null, subItems);
  3314.     }
  3315.  
  3316.     public void AddItem(string text, Image icon, object tag, params string[] subItems)
  3317.     {
  3318.         List<NSListViewSubItem> Items = new List<NSListViewSubItem>();
  3319.         foreach (string I in subItems)
  3320.         {
  3321.             NSListViewSubItem SubItem = new NSListViewSubItem();
  3322.             SubItem.Text = I;
  3323.             Items.Add(SubItem);
  3324.         }
  3325.  
  3326.         NSListViewItem Item = new NSListViewItem(this);
  3327.         Item.Text = text;
  3328.         Item.Icon = icon;
  3329.         Item.Tag = tag;
  3330.         Item.SubItems = Items;
  3331.  
  3332.         _Items.Add(Item);
  3333.         InvalidateScroll();
  3334.     }
  3335.  
  3336.     public void RemoveItemAt(int index)
  3337.     {
  3338.         _Items.RemoveAt(index);
  3339.         InvalidateScroll();
  3340.     }
  3341.  
  3342.     public void RemoveItem(NSListViewItem item)
  3343.     {
  3344.         _Items.Remove(item);
  3345.         InvalidateScroll();
  3346.     }
  3347.  
  3348.     public void RemoveItems(NSListViewItem[] items)
  3349.     {
  3350.         foreach (NSListViewItem I in items)
  3351.         {
  3352.             _Items.Remove(I);
  3353.         }
  3354.  
  3355.         InvalidateScroll();
  3356.     }
  3357.  
  3358.     public void Clear()
  3359.     {
  3360.         _Items.Clear();
  3361.         _SelectedItems.Clear();
  3362.         SelectedIndices.Clear();
  3363.         InvalidateScroll();
  3364.     }
  3365.  
  3366.     #endregion
  3367.  
  3368.  
  3369.     private NSVScrollBar VS;
  3370.     public NSListView()
  3371.     {
  3372.         SelectedIndices = new List<int>();
  3373.  
  3374.         SetStyle((ControlStyles)139286, true);
  3375.         SetStyle(ControlStyles.Selectable, true);
  3376.  
  3377.         P1 = new Pen(Color.FromArgb(55, 55, 55));
  3378.         P2 = new Pen(Color.FromArgb(35, 35, 35));
  3379.         P3 = new Pen(Color.FromArgb(65, 65, 65));
  3380.  
  3381.         B1 = new SolidBrush(Color.FromArgb(62, 62, 62));
  3382.         B2 = new SolidBrush(Color.FromArgb(65, 65, 65));
  3383.         B3 = new SolidBrush(Color.FromArgb(47, 47, 47));
  3384.         B4 = new SolidBrush(Color.FromArgb(50, 50, 50));
  3385.  
  3386.         VS = new NSVScrollBar();
  3387.         VS.SmallChange = ItemHeight;
  3388.         VS.LargeChange = ItemHeight;
  3389.  
  3390.         VS.Scroll += HandleScroll;
  3391.         VS.MouseDown += VS_MouseDown;
  3392.         Controls.Add(VS);
  3393.  
  3394.         InvalidateLayout();
  3395.     }
  3396.  
  3397.     protected override void OnSizeChanged(EventArgs e)
  3398.     {
  3399.         InvalidateLayout();
  3400.         base.OnSizeChanged(e);
  3401.     }
  3402.  
  3403.     private void HandleScroll(object sender)
  3404.     {
  3405.         Invalidate();
  3406.     }
  3407.  
  3408.     private void InvalidateScroll()
  3409.     {
  3410.         VS.Maximum = (_Items.Count * ItemHeight);
  3411.         Invalidate();
  3412.     }
  3413.  
  3414.     private void InvalidateLayout()
  3415.     {
  3416.         VS.Location = new Point(Width - VS.Width - 1, 1);
  3417.         VS.Size = new Size(18, Height - 2);
  3418.  
  3419.         Invalidate();
  3420.     }
  3421.  
  3422.     private int[] ColumnOffsets;
  3423.  
  3424.     public void InvalidateColumns()
  3425.     {
  3426.         int Width = 3;
  3427.         ColumnOffsets = new int[_Columns.Count];
  3428.  
  3429.         for (int I = 0; I <= _Columns.Count - 1; I++)
  3430.         {
  3431.             ColumnOffsets[I] = Width;
  3432.             Width += Columns[I].Width;
  3433.         }
  3434.  
  3435.         Invalidate();
  3436.     }
  3437.  
  3438.     private void VS_MouseDown(object sender, MouseEventArgs e)
  3439.     {
  3440.         Focus();
  3441.     }
  3442.  
  3443.     protected override void OnMouseDown(MouseEventArgs e)
  3444.     {
  3445.         Focus();
  3446.  
  3447.         if (e.Button == System.Windows.Forms.MouseButtons.Left || (e.Button == System.Windows.Forms.MouseButtons.Right && _SelectedItems.Count <= 1))
  3448.         {
  3449.             int Offset = Convert.ToInt32(VS.Percent * (VS.Maximum - (Height - (ItemHeight * 2))));
  3450.             int Index = ((e.Y + Offset - ItemHeight) / ItemHeight);
  3451.  
  3452.             if (Index > _Items.Count - 1)
  3453.                 Index = -1;
  3454.  
  3455.             if (!(Index == -1))
  3456.             {
  3457.                 //TODO: Handle Shift key
  3458.  
  3459.                 if (ModifierKeys == Keys.Control && _MultiSelect)
  3460.                 {
  3461.                     if (_SelectedItems.Contains(_Items[Index]))
  3462.                     {
  3463.                         _SelectedItems.Remove(_Items[Index]);
  3464.                         SelectedIndices.Remove(Index);
  3465.                     }
  3466.                     else
  3467.                     {
  3468.                         _SelectedItems.Add(_Items[Index]);
  3469.                         SelectedIndices.Add(Index);
  3470.                     }
  3471.                 }
  3472.                 else
  3473.                 {
  3474.                     _SelectedItems.Clear();
  3475.                     SelectedIndices.Clear();
  3476.                     _SelectedItems.Add(_Items[Index]);
  3477.                     SelectedIndices.Add(Index);
  3478.                 }
  3479.  
  3480.                 if (SelectedIndexChanged != null)
  3481.                     SelectedIndexChanged();
  3482.             }
  3483.  
  3484.             Invalidate();
  3485.         }
  3486.  
  3487.         base.OnMouseDown(e);
  3488.     }
  3489.  
  3490.     private Pen P1;
  3491.     private Pen P2;
  3492.     private Pen P3;
  3493.     private SolidBrush B1;
  3494.     private SolidBrush B2;
  3495.     private SolidBrush B3;
  3496.     private SolidBrush B4;
  3497.  
  3498.     private LinearGradientBrush GB1;
  3499.     //I am so sorry you have to witness this. I tried warning you. ;.;
  3500.  
  3501.     private Graphics G;
  3502.     protected override void OnPaint(PaintEventArgs e)
  3503.     {
  3504.         G = e.Graphics;
  3505.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  3506.  
  3507.         G.Clear(BackColor);
  3508.  
  3509.         int X = 0;
  3510.         int Y = 0;
  3511.         float H = 0;
  3512.  
  3513.         G.DrawRectangle(P1, 1, 1, Width - 3, Height - 3);
  3514.  
  3515.         Rectangle R1 = default(Rectangle);
  3516.         NSListViewItem CI = null;
  3517.  
  3518.         int Offset = Convert.ToInt32(VS.Percent * (VS.Maximum - (Height - (ItemHeight * 2))));
  3519.  
  3520.         int StartIndex = 0;
  3521.         if (Offset == 0)
  3522.             StartIndex = 0;
  3523.         else
  3524.             StartIndex = (Offset / ItemHeight);
  3525.  
  3526.         int EndIndex = Math.Min(StartIndex + (Height / ItemHeight), _Items.Count - 1);
  3527.  
  3528.         for (int I = StartIndex; I <= EndIndex; I++)
  3529.         {
  3530.             CI = Items[I];
  3531.  
  3532.             R1 = new Rectangle(0, ItemHeight + (I * ItemHeight) + 1 - Offset, Width, ItemHeight - 1);
  3533.  
  3534.             H = G.MeasureString(CI.Text, Font).Height;
  3535.             Y = R1.Y + Convert.ToInt32((ItemHeight / 2) - (H / 2));
  3536.  
  3537.             if (_SelectedItems.Contains(CI))
  3538.             {
  3539.                 if (I % 2 == 0)
  3540.                 {
  3541.                     G.FillRectangle(B1, R1);
  3542.                 }
  3543.                 else
  3544.                 {
  3545.                     G.FillRectangle(B2, R1);
  3546.                 }
  3547.             }
  3548.             else
  3549.             {
  3550.                 if (I % 2 == 0)
  3551.                 {
  3552.                     G.FillRectangle(B3, R1);
  3553.                 }
  3554.                 else
  3555.                 {
  3556.                     G.FillRectangle(B4, R1);
  3557.                 }
  3558.             }
  3559.  
  3560.             G.DrawLine(P2, 0, R1.Bottom, Width, R1.Bottom);
  3561.  
  3562.             if (Columns.Length > 0)
  3563.             {
  3564.                 if (Columns[0].Width != 0)
  3565.                     R1.Width = Columns[0].Width;
  3566.                 else
  3567.                     R1.Width = Width;
  3568.                 G.SetClip(R1);
  3569.             }
  3570.  
  3571.             int imageWidth = 0;
  3572.  
  3573.             int imageMarginX = 12;
  3574.  
  3575.             int imageMarginY = 8;
  3576.  
  3577.             //TODO: Ellipse text that overhangs seperators.
  3578.             if (CI.Icon != null)
  3579.             {
  3580.                 double scale = (double)(ItemHeight - imageMarginY) / CI.Icon.Height;
  3581.                 imageWidth = (int)(scale * CI.Icon.Width);
  3582.                 G.DrawImage(CI.Icon, new Rectangle(imageMarginX / 2, R1.Top + (imageMarginY / 2), imageWidth, ItemHeight - imageMarginY));
  3583.             }
  3584.             G.DrawString(CI.Text, Font, Brushes.Black, imageWidth + imageMarginX / 2 + 1, Y + 1);
  3585.             G.DrawString(CI.Text, Font, Brushes.White, imageWidth + imageMarginX / 2, Y);
  3586.  
  3587.             if (CI.SubItems != null)
  3588.             {
  3589.                 for (int I2 = 0; I2 <= Math.Min(CI.SubItems.Count, _Columns.Count) - 1; I2++)
  3590.                 {
  3591.                     X = ColumnOffsets[I2 + 1] + 4;
  3592.  
  3593.                     R1.X = X;
  3594.                     R1.Width = Columns[I2 + 1].Width - 12;
  3595.                     G.SetClip(R1);
  3596.  
  3597.                     G.DrawString(CI.SubItems[I2].Text, Font, Brushes.Black, X + 1, Y + 1);
  3598.                     G.DrawString(CI.SubItems[I2].Text, Font, Brushes.White, X, Y);
  3599.                 }
  3600.             }
  3601.  
  3602.             G.ResetClip();
  3603.         }
  3604.  
  3605.         R1 = new Rectangle(0, 0, Width, ItemHeight);
  3606.  
  3607.         GB1 = new LinearGradientBrush(R1, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  3608.         G.FillRectangle(GB1, R1);
  3609.         G.DrawRectangle(P3, 1, 1, Width - 22, ItemHeight - 2);
  3610.  
  3611.         int LH = Math.Min(VS.Maximum + ItemHeight - Offset, Height);
  3612.  
  3613.         NSListViewColumnHeader CC = null;
  3614.         for (int I = 0; I <= _Columns.Count - 1; I++)
  3615.         {
  3616.             CC = Columns[I];
  3617.  
  3618.             H = G.MeasureString(CC.Text, Font).Height;
  3619.             Y = Convert.ToInt32((ItemHeight / 2) - (H / 2));
  3620.             X = ColumnOffsets[I];
  3621.  
  3622.             G.DrawString(CC.Text, Font, Brushes.Black, X + 1, Y + 1);
  3623.             G.DrawString(CC.Text, Font, Brushes.White, X, Y);
  3624.  
  3625.             G.DrawLine(P2, X - 3, 0, X - 3, LH);
  3626.             G.DrawLine(P3, X - 2, 0, X - 2, ItemHeight);
  3627.         }
  3628.  
  3629.         G.DrawRectangle(P2, 0, 0, Width - 1, Height - 1);
  3630.  
  3631.         G.DrawLine(P2, 0, ItemHeight, Width, ItemHeight);
  3632.         G.DrawLine(P2, VS.Location.X - 1, 0, VS.Location.X - 1, Height);
  3633.     }
  3634.  
  3635.     protected override void OnMouseWheel(MouseEventArgs e)
  3636.     {
  3637.         int Move = -((e.Delta * SystemInformation.MouseWheelScrollLines / 120) * (ItemHeight / 2));
  3638.  
  3639.         int Value = Math.Max(Math.Min(VS.Value + Move, VS.Maximum), VS.Minimum);
  3640.         VS.Value = Value;
  3641.  
  3642.         base.OnMouseWheel(e);
  3643.     }
  3644.  
  3645. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement