Advertisement
MaximeSony

Net Seal.cs Partie 1

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