Advertisement
Guest User

Untitled

a guest
May 7th, 2016
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 166.80 KB | None | 0 0
  1. namespace myForm
  2. {
  3.     using System;
  4.     using System.Windows.Forms;
  5.     using System.Drawing;
  6.     using System.Drawing.Drawing2D;
  7.     using System.Drawing.Text;
  8.     using System.ComponentModel;
  9.     using System.Text;
  10.     using System.Collections.Generic;
  11.  
  12. //IMPORTANT:
  13. //Please leave these comments in place as they help protect intellectual rights and allow
  14. //developers to determine the version of the theme they are using. The preffered method
  15. //of distributing this theme is through the Nimoru Software home page at nimoru.com.
  16.  
  17. //Name: Net Seal Theme
  18. //Created: 6/21/2013
  19. //Version: 1.0.0.2 beta
  20. //Site: http://nimoru.com/
  21.  
  22. //This work is licensed under a Creative Commons Attribution 3.0 Unported License.
  23. //To view a copy of this license, please visit http://creativecommons.org/licenses/by/3.0/
  24.  
  25. //Copyright � 2013 Nimoru Software
  26.  
  27.     static class ThemeModule
  28.     {
  29.  
  30.         static ThemeModule()
  31.         {
  32.             TextBitmap = new Bitmap(1, 1);
  33.             TextGraphics = Graphics.FromImage(TextBitmap);
  34.         }
  35.  
  36.         private static Bitmap TextBitmap;
  37.  
  38.         private static Graphics TextGraphics;
  39.  
  40.         static internal SizeF MeasureString(string text, Font font)
  41.         {
  42.             return TextGraphics.MeasureString(text, font);
  43.         }
  44.  
  45.         static internal SizeF MeasureString(string text, Font font, int width)
  46.         {
  47.             return TextGraphics.MeasureString(text, font, width, StringFormat.GenericTypographic);
  48.         }
  49.  
  50.         private static GraphicsPath CreateRoundPath;
  51.  
  52.         private static Rectangle CreateRoundRectangle;
  53.  
  54.         static internal GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
  55.         {
  56.             CreateRoundRectangle = new Rectangle(x, y, width, height);
  57.             return CreateRound(CreateRoundRectangle, slope);
  58.         }
  59.  
  60.         static internal GraphicsPath CreateRound(Rectangle r, int slope)
  61.         {
  62.             CreateRoundPath = new GraphicsPath(FillMode.Winding);
  63.             CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
  64.             CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
  65.             CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
  66.             CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
  67.             CreateRoundPath.CloseFigure();
  68.             return CreateRoundPath;
  69.         }
  70.  
  71.     }
  72.  
  73.     class NSTheme : ThemeContainer154
  74.     {
  75.  
  76.         private int _AccentOffset = 0;
  77.  
  78.         public int AccentOffset
  79.         {
  80.             get { return _AccentOffset; }
  81.             set
  82.             {
  83.                 _AccentOffset = value;
  84.                 Invalidate();
  85.             }
  86.         }
  87.  
  88.         public NSTheme()
  89.         {
  90.             Header = 30;
  91.             BackColor = Color.FromArgb(50, 50, 50);
  92.  
  93.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  94.             P2 = new Pen(Color.FromArgb(60, 60, 60));
  95.  
  96.             B1 = new SolidBrush(Color.FromArgb(50, 50, 50));
  97.         }
  98.  
  99.  
  100.         protected override void ColorHook()
  101.         {
  102.         }
  103.  
  104.  
  105.         private Rectangle R1;
  106.         private Pen P1;
  107.         private Pen P2;
  108.  
  109.         private SolidBrush B1;
  110.  
  111.         private int Pad;
  112.  
  113.         protected override void PaintHook()
  114.         {
  115.             G.Clear(BackColor);
  116.             DrawBorders(P2, 1);
  117.  
  118.             G.DrawLine(P1, 0, 26, Width, 26);
  119.             G.DrawLine(P2, 0, 25, Width, 25);
  120.  
  121.             Pad = Math.Max(Measure().Width + 20, 80);
  122.             R1 = new Rectangle(Pad, 17, Width - (Pad*2) + _AccentOffset, 8);
  123.  
  124.             G.DrawRectangle(P2, R1);
  125.             G.DrawRectangle(P1, R1.X + 1, R1.Y + 1, R1.Width - 2, R1.Height);
  126.  
  127.             G.DrawLine(P1, 0, 29, Width, 29);
  128.             G.DrawLine(P2, 0, 30, Width, 30);
  129.  
  130.             DrawText(Brushes.Black, HorizontalAlignment.Left, 8, 1);
  131.             DrawText(Brushes.White, HorizontalAlignment.Left, 7, 0);
  132.  
  133.             G.FillRectangle(B1, 0, 27, Width, 2);
  134.             DrawBorders(Pens.Black);
  135.         }
  136.  
  137.     }
  138.  
  139.     class NSButton : Control
  140.     {
  141.  
  142.         public NSButton()
  143.         {
  144.             SetStyle((ControlStyles) 139286, true);
  145.             SetStyle(ControlStyles.Selectable, false);
  146.  
  147.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  148.             P2 = new Pen(Color.FromArgb(65, 65, 65));
  149.         }
  150.  
  151.  
  152.         private bool IsMouseDown;
  153.         private GraphicsPath GP1;
  154.  
  155.         private GraphicsPath GP2;
  156.         private SizeF SZ1;
  157.  
  158.         private PointF PT1;
  159.         private Pen P1;
  160.  
  161.         private Pen P2;
  162.         private PathGradientBrush PB1;
  163.  
  164.         private LinearGradientBrush GB1;
  165.  
  166.         private Graphics G;
  167.  
  168.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  169.         {
  170.             G = e.Graphics;
  171.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  172.  
  173.             G.Clear(BackColor);
  174.             G.SmoothingMode = SmoothingMode.AntiAlias;
  175.  
  176.             GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  177.             GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  178.  
  179.             if (IsMouseDown)
  180.             {
  181.                 PB1 = new PathGradientBrush(GP1);
  182.                 PB1.CenterColor = Color.FromArgb(60, 60, 60);
  183.                 PB1.SurroundColors = new Color[] {Color.FromArgb(55, 55, 55)};
  184.                 PB1.FocusScales = new PointF(0.8f, 0.5f);
  185.  
  186.                 G.FillPath(PB1, GP1);
  187.             }
  188.             else
  189.             {
  190.                 GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55),
  191.                     90f);
  192.                 G.FillPath(GB1, GP1);
  193.             }
  194.  
  195.             G.DrawPath(P1, GP1);
  196.             G.DrawPath(P2, GP2);
  197.  
  198.             SZ1 = G.MeasureString(Text, Font);
  199.             PT1 = new PointF(5, Height/2 - SZ1.Height/2);
  200.  
  201.             if (IsMouseDown)
  202.             {
  203.                 PT1.X += 1f;
  204.                 PT1.Y += 1f;
  205.             }
  206.  
  207.             G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  208.             G.DrawString(Text, Font, Brushes.White, PT1);
  209.         }
  210.  
  211.         protected override void OnMouseDown(MouseEventArgs e)
  212.         {
  213.             IsMouseDown = true;
  214.             Invalidate();
  215.         }
  216.  
  217.         protected override void OnMouseUp(MouseEventArgs e)
  218.         {
  219.             IsMouseDown = false;
  220.             Invalidate();
  221.         }
  222.  
  223.     }
  224.  
  225.     class NSProgressBar : Control
  226.     {
  227.  
  228.         private int _Minimum;
  229.  
  230.         public int Minimum
  231.         {
  232.             get { return _Minimum; }
  233.             set
  234.             {
  235.                 if (value < 0)
  236.                 {
  237.                     throw new Exception("Property value is not valid.");
  238.                 }
  239.  
  240.                 _Minimum = value;
  241.                 if (value > _Value)
  242.                     _Value = value;
  243.                 if (value > _Maximum)
  244.                     _Maximum = value;
  245.                 Invalidate();
  246.             }
  247.         }
  248.  
  249.         private int _Maximum = 100;
  250.  
  251.         public int Maximum
  252.         {
  253.             get { return _Maximum; }
  254.             set
  255.             {
  256.                 if (value < 0)
  257.                 {
  258.                     throw new Exception("Property value is not valid.");
  259.                 }
  260.  
  261.                 _Maximum = value;
  262.                 if (value < _Value)
  263.                     _Value = value;
  264.                 if (value < _Minimum)
  265.                     _Minimum = value;
  266.                 Invalidate();
  267.             }
  268.         }
  269.  
  270.         private int _Value;
  271.  
  272.         public int Value
  273.         {
  274.             get { return _Value; }
  275.             set
  276.             {
  277.                 if (value > _Maximum || value < _Minimum)
  278.                 {
  279.                     throw new Exception("Property value is not valid.");
  280.                 }
  281.  
  282.                 _Value = value;
  283.                 Invalidate();
  284.             }
  285.         }
  286.  
  287.         private void Increment(int amount)
  288.         {
  289.             Value += amount;
  290.         }
  291.  
  292.         public NSProgressBar()
  293.         {
  294.             SetStyle((ControlStyles) 139286, true);
  295.             SetStyle(ControlStyles.Selectable, false);
  296.  
  297.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  298.             P2 = new Pen(Color.FromArgb(55, 55, 55));
  299.             B1 = new SolidBrush(Color.FromArgb(200, 160, 0));
  300.         }
  301.  
  302.         private GraphicsPath GP1;
  303.         private GraphicsPath GP2;
  304.  
  305.         private GraphicsPath GP3;
  306.         private Rectangle R1;
  307.  
  308.         private Rectangle R2;
  309.         private Pen P1;
  310.         private Pen P2;
  311.         private SolidBrush B1;
  312.         private LinearGradientBrush GB1;
  313.  
  314.         private LinearGradientBrush GB2;
  315.  
  316.         private int I1;
  317.         private Graphics G;
  318.  
  319.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  320.         {
  321.             G = e.Graphics;
  322.  
  323.             G.Clear(BackColor);
  324.             G.SmoothingMode = SmoothingMode.AntiAlias;
  325.  
  326.             GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  327.             GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  328.  
  329.             R1 = new Rectangle(0, 2, Width - 1, Height - 1);
  330.             GB1 = new LinearGradientBrush(R1, Color.FromArgb(45, 45, 45), Color.FromArgb(50, 50, 50), 90f);
  331.  
  332.             G.SetClip(GP1);
  333.             G.FillRectangle(GB1, R1);
  334.  
  335.             I1 = Convert.ToInt32((_Value - _Minimum)/(_Maximum - _Minimum)*(Width - 3));
  336.  
  337.             if (I1 > 1)
  338.             {
  339.                 GP3 = ThemeModule.CreateRound(1, 1, I1, Height - 3, 7);
  340.  
  341.                 R2 = new Rectangle(1, 1, I1, Height - 3);
  342.                 GB2 = new LinearGradientBrush(R2, Color.FromArgb(205, 150, 0), Color.FromArgb(150, 110, 0), 90f);
  343.  
  344.                 G.FillPath(GB2, GP3);
  345.                 G.DrawPath(P1, GP3);
  346.  
  347.                 G.SetClip(GP3);
  348.                 G.SmoothingMode = SmoothingMode.None;
  349.  
  350.                 G.FillRectangle(B1, R2.X, R2.Y + 1, R2.Width, R2.Height/2);
  351.  
  352.                 G.SmoothingMode = SmoothingMode.AntiAlias;
  353.                 G.ResetClip();
  354.             }
  355.  
  356.             G.DrawPath(P2, GP1);
  357.             G.DrawPath(P1, GP2);
  358.         }
  359.  
  360.     }
  361.  
  362.     class NSLabel : Control
  363.     {
  364.  
  365.         public NSLabel()
  366.         {
  367.             SetStyle((ControlStyles) 139286, true);
  368.             SetStyle(ControlStyles.Selectable, false);
  369.  
  370.             Font = new Font("Segoe UI", 11.25f, FontStyle.Bold);
  371.  
  372.             B1 = new SolidBrush(Color.FromArgb(205, 150, 0));
  373.         }
  374.  
  375.         private string _Value1 = "NET";
  376.  
  377.         public string Value1
  378.         {
  379.             get { return _Value1; }
  380.             set
  381.             {
  382.                 _Value1 = value;
  383.                 Invalidate();
  384.             }
  385.         }
  386.  
  387.         private string _Value2 = "SEAL";
  388.  
  389.         public string Value2
  390.         {
  391.             get { return _Value2; }
  392.             set
  393.             {
  394.                 _Value2 = value;
  395.                 Invalidate();
  396.             }
  397.         }
  398.  
  399.  
  400.         private SolidBrush B1;
  401.         private PointF PT1;
  402.         private PointF PT2;
  403.         private SizeF SZ1;
  404.  
  405.         private SizeF SZ2;
  406.         private Graphics G;
  407.  
  408.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  409.         {
  410.             G = e.Graphics;
  411.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  412.  
  413.             G.Clear(BackColor);
  414.  
  415.             SZ1 = G.MeasureString(Value1, Font, Width, StringFormat.GenericTypographic);
  416.             SZ2 = G.MeasureString(Value2, Font, Width, StringFormat.GenericTypographic);
  417.  
  418.             PT1 = new PointF(0, Height/2 - SZ1.Height/2);
  419.             PT2 = new PointF(SZ1.Width + 1, Height/2 - SZ1.Height/2);
  420.  
  421.             G.DrawString(Value1, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  422.             G.DrawString(Value1, Font, Brushes.White, PT1);
  423.  
  424.             G.DrawString(Value2, Font, Brushes.Black, PT2.X + 1, PT2.Y + 1);
  425.             G.DrawString(Value2, Font, B1, PT2);
  426.         }
  427.  
  428.     }
  429.  
  430.     [DefaultEvent("TextChanged")]
  431.     class NSTextBox : Control
  432.     {
  433.  
  434.         private HorizontalAlignment _TextAlign = HorizontalAlignment.Left;
  435.  
  436.         public HorizontalAlignment TextAlign
  437.         {
  438.             get { return _TextAlign; }
  439.             set
  440.             {
  441.                 _TextAlign = value;
  442.                 if (Base != null)
  443.                 {
  444.                     Base.TextAlign = value;
  445.                 }
  446.             }
  447.         }
  448.  
  449.         private int _MaxLength = 32767;
  450.  
  451.         public int MaxLength
  452.         {
  453.             get { return _MaxLength; }
  454.             set
  455.             {
  456.                 _MaxLength = value;
  457.                 if (Base != null)
  458.                 {
  459.                     Base.MaxLength = value;
  460.                 }
  461.             }
  462.         }
  463.  
  464.         private bool _ReadOnly;
  465.  
  466.         public bool ReadOnly
  467.         {
  468.             get { return _ReadOnly; }
  469.             set
  470.             {
  471.                 _ReadOnly = value;
  472.                 if (Base != null)
  473.                 {
  474.                     Base.ReadOnly = value;
  475.                 }
  476.             }
  477.         }
  478.  
  479.         private bool _UseSystemPasswordChar;
  480.  
  481.         public bool UseSystemPasswordChar
  482.         {
  483.             get { return _UseSystemPasswordChar; }
  484.             set
  485.             {
  486.                 _UseSystemPasswordChar = value;
  487.                 if (Base != null)
  488.                 {
  489.                     Base.UseSystemPasswordChar = value;
  490.                 }
  491.             }
  492.         }
  493.  
  494.         private bool _Multiline;
  495.  
  496.         public bool Multiline
  497.         {
  498.             get { return _Multiline; }
  499.             set
  500.             {
  501.                 _Multiline = value;
  502.                 if (Base != null)
  503.                 {
  504.                     Base.Multiline = value;
  505.  
  506.                     if (value)
  507.                     {
  508.                         Base.Height = Height - 11;
  509.                     }
  510.                     else
  511.                     {
  512.                         Height = Base.Height + 11;
  513.                     }
  514.                 }
  515.             }
  516.         }
  517.  
  518.         public override string Text
  519.         {
  520.             get { return base.Text; }
  521.             set
  522.             {
  523.                 base.Text = value;
  524.                 if (Base != null)
  525.                 {
  526.                     Base.Text = value;
  527.                 }
  528.             }
  529.         }
  530.  
  531.         public override Font Font
  532.         {
  533.             get { return base.Font; }
  534.             set
  535.             {
  536.                 base.Font = value;
  537.                 if (Base != null)
  538.                 {
  539.                     Base.Font = value;
  540.                     Base.Location = new Point(5, 5);
  541.                     Base.Width = Width - 8;
  542.  
  543.                     if (!_Multiline)
  544.                     {
  545.                         Height = Base.Height + 11;
  546.                     }
  547.                 }
  548.             }
  549.         }
  550.  
  551.         protected override void OnHandleCreated(EventArgs e)
  552.         {
  553.             if (!Controls.Contains(Base))
  554.             {
  555.                 Controls.Add(Base);
  556.             }
  557.  
  558.             base.OnHandleCreated(e);
  559.         }
  560.  
  561.         private TextBox Base;
  562.  
  563.         public NSTextBox()
  564.         {
  565.             SetStyle((ControlStyles) 139286, true);
  566.             SetStyle(ControlStyles.Selectable, true);
  567.  
  568.             Cursor = Cursors.IBeam;
  569.  
  570.             Base = new TextBox();
  571.             Base.Font = Font;
  572.             Base.Text = Text;
  573.             Base.MaxLength = _MaxLength;
  574.             Base.Multiline = _Multiline;
  575.             Base.ReadOnly = _ReadOnly;
  576.             Base.UseSystemPasswordChar = _UseSystemPasswordChar;
  577.  
  578.             Base.ForeColor = Color.White;
  579.             Base.BackColor = Color.FromArgb(50, 50, 50);
  580.  
  581.             Base.BorderStyle = BorderStyle.None;
  582.  
  583.             Base.Location = new Point(5, 5);
  584.             Base.Width = Width - 14;
  585.  
  586.             if (_Multiline)
  587.             {
  588.                 Base.Height = Height - 11;
  589.             }
  590.             else
  591.             {
  592.                 Height = Base.Height + 11;
  593.             }
  594.  
  595.             Base.TextChanged += OnBaseTextChanged;
  596.             Base.KeyDown += OnBaseKeyDown;
  597.  
  598.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  599.             P2 = new Pen(Color.FromArgb(55, 55, 55));
  600.         }
  601.  
  602.         private GraphicsPath GP1;
  603.  
  604.         private GraphicsPath GP2;
  605.         private Pen P1;
  606.         private Pen P2;
  607.  
  608.         private PathGradientBrush PB1;
  609.         private Graphics G;
  610.  
  611.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  612.         {
  613.             G = e.Graphics;
  614.  
  615.             G.Clear(BackColor);
  616.             G.SmoothingMode = SmoothingMode.AntiAlias;
  617.  
  618.             GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  619.             GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  620.  
  621.             PB1 = new PathGradientBrush(GP1);
  622.             PB1.CenterColor = Color.FromArgb(50, 50, 50);
  623.             PB1.SurroundColors = new Color[] {Color.FromArgb(45, 45, 45)};
  624.             PB1.FocusScales = new PointF(0.9f, 0.5f);
  625.  
  626.             G.FillPath(PB1, GP1);
  627.  
  628.             G.DrawPath(P2, GP1);
  629.             G.DrawPath(P1, GP2);
  630.         }
  631.  
  632.         private void OnBaseTextChanged(object s, EventArgs e)
  633.         {
  634.             Text = Base.Text;
  635.         }
  636.  
  637.         private void OnBaseKeyDown(object s, KeyEventArgs e)
  638.         {
  639.             if (e.Control && e.KeyCode == Keys.A)
  640.             {
  641.                 Base.SelectAll();
  642.                 e.SuppressKeyPress = true;
  643.             }
  644.             if (e.KeyCode == Keys.Enter)
  645.             {
  646.                 e.SuppressKeyPress = true;
  647.             }
  648.         }
  649.  
  650.         protected override void OnResize(EventArgs e)
  651.         {
  652.             Base.Location = new Point(5, 5);
  653.  
  654.             Base.Width = Width - 10;
  655.             Base.Height = Height - 11;
  656.  
  657.             base.OnResize(e);
  658.         }
  659.  
  660.         protected override void OnMouseDown(MouseEventArgs e)
  661.         {
  662.             Base.Focus();
  663.             base.OnMouseDown(e);
  664.         }
  665.  
  666.         protected override void OnEnter(EventArgs e)
  667.         {
  668.             Base.Focus();
  669.             Invalidate();
  670.             base.OnEnter(e);
  671.         }
  672.  
  673.         protected override void OnLeave(EventArgs e)
  674.         {
  675.             Invalidate();
  676.             base.OnLeave(e);
  677.         }
  678.  
  679.     }
  680.  
  681.     [DefaultEvent("CheckedChanged")]
  682.     class NSCheckBox : Control
  683.     {
  684.  
  685.         public event CheckedChangedEventHandler CheckedChanged;
  686.  
  687.         public delegate void CheckedChangedEventHandler(object sender);
  688.  
  689.         public NSCheckBox()
  690.         {
  691.             SetStyle((ControlStyles) 139286, true);
  692.             SetStyle(ControlStyles.Selectable, false);
  693.  
  694.             P11 = new Pen(Color.FromArgb(55, 55, 55));
  695.             P22 = new Pen(Color.FromArgb(35, 35, 35));
  696.             P3 = new Pen(Color.Black, 2f);
  697.             P4 = new Pen(Color.White, 2f);
  698.         }
  699.  
  700.         private bool _Checked;
  701.  
  702.         public bool Checked
  703.         {
  704.             get { return _Checked; }
  705.             set
  706.             {
  707.                 _Checked = value;
  708.                 if (CheckedChanged != null)
  709.                 {
  710.                     CheckedChanged(this);
  711.                 }
  712.  
  713.                 Invalidate();
  714.             }
  715.         }
  716.  
  717.         private GraphicsPath GP1;
  718.  
  719.         private GraphicsPath GP2;
  720.         private SizeF SZ1;
  721.  
  722.         private PointF PT1;
  723.         private Pen P11;
  724.         private Pen P22;
  725.         private Pen P3;
  726.  
  727.         private Pen P4;
  728.  
  729.         private PathGradientBrush PB1;
  730.         private Graphics G;
  731.  
  732.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  733.         {
  734.             G = e.Graphics;
  735.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  736.  
  737.             G.Clear(BackColor);
  738.             G.SmoothingMode = SmoothingMode.AntiAlias;
  739.  
  740.             GP1 = ThemeModule.CreateRound(0, 2, Height - 5, Height - 5, 5);
  741.             GP2 = ThemeModule.CreateRound(1, 3, Height - 7, Height - 7, 5);
  742.  
  743.             PB1 = new PathGradientBrush(GP1);
  744.             PB1.CenterColor = Color.FromArgb(50, 50, 50);
  745.             PB1.SurroundColors = new Color[] {Color.FromArgb(45, 45, 45)};
  746.             PB1.FocusScales = new PointF(0.3f, 0.3f);
  747.  
  748.             G.FillPath(PB1, GP1);
  749.             G.DrawPath(P11, GP1);
  750.             G.DrawPath(P22, GP2);
  751.  
  752.             if (_Checked)
  753.             {
  754.                 G.DrawLine(P3, 5, Height - 9, 8, Height - 7);
  755.                 G.DrawLine(P3, 7, Height - 7, Height - 8, 7);
  756.  
  757.                 G.DrawLine(P4, 4, Height - 10, 7, Height - 8);
  758.                 G.DrawLine(P4, 6, Height - 8, Height - 9, 6);
  759.             }
  760.  
  761.             SZ1 = G.MeasureString(Text, Font);
  762.             PT1 = new PointF(Height - 3, Height/2 - SZ1.Height/2);
  763.  
  764.             G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  765.             G.DrawString(Text, Font, Brushes.White, PT1);
  766.         }
  767.  
  768.         protected override void OnMouseDown(MouseEventArgs e)
  769.         {
  770.             Checked = !Checked;
  771.         }
  772.  
  773.     }
  774.  
  775.     [DefaultEvent("CheckedChanged")]
  776.     class NSRadioButton : Control
  777.     {
  778.  
  779.         public event CheckedChangedEventHandler CheckedChanged;
  780.  
  781.         public delegate void CheckedChangedEventHandler(object sender);
  782.  
  783.         public NSRadioButton()
  784.         {
  785.             SetStyle((ControlStyles) 139286, true);
  786.             SetStyle(ControlStyles.Selectable, false);
  787.  
  788.             P1 = new Pen(Color.FromArgb(55, 55, 55));
  789.             P2 = new Pen(Color.FromArgb(35, 35, 35));
  790.         }
  791.  
  792.         private bool _Checked;
  793.  
  794.         public bool Checked
  795.         {
  796.             get { return _Checked; }
  797.             set
  798.             {
  799.                 _Checked = value;
  800.  
  801.                 if (_Checked)
  802.                 {
  803.                     InvalidateParent();
  804.                 }
  805.  
  806.                 if (CheckedChanged != null)
  807.                 {
  808.                     CheckedChanged(this);
  809.                 }
  810.                 Invalidate();
  811.             }
  812.         }
  813.  
  814.         private void InvalidateParent()
  815.         {
  816.             if (Parent == null)
  817.                 return;
  818.  
  819.             foreach (Control C in Parent.Controls)
  820.             {
  821.                 if ((!object.ReferenceEquals(C, this)) && (C is NSRadioButton))
  822.                 {
  823.                     ((NSRadioButton) C).Checked = false;
  824.                 }
  825.             }
  826.         }
  827.  
  828.  
  829.         private GraphicsPath GP1;
  830.         private SizeF SZ1;
  831.  
  832.         private PointF PT1;
  833.         private Pen P1;
  834.  
  835.         private Pen P2;
  836.  
  837.         private PathGradientBrush PB1;
  838.         private Graphics G;
  839.  
  840.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  841.         {
  842.             G = e.Graphics;
  843.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  844.  
  845.             G.Clear(BackColor);
  846.             G.SmoothingMode = SmoothingMode.AntiAlias;
  847.  
  848.             GP1 = new GraphicsPath();
  849.             GP1.AddEllipse(0, 2, Height - 5, Height - 5);
  850.  
  851.             PB1 = new PathGradientBrush(GP1);
  852.             PB1.CenterColor = Color.FromArgb(50, 50, 50);
  853.             PB1.SurroundColors = new Color[] {Color.FromArgb(45, 45, 45)};
  854.             PB1.FocusScales = new PointF(0.3f, 0.3f);
  855.  
  856.             G.FillPath(PB1, GP1);
  857.  
  858.             G.DrawEllipse(P1, 0, 2, Height - 5, Height - 5);
  859.             G.DrawEllipse(P2, 1, 3, Height - 7, Height - 7);
  860.  
  861.             if (_Checked)
  862.             {
  863.                 G.FillEllipse(Brushes.Black, 6, 8, Height - 15, Height - 15);
  864.                 G.FillEllipse(Brushes.White, 5, 7, Height - 15, Height - 15);
  865.             }
  866.  
  867.             SZ1 = G.MeasureString(Text, Font);
  868.             PT1 = new PointF(Height - 3, Height/2 - SZ1.Height/2);
  869.  
  870.             G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  871.             G.DrawString(Text, Font, Brushes.White, PT1);
  872.         }
  873.  
  874.         protected override void OnMouseDown(MouseEventArgs e)
  875.         {
  876.             Checked = true;
  877.             base.OnMouseDown(e);
  878.         }
  879.  
  880.     }
  881.  
  882.     class NSComboBox : ComboBox
  883.     {
  884.  
  885.         public NSComboBox()
  886.         {
  887.             SetStyle((ControlStyles) 139286, true);
  888.             SetStyle(ControlStyles.Selectable, false);
  889.  
  890.             DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
  891.             DropDownStyle = ComboBoxStyle.DropDownList;
  892.  
  893.             BackColor = Color.FromArgb(50, 50, 50);
  894.             ForeColor = Color.White;
  895.  
  896.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  897.             P2 = new Pen(Color.White, 2f);
  898.             P3 = new Pen(Brushes.Black, 2f);
  899.             P4 = new Pen(Color.FromArgb(65, 65, 65));
  900.  
  901.             B1 = new SolidBrush(Color.FromArgb(65, 65, 65));
  902.             B2 = new SolidBrush(Color.FromArgb(55, 55, 55));
  903.         }
  904.  
  905.         private GraphicsPath GP1;
  906.  
  907.         private GraphicsPath GP2;
  908.         private SizeF SZ1;
  909.  
  910.         private PointF PT1;
  911.         private Pen P1;
  912.         private Pen P2;
  913.         private Pen P3;
  914.         private Pen P4;
  915.         private SolidBrush B1;
  916.  
  917.         private SolidBrush B2;
  918.  
  919.         private LinearGradientBrush GB1;
  920.         private Graphics G;
  921.  
  922.         protected override void OnPaint(PaintEventArgs e)
  923.         {
  924.             G = e.Graphics;
  925.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  926.  
  927.             G.Clear(BackColor);
  928.             G.SmoothingMode = SmoothingMode.AntiAlias;
  929.  
  930.             GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  931.             GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  932.  
  933.             GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  934.             G.SetClip(GP1);
  935.             G.FillRectangle(GB1, ClientRectangle);
  936.             G.ResetClip();
  937.  
  938.             G.DrawPath(P1, GP1);
  939.             G.DrawPath(P4, GP2);
  940.  
  941.             SZ1 = G.MeasureString(Text, Font);
  942.             PT1 = new PointF(5, Height/2 - SZ1.Height/2);
  943.  
  944.             G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  945.             G.DrawString(Text, Font, Brushes.White, PT1);
  946.  
  947.             G.DrawLine(P3, Width - 15, 10, Width - 11, 13);
  948.             G.DrawLine(P3, Width - 7, 10, Width - 11, 13);
  949.             G.DrawLine(Pens.Black, Width - 11, 13, Width - 11, 14);
  950.  
  951.             G.DrawLine(P2, Width - 16, 9, Width - 12, 12);
  952.             G.DrawLine(P2, Width - 8, 9, Width - 12, 12);
  953.             G.DrawLine(Pens.White, Width - 12, 12, Width - 12, 13);
  954.  
  955.             G.DrawLine(P1, Width - 22, 0, Width - 22, Height);
  956.             G.DrawLine(P4, Width - 23, 1, Width - 23, Height - 2);
  957.             G.DrawLine(P4, Width - 21, 1, Width - 21, Height - 2);
  958.         }
  959.  
  960.         protected override void OnDrawItem(DrawItemEventArgs e)
  961.         {
  962.             e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  963.  
  964.             if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
  965.             {
  966.                 e.Graphics.FillRectangle(B1, e.Bounds);
  967.             }
  968.             else
  969.             {
  970.                 e.Graphics.FillRectangle(B2, e.Bounds);
  971.             }
  972.  
  973.             if (!(e.Index == -1))
  974.             {
  975.                 e.Graphics.DrawString(GetItemText(Items[e.Index]), e.Font, Brushes.White, e.Bounds);
  976.             }
  977.         }
  978.  
  979.     }
  980.  
  981.     class NSTabControl : TabControl
  982.     {
  983.  
  984.         public NSTabControl()
  985.         {
  986.             SetStyle((ControlStyles) 139286, true);
  987.             SetStyle(ControlStyles.Selectable, false);
  988.  
  989.             SizeMode = TabSizeMode.Fixed;
  990.             Alignment = TabAlignment.Left;
  991.             ItemSize = new Size(28, 115);
  992.  
  993.             DrawMode = TabDrawMode.OwnerDrawFixed;
  994.  
  995.             P1 = new Pen(Color.FromArgb(55, 55, 55));
  996.             P2 = new Pen(Color.FromArgb(35, 35, 35));
  997.             P3 = new Pen(Color.FromArgb(45, 45, 45), 2);
  998.  
  999.             B1 = new SolidBrush(Color.FromArgb(50, 50, 50));
  1000.             B2 = new SolidBrush(Color.FromArgb(35, 35, 35));
  1001.             B3 = new SolidBrush(Color.FromArgb(205, 150, 0));
  1002.             B4 = new SolidBrush(Color.FromArgb(65, 65, 65));
  1003.  
  1004.             SF1 = new StringFormat();
  1005.             SF1.LineAlignment = StringAlignment.Center;
  1006.         }
  1007.  
  1008.         protected override void OnControlAdded(ControlEventArgs e)
  1009.         {
  1010.             if (e.Control is TabPage)
  1011.             {
  1012.                 e.Control.BackColor = Color.FromArgb(50, 50, 50);
  1013.             }
  1014.  
  1015.             base.OnControlAdded(e);
  1016.         }
  1017.  
  1018.         private GraphicsPath GP1;
  1019.         private GraphicsPath GP2;
  1020.         private GraphicsPath GP3;
  1021.  
  1022.         private GraphicsPath GP4;
  1023.         private Rectangle R1;
  1024.  
  1025.         private Rectangle R2;
  1026.         private Pen P1;
  1027.         private Pen P2;
  1028.         private Pen P3;
  1029.         private SolidBrush B1;
  1030.         private SolidBrush B2;
  1031.         private SolidBrush B3;
  1032.  
  1033.         private SolidBrush B4;
  1034.  
  1035.         private PathGradientBrush PB1;
  1036.         private TabPage TP1;
  1037.  
  1038.         private StringFormat SF1;
  1039.         private int Offset;
  1040.  
  1041.         private int ItemHeight;
  1042.         private Graphics G;
  1043.  
  1044.         protected override void OnPaint(PaintEventArgs e)
  1045.         {
  1046.             G = e.Graphics;
  1047.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  1048.  
  1049.             G.Clear(Color.FromArgb(50, 50, 50));
  1050.             G.SmoothingMode = SmoothingMode.AntiAlias;
  1051.  
  1052.             ItemHeight = ItemSize.Height + 2;
  1053.  
  1054.             GP1 = ThemeModule.CreateRound(0, 0, ItemHeight + 3, Height - 1, 7);
  1055.             GP2 = ThemeModule.CreateRound(1, 1, ItemHeight + 3, Height - 3, 7);
  1056.  
  1057.             PB1 = new PathGradientBrush(GP1);
  1058.             PB1.CenterColor = Color.FromArgb(50, 50, 50);
  1059.             PB1.SurroundColors = new Color[] {Color.FromArgb(45, 45, 45)};
  1060.             PB1.FocusScales = new PointF(0.8f, 0.95f);
  1061.  
  1062.             G.FillPath(PB1, GP1);
  1063.  
  1064.             G.DrawPath(P1, GP1);
  1065.             G.DrawPath(P2, GP2);
  1066.  
  1067.             for (int I = 0; I <= TabCount - 1; I++)
  1068.             {
  1069.                 R1 = GetTabRect(I);
  1070.                 R1.Y += 2;
  1071.                 R1.Height -= 3;
  1072.                 R1.Width += 1;
  1073.                 R1.X -= 1;
  1074.  
  1075.                 TP1 = TabPages[I];
  1076.                 Offset = 0;
  1077.  
  1078.                 if (SelectedIndex == I)
  1079.                 {
  1080.                     G.FillRectangle(B1, R1);
  1081.  
  1082.                     for (int J = 0; J <= 1; J++)
  1083.                     {
  1084.                         G.FillRectangle(B2, R1.X + 5 + (J*5), R1.Y + 6, 2, R1.Height - 9);
  1085.  
  1086.                         G.SmoothingMode = SmoothingMode.None;
  1087.                         G.FillRectangle(B3, R1.X + 5 + (J*5), R1.Y + 5, 2, R1.Height - 9);
  1088.                         G.SmoothingMode = SmoothingMode.AntiAlias;
  1089.  
  1090.                         Offset += 5;
  1091.                     }
  1092.  
  1093.                     G.DrawRectangle(P3, R1.X + 1, R1.Y - 1, R1.Width, R1.Height + 2);
  1094.                     G.DrawRectangle(P1, R1.X + 1, R1.Y + 1, R1.Width - 2, R1.Height - 2);
  1095.                     G.DrawRectangle(P2, R1);
  1096.                 }
  1097.                 else
  1098.                 {
  1099.                     for (int J = 0; J <= 1; J++)
  1100.                     {
  1101.                         G.FillRectangle(B2, R1.X + 5 + (J*5), R1.Y + 6, 2, R1.Height - 9);
  1102.  
  1103.                         G.SmoothingMode = SmoothingMode.None;
  1104.                         G.FillRectangle(B4, R1.X + 5 + (J*5), R1.Y + 5, 2, R1.Height - 9);
  1105.                         G.SmoothingMode = SmoothingMode.AntiAlias;
  1106.  
  1107.                         Offset += 5;
  1108.                     }
  1109.                 }
  1110.  
  1111.                 R1.X += 5 + Offset;
  1112.  
  1113.                 R2 = R1;
  1114.                 R2.Y += 1;
  1115.                 R2.X += 1;
  1116.  
  1117.                 G.DrawString(TP1.Text, Font, Brushes.Black, R2, SF1);
  1118.                 G.DrawString(TP1.Text, Font, Brushes.White, R1, SF1);
  1119.             }
  1120.  
  1121.             GP3 = ThemeModule.CreateRound(ItemHeight, 0, Width - ItemHeight - 1, Height - 1, 7);
  1122.             GP4 = ThemeModule.CreateRound(ItemHeight + 1, 1, Width - ItemHeight - 3, Height - 3, 7);
  1123.  
  1124.             G.DrawPath(P2, GP3);
  1125.             G.DrawPath(P1, GP4);
  1126.         }
  1127.  
  1128.     }
  1129.  
  1130.     [DefaultEvent("CheckedChanged")]
  1131.     class NSOnOffBox : Control
  1132.     {
  1133.  
  1134.         public event CheckedChangedEventHandler CheckedChanged;
  1135.  
  1136.         public delegate void CheckedChangedEventHandler(object sender);
  1137.  
  1138.         public NSOnOffBox()
  1139.         {
  1140.             SetStyle((ControlStyles) 139286, true);
  1141.             SetStyle(ControlStyles.Selectable, false);
  1142.  
  1143.             P1 = new Pen(Color.FromArgb(55, 55, 55));
  1144.             P2 = new Pen(Color.FromArgb(35, 35, 35));
  1145.             P3 = new Pen(Color.FromArgb(65, 65, 65));
  1146.  
  1147.             B1 = new SolidBrush(Color.FromArgb(35, 35, 35));
  1148.             B2 = new SolidBrush(Color.FromArgb(85, 85, 85));
  1149.             B3 = new SolidBrush(Color.FromArgb(65, 65, 65));
  1150.             B4 = new SolidBrush(Color.FromArgb(205, 150, 0));
  1151.             B5 = new SolidBrush(Color.FromArgb(40, 40, 40));
  1152.  
  1153.             SF1 = new StringFormat();
  1154.             SF1.LineAlignment = StringAlignment.Center;
  1155.             SF1.Alignment = StringAlignment.Near;
  1156.  
  1157.             SF2 = new StringFormat();
  1158.             SF2.LineAlignment = StringAlignment.Center;
  1159.             SF2.Alignment = StringAlignment.Far;
  1160.  
  1161.             Size = new Size(56, 24);
  1162.             MinimumSize = Size;
  1163.             MaximumSize = Size;
  1164.         }
  1165.  
  1166.         private bool _Checked;
  1167.  
  1168.         public bool Checked
  1169.         {
  1170.             get { return _Checked; }
  1171.             set
  1172.             {
  1173.                 _Checked = value;
  1174.                 if (CheckedChanged != null)
  1175.                 {
  1176.                     CheckedChanged(this);
  1177.                 }
  1178.  
  1179.                 Invalidate();
  1180.             }
  1181.         }
  1182.  
  1183.         private GraphicsPath GP1;
  1184.         private GraphicsPath GP2;
  1185.         private GraphicsPath GP3;
  1186.  
  1187.         private GraphicsPath GP4;
  1188.         private Pen P1;
  1189.         private Pen P2;
  1190.         private Pen P3;
  1191.         private SolidBrush B1;
  1192.         private SolidBrush B2;
  1193.         private SolidBrush B3;
  1194.         private SolidBrush B4;
  1195.  
  1196.         private SolidBrush B5;
  1197.         private PathGradientBrush PB1;
  1198.  
  1199.         private LinearGradientBrush GB1;
  1200.         private Rectangle R1;
  1201.         private Rectangle R2;
  1202.         private Rectangle R3;
  1203.         private StringFormat SF1;
  1204.  
  1205.         private StringFormat SF2;
  1206.  
  1207.         private int Offset;
  1208.         private Graphics G;
  1209.  
  1210.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  1211.         {
  1212.             G = e.Graphics;
  1213.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  1214.  
  1215.             G.Clear(BackColor);
  1216.             G.SmoothingMode = SmoothingMode.AntiAlias;
  1217.  
  1218.             GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  1219.             GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  1220.  
  1221.             PB1 = new PathGradientBrush(GP1);
  1222.             PB1.CenterColor = Color.FromArgb(50, 50, 50);
  1223.             PB1.SurroundColors = new Color[] {Color.FromArgb(45, 45, 45)};
  1224.             PB1.FocusScales = new PointF(0.3f, 0.3f);
  1225.  
  1226.             G.FillPath(PB1, GP1);
  1227.             G.DrawPath(P1, GP1);
  1228.             G.DrawPath(P2, GP2);
  1229.  
  1230.             R1 = new Rectangle(5, 0, Width - 10, Height + 2);
  1231.             R2 = new Rectangle(6, 1, Width - 10, Height + 2);
  1232.  
  1233.             R3 = new Rectangle(1, 1, (Width/2) - 1, Height - 3);
  1234.  
  1235.             if (_Checked)
  1236.             {
  1237.                 G.DrawString("On", Font, Brushes.Black, R2, SF1);
  1238.                 G.DrawString("On", Font, Brushes.White, R1, SF1);
  1239.  
  1240.                 R3.X += (Width/2) - 1;
  1241.             }
  1242.             else
  1243.             {
  1244.                 G.DrawString("Off", Font, B1, R2, SF2);
  1245.                 G.DrawString("Off", Font, B2, R1, SF2);
  1246.             }
  1247.  
  1248.             GP3 = ThemeModule.CreateRound(R3, 7);
  1249.             GP4 = ThemeModule.CreateRound(R3.X + 1, R3.Y + 1, R3.Width - 2, R3.Height - 2, 7);
  1250.  
  1251.             GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  1252.  
  1253.             G.FillPath(GB1, GP3);
  1254.             G.DrawPath(P2, GP3);
  1255.             G.DrawPath(P3, GP4);
  1256.  
  1257.             Offset = R3.X + (R3.Width/2) - 3;
  1258.  
  1259.             for (int I = 0; I <= 1; I++)
  1260.             {
  1261.                 if (_Checked)
  1262.                 {
  1263.                     G.FillRectangle(B1, Offset + (I*5), 7, 2, Height - 14);
  1264.                 }
  1265.                 else
  1266.                 {
  1267.                     G.FillRectangle(B3, Offset + (I*5), 7, 2, Height - 14);
  1268.                 }
  1269.  
  1270.                 G.SmoothingMode = SmoothingMode.None;
  1271.  
  1272.                 if (_Checked)
  1273.                 {
  1274.                     G.FillRectangle(B4, Offset + (I*5), 7, 2, Height - 14);
  1275.                 }
  1276.                 else
  1277.                 {
  1278.                     G.FillRectangle(B5, Offset + (I*5), 7, 2, Height - 14);
  1279.                 }
  1280.  
  1281.                 G.SmoothingMode = SmoothingMode.AntiAlias;
  1282.             }
  1283.         }
  1284.  
  1285.         protected override void OnMouseDown(MouseEventArgs e)
  1286.         {
  1287.             Checked = !Checked;
  1288.             base.OnMouseDown(e);
  1289.         }
  1290.  
  1291.     }
  1292.  
  1293.     class NSControlButton : Control
  1294.     {
  1295.  
  1296.         public enum Button : byte
  1297.         {
  1298.             None = 0,
  1299.             Minimize = 1,
  1300.             MaximizeRestore = 2,
  1301.             Close = 3
  1302.         }
  1303.  
  1304.         private Button _ControlButton = Button.Close;
  1305.  
  1306.         public Button ControlButton
  1307.         {
  1308.             get { return _ControlButton; }
  1309.             set
  1310.             {
  1311.                 _ControlButton = value;
  1312.                 Invalidate();
  1313.             }
  1314.         }
  1315.  
  1316.         public NSControlButton()
  1317.         {
  1318.             SetStyle((ControlStyles) 139286, true);
  1319.             SetStyle(ControlStyles.Selectable, false);
  1320.  
  1321.             Anchor = AnchorStyles.Top | AnchorStyles.Right;
  1322.  
  1323.             Width = 18;
  1324.             Height = 20;
  1325.  
  1326.             MinimumSize = Size;
  1327.             MaximumSize = Size;
  1328.  
  1329.             Margin = new Padding(0);
  1330.         }
  1331.  
  1332.         private Graphics G;
  1333.  
  1334.         protected override void OnPaint(PaintEventArgs e)
  1335.         {
  1336.             G = e.Graphics;
  1337.             G.Clear(BackColor);
  1338.  
  1339.             switch (_ControlButton)
  1340.             {
  1341.                 case Button.Minimize:
  1342.                     DrawMinimize(3, 10);
  1343.                     break;
  1344.                 case Button.MaximizeRestore:
  1345.                     if (FindForm().WindowState == FormWindowState.Normal)
  1346.                     {
  1347.                         DrawMaximize(3, 5);
  1348.                     }
  1349.                     else
  1350.                     {
  1351.                         DrawRestore(3, 4);
  1352.                     }
  1353.                     break;
  1354.                 case Button.Close:
  1355.                     DrawClose(4, 5);
  1356.                     break;
  1357.             }
  1358.         }
  1359.  
  1360.         private void DrawMinimize(int x, int y)
  1361.         {
  1362.             G.FillRectangle(Brushes.White, x, y, 12, 5);
  1363.             G.DrawRectangle(Pens.Black, x, y, 11, 4);
  1364.         }
  1365.  
  1366.         private void DrawMaximize(int x, int y)
  1367.         {
  1368.             G.DrawRectangle(new Pen(Color.White, 2), x + 2, y + 2, 8, 6);
  1369.             G.DrawRectangle(Pens.Black, x, y, 11, 9);
  1370.             G.DrawRectangle(Pens.Black, x + 3, y + 3, 5, 3);
  1371.         }
  1372.  
  1373.         private void DrawRestore(int x, int y)
  1374.         {
  1375.             G.FillRectangle(Brushes.White, x + 3, y + 1, 8, 4);
  1376.             G.FillRectangle(Brushes.White, x + 7, y + 5, 4, 4);
  1377.             G.DrawRectangle(Pens.Black, x + 2, y + 0, 9, 9);
  1378.  
  1379.             G.FillRectangle(Brushes.White, x + 1, y + 3, 2, 6);
  1380.             G.FillRectangle(Brushes.White, x + 1, y + 9, 8, 2);
  1381.             G.DrawRectangle(Pens.Black, x, y + 2, 9, 9);
  1382.             G.DrawRectangle(Pens.Black, x + 3, y + 5, 3, 3);
  1383.         }
  1384.  
  1385.         private GraphicsPath ClosePath;
  1386.  
  1387.         private void DrawClose(int x, int y)
  1388.         {
  1389.             if (ClosePath == null)
  1390.             {
  1391.                 ClosePath = new GraphicsPath();
  1392.                 ClosePath.AddLine(x + 1, y, x + 3, y);
  1393.                 ClosePath.AddLine(x + 5, y + 2, x + 7, y);
  1394.                 ClosePath.AddLine(x + 9, y, x + 10, y + 1);
  1395.                 ClosePath.AddLine(x + 7, y + 4, x + 7, y + 5);
  1396.                 ClosePath.AddLine(x + 10, y + 8, x + 9, y + 9);
  1397.                 ClosePath.AddLine(x + 7, y + 9, x + 5, y + 7);
  1398.                 ClosePath.AddLine(x + 3, y + 9, x + 1, y + 9);
  1399.                 ClosePath.AddLine(x + 0, y + 8, x + 3, y + 5);
  1400.                 ClosePath.AddLine(x + 3, y + 4, x + 0, y + 1);
  1401.             }
  1402.  
  1403.             G.FillPath(Brushes.White, ClosePath);
  1404.             G.DrawPath(Pens.Black, ClosePath);
  1405.         }
  1406.  
  1407.         protected override void OnMouseClick(MouseEventArgs e)
  1408.         {
  1409.  
  1410.             if (e.Button == System.Windows.Forms.MouseButtons.Left)
  1411.             {
  1412.                 Form F = FindForm();
  1413.  
  1414.                 switch (_ControlButton)
  1415.                 {
  1416.                     case Button.Minimize:
  1417.                         F.WindowState = FormWindowState.Minimized;
  1418.                         break;
  1419.                     case Button.MaximizeRestore:
  1420.                         if (F.WindowState == FormWindowState.Normal)
  1421.                         {
  1422.                             F.WindowState = FormWindowState.Maximized;
  1423.                         }
  1424.                         else
  1425.                         {
  1426.                             F.WindowState = FormWindowState.Normal;
  1427.                         }
  1428.                         break;
  1429.                     case Button.Close:
  1430.                         F.Close();
  1431.                         break;
  1432.                 }
  1433.  
  1434.             }
  1435.  
  1436.             Invalidate();
  1437.             base.OnMouseClick(e);
  1438.         }
  1439.  
  1440.     }
  1441.  
  1442.     class NSGroupBox : ContainerControl
  1443.     {
  1444.  
  1445.         private bool _DrawSeperator;
  1446.  
  1447.         public bool DrawSeperator
  1448.         {
  1449.             get { return _DrawSeperator; }
  1450.             set
  1451.             {
  1452.                 _DrawSeperator = value;
  1453.                 Invalidate();
  1454.             }
  1455.         }
  1456.  
  1457.         private string _Title = "GroupBox";
  1458.  
  1459.         public string Title
  1460.         {
  1461.             get { return _Title; }
  1462.             set
  1463.             {
  1464.                 _Title = value;
  1465.                 Invalidate();
  1466.             }
  1467.         }
  1468.  
  1469.         private string _SubTitle = "Details";
  1470.  
  1471.         public string SubTitle
  1472.         {
  1473.             get { return _SubTitle; }
  1474.             set
  1475.             {
  1476.                 _SubTitle = value;
  1477.                 Invalidate();
  1478.             }
  1479.         }
  1480.  
  1481.         private Font _TitleFont;
  1482.  
  1483.         private Font _SubTitleFont;
  1484.  
  1485.         public NSGroupBox()
  1486.         {
  1487.             SetStyle((ControlStyles) 139286, true);
  1488.             SetStyle(ControlStyles.Selectable, false);
  1489.  
  1490.             _TitleFont = new Font("Verdana", 10f);
  1491.             _SubTitleFont = new Font("Verdana", 6.5f);
  1492.  
  1493.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  1494.             P2 = new Pen(Color.FromArgb(55, 55, 55));
  1495.  
  1496.             B1 = new SolidBrush(Color.FromArgb(205, 150, 0));
  1497.         }
  1498.  
  1499.         private GraphicsPath GP1;
  1500.  
  1501.         private GraphicsPath GP2;
  1502.         private PointF PT1;
  1503.         private SizeF SZ1;
  1504.  
  1505.         private SizeF SZ2;
  1506.         private Pen P1;
  1507.         private Pen P2;
  1508.  
  1509.         private SolidBrush B1;
  1510.         private Graphics G;
  1511.  
  1512.         protected override void OnPaint(PaintEventArgs e)
  1513.         {
  1514.             G = e.Graphics;
  1515.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  1516.  
  1517.             G.Clear(BackColor);
  1518.             G.SmoothingMode = SmoothingMode.AntiAlias;
  1519.  
  1520.             GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  1521.             GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  1522.  
  1523.             G.DrawPath(P1, GP1);
  1524.             G.DrawPath(P2, GP2);
  1525.  
  1526.             SZ1 = G.MeasureString(_Title, _TitleFont, Width, StringFormat.GenericTypographic);
  1527.             SZ2 = G.MeasureString(_SubTitle, _SubTitleFont, Width, StringFormat.GenericTypographic);
  1528.  
  1529.             G.DrawString(_Title, _TitleFont, Brushes.Black, 6, 6);
  1530.             G.DrawString(_Title, _TitleFont, B1, 5, 5);
  1531.  
  1532.             PT1 = new PointF(6f, SZ1.Height + 4f);
  1533.  
  1534.             G.DrawString(_SubTitle, _SubTitleFont, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  1535.             G.DrawString(_SubTitle, _SubTitleFont, Brushes.White, PT1.X, PT1.Y);
  1536.  
  1537.             if (_DrawSeperator)
  1538.             {
  1539.                 int Y = Convert.ToInt32(PT1.Y + SZ2.Height) + 8;
  1540.  
  1541.                 G.DrawLine(P1, 4, Y, Width - 5, Y);
  1542.                 G.DrawLine(P2, 4, Y + 1, Width - 5, Y + 1);
  1543.             }
  1544.         }
  1545.  
  1546.     }
  1547.  
  1548.     class NSSeperator : Control
  1549.     {
  1550.  
  1551.         public NSSeperator()
  1552.         {
  1553.             SetStyle((ControlStyles) 139286, true);
  1554.             SetStyle(ControlStyles.Selectable, false);
  1555.  
  1556.             Height = 10;
  1557.  
  1558.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  1559.             P2 = new Pen(Color.FromArgb(55, 55, 55));
  1560.         }
  1561.  
  1562.         private Pen P1;
  1563.  
  1564.         private Pen P2;
  1565.         private Graphics G;
  1566.  
  1567.         protected override void OnPaint(PaintEventArgs e)
  1568.         {
  1569.             G = e.Graphics;
  1570.             G.Clear(BackColor);
  1571.  
  1572.             G.DrawLine(P1, 0, 5, Width, 5);
  1573.             G.DrawLine(P2, 0, 6, Width, 6);
  1574.         }
  1575.  
  1576.     }
  1577.  
  1578.     [DefaultEvent("Scroll")]
  1579.     class NSTrackBar : Control
  1580.     {
  1581.  
  1582.         public event ScrollEventHandler Scroll;
  1583.  
  1584.         public delegate void ScrollEventHandler(object sender);
  1585.  
  1586.         private int _Minimum;
  1587.  
  1588.         public int Minimum
  1589.         {
  1590.             get { return _Minimum; }
  1591.             set
  1592.             {
  1593.                 if (value < 0)
  1594.                 {
  1595.                     throw new Exception("Property value is not valid.");
  1596.                 }
  1597.  
  1598.                 _Minimum = value;
  1599.                 if (value > _Value)
  1600.                     _Value = value;
  1601.                 if (value > _Maximum)
  1602.                     _Maximum = value;
  1603.                 Invalidate();
  1604.             }
  1605.         }
  1606.  
  1607.         private int _Maximum = 10;
  1608.  
  1609.         public int Maximum
  1610.         {
  1611.             get { return _Maximum; }
  1612.             set
  1613.             {
  1614.                 if (value < 0)
  1615.                 {
  1616.                     throw new Exception("Property value is not valid.");
  1617.                 }
  1618.  
  1619.                 _Maximum = value;
  1620.                 if (value < _Value)
  1621.                     _Value = value;
  1622.                 if (value < _Minimum)
  1623.                     _Minimum = value;
  1624.                 Invalidate();
  1625.             }
  1626.         }
  1627.  
  1628.         private int _Value;
  1629.  
  1630.         public int Value
  1631.         {
  1632.             get { return _Value; }
  1633.             set
  1634.             {
  1635.                 if (value == _Value)
  1636.                     return;
  1637.  
  1638.                 if (value > _Maximum || value < _Minimum)
  1639.                 {
  1640.                     throw new Exception("Property value is not valid.");
  1641.                 }
  1642.  
  1643.                 _Value = value;
  1644.                 Invalidate();
  1645.  
  1646.                 if (Scroll != null)
  1647.                 {
  1648.                     Scroll(this);
  1649.                 }
  1650.             }
  1651.         }
  1652.  
  1653.         public NSTrackBar()
  1654.         {
  1655.             SetStyle((ControlStyles) 139286, true);
  1656.             SetStyle(ControlStyles.Selectable, false);
  1657.  
  1658.             Height = 17;
  1659.  
  1660.             P1 = new Pen(Color.FromArgb(150, 110, 0), 2);
  1661.             P2 = new Pen(Color.FromArgb(55, 55, 55));
  1662.             P3 = new Pen(Color.FromArgb(35, 35, 35));
  1663.             P4 = new Pen(Color.FromArgb(65, 65, 65));
  1664.         }
  1665.  
  1666.         private GraphicsPath GP1;
  1667.         private GraphicsPath GP2;
  1668.         private GraphicsPath GP3;
  1669.  
  1670.         private GraphicsPath GP4;
  1671.         private Rectangle R1;
  1672.         private Rectangle R2;
  1673.         private Rectangle R3;
  1674.  
  1675.         private int I1;
  1676.         private Pen P1;
  1677.         private Pen P2;
  1678.         private Pen P3;
  1679.  
  1680.         private Pen P4;
  1681.         private LinearGradientBrush GB1;
  1682.         private LinearGradientBrush GB2;
  1683.  
  1684.         private LinearGradientBrush GB3;
  1685.         private Graphics G;
  1686.  
  1687.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  1688.         {
  1689.             G = e.Graphics;
  1690.  
  1691.             G.Clear(BackColor);
  1692.             G.SmoothingMode = SmoothingMode.AntiAlias;
  1693.  
  1694.             GP1 = ThemeModule.CreateRound(0, 5, Width - 1, 10, 5);
  1695.             GP2 = ThemeModule.CreateRound(1, 6, Width - 3, 8, 5);
  1696.  
  1697.             R1 = new Rectangle(0, 7, Width - 1, 5);
  1698.             GB1 = new LinearGradientBrush(R1, Color.FromArgb(45, 45, 45), Color.FromArgb(50, 50, 50), 90f);
  1699.  
  1700.             I1 = Convert.ToInt32((double) (_Value - _Minimum)/(double) (_Maximum - _Minimum)*(Width - 11));
  1701.             R2 = new Rectangle(I1, 0, 10, 20);
  1702.  
  1703.             G.SetClip(GP2);
  1704.             G.FillRectangle(GB1, R1);
  1705.  
  1706.             R3 = new Rectangle(1, 7, R2.X + R2.Width - 2, 8);
  1707.             GB2 = new LinearGradientBrush(R3, Color.FromArgb(205, 150, 0), Color.FromArgb(150, 110, 0), 90f);
  1708.  
  1709.             G.SmoothingMode = SmoothingMode.None;
  1710.             G.FillRectangle(GB2, R3);
  1711.             G.SmoothingMode = SmoothingMode.AntiAlias;
  1712.  
  1713.             for (int I = 0; I <= R3.Width - 15; I += 5)
  1714.             {
  1715.                 G.DrawLine(P1, I, 0, I + 15, Height);
  1716.             }
  1717.  
  1718.             G.ResetClip();
  1719.  
  1720.             G.DrawPath(P2, GP1);
  1721.             G.DrawPath(P3, GP2);
  1722.  
  1723.             GP3 = ThemeModule.CreateRound(R2, 5);
  1724.             GP4 = ThemeModule.CreateRound(R2.X + 1, R2.Y + 1, R2.Width - 2, R2.Height - 2, 5);
  1725.             GB3 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  1726.  
  1727.             G.FillPath(GB3, GP3);
  1728.             G.DrawPath(P3, GP3);
  1729.             G.DrawPath(P4, GP4);
  1730.         }
  1731.  
  1732.         private bool TrackDown;
  1733.  
  1734.         protected override void OnMouseDown(MouseEventArgs e)
  1735.         {
  1736.             if (e.Button == System.Windows.Forms.MouseButtons.Left)
  1737.             {
  1738.                 I1 = Convert.ToInt32((double) (_Value - _Minimum)/(double) (_Maximum - _Minimum)*(Width - 11));
  1739.                 R2 = new Rectangle(I1, 0, 10, 20);
  1740.  
  1741.                 TrackDown = R2.Contains(e.Location);
  1742.             }
  1743.  
  1744.             base.OnMouseDown(e);
  1745.         }
  1746.  
  1747.         protected override void OnMouseMove(MouseEventArgs e)
  1748.         {
  1749.             if (TrackDown && e.X > -1 && e.X < (Width + 1))
  1750.             {
  1751.                 Value = _Minimum + Convert.ToInt32((_Maximum - _Minimum)*((double) e.X/(double) Width));
  1752.             }
  1753.  
  1754.             base.OnMouseMove(e);
  1755.         }
  1756.  
  1757.         protected override void OnMouseUp(MouseEventArgs e)
  1758.         {
  1759.             TrackDown = false;
  1760.             base.OnMouseUp(e);
  1761.         }
  1762.  
  1763.     }
  1764.  
  1765.     [DefaultEvent("ValueChanged")]
  1766.     class NSRandomPool : Control
  1767.     {
  1768.  
  1769.         public event ValueChangedEventHandler ValueChanged;
  1770.  
  1771.         public delegate void ValueChangedEventHandler(object sender);
  1772.  
  1773.         private StringBuilder _Value = new StringBuilder();
  1774.  
  1775.         public string Value
  1776.         {
  1777.             get { return _Value.ToString(); }
  1778.         }
  1779.  
  1780.         public string FullValue
  1781.         {
  1782.             get { return BitConverter.ToString(Table).Replace("-", ""); }
  1783.         }
  1784.  
  1785.  
  1786.         private Random RNG = new Random();
  1787.         private int ItemSize = 9;
  1788.  
  1789.         private int DrawSize = 8;
  1790.  
  1791.         private Rectangle WA;
  1792.         private int RowSize;
  1793.  
  1794.         private int ColumnSize;
  1795.  
  1796.         public NSRandomPool()
  1797.         {
  1798.             SetStyle((ControlStyles) 139286, true);
  1799.             SetStyle(ControlStyles.Selectable, false);
  1800.  
  1801.             P1 = new Pen(Color.FromArgb(55, 55, 55));
  1802.             P2 = new Pen(Color.FromArgb(35, 35, 35));
  1803.  
  1804.             B1 = new SolidBrush(Color.FromArgb(30, 30, 30));
  1805.         }
  1806.  
  1807.         protected override void OnHandleCreated(EventArgs e)
  1808.         {
  1809.             UpdateTable();
  1810.             base.OnHandleCreated(e);
  1811.         }
  1812.  
  1813.         private byte[] Table;
  1814.  
  1815.         private void UpdateTable()
  1816.         {
  1817.             WA = new Rectangle(5, 5, Width - 10, Height - 10);
  1818.  
  1819.             RowSize = WA.Width/ItemSize;
  1820.             ColumnSize = WA.Height/ItemSize;
  1821.  
  1822.             WA.Width = RowSize*ItemSize;
  1823.             WA.Height = ColumnSize*ItemSize;
  1824.  
  1825.             WA.X = (Width/2) - (WA.Width/2);
  1826.             WA.Y = (Height/2) - (WA.Height/2);
  1827.  
  1828.             Table = new byte[(RowSize*ColumnSize)];
  1829.  
  1830.             for (int I = 0; I <= Table.Length - 1; I++)
  1831.             {
  1832.                 Table[I] = Convert.ToByte(RNG.Next(100));
  1833.             }
  1834.  
  1835.             Invalidate();
  1836.         }
  1837.  
  1838.         protected override void OnSizeChanged(EventArgs e)
  1839.         {
  1840.             UpdateTable();
  1841.         }
  1842.  
  1843.         private int Index1 = -1;
  1844.  
  1845.         private int Index2;
  1846.  
  1847.         private bool InvertColors;
  1848.  
  1849.         protected override void OnMouseMove(MouseEventArgs e)
  1850.         {
  1851.             HandleDraw(e);
  1852.         }
  1853.  
  1854.         protected override void OnMouseDown(MouseEventArgs e)
  1855.         {
  1856.             HandleDraw(e);
  1857.             base.OnMouseDown(e);
  1858.         }
  1859.  
  1860.         private void HandleDraw(MouseEventArgs e)
  1861.         {
  1862.             if (e.Button == System.Windows.Forms.MouseButtons.Left ||
  1863.                 e.Button == System.Windows.Forms.MouseButtons.Right)
  1864.             {
  1865.                 if (!WA.Contains(e.Location))
  1866.                     return;
  1867.  
  1868.                 InvertColors = (e.Button == System.Windows.Forms.MouseButtons.Right);
  1869.  
  1870.                 Index1 = GetIndex(e.X, e.Y);
  1871.                 if (Index1 == Index2)
  1872.                     return;
  1873.  
  1874.                 bool L = !(Index1%RowSize == 0);
  1875.                 bool R = !(Index1%RowSize == (RowSize - 1));
  1876.  
  1877.                 Randomize(Index1 - RowSize);
  1878.                 if (L)
  1879.                     Randomize(Index1 - 1);
  1880.                 Randomize(Index1);
  1881.                 if (R)
  1882.                     Randomize(Index1 + 1);
  1883.                 Randomize(Index1 + RowSize);
  1884.  
  1885.                 _Value.Append(Table[Index1].ToString("X"));
  1886.                 if (_Value.Length > 32)
  1887.                     _Value.Remove(0, 2);
  1888.  
  1889.                 if (ValueChanged != null)
  1890.                 {
  1891.                     ValueChanged(this);
  1892.                 }
  1893.  
  1894.                 Index2 = Index1;
  1895.                 Invalidate();
  1896.             }
  1897.         }
  1898.  
  1899.         private GraphicsPath GP1;
  1900.  
  1901.         private GraphicsPath GP2;
  1902.         private Pen P1;
  1903.         private Pen P2;
  1904.         private SolidBrush B1;
  1905.  
  1906.         private SolidBrush B2;
  1907.  
  1908.         private PathGradientBrush PB1;
  1909.         private Graphics G;
  1910.  
  1911.         protected override void OnPaint(PaintEventArgs e)
  1912.         {
  1913.             G = e.Graphics;
  1914.  
  1915.             G.Clear(BackColor);
  1916.             G.SmoothingMode = SmoothingMode.AntiAlias;
  1917.  
  1918.             GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7);
  1919.             GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7);
  1920.  
  1921.             PB1 = new PathGradientBrush(GP1);
  1922.             PB1.CenterColor = Color.FromArgb(50, 50, 50);
  1923.             PB1.SurroundColors = new Color[] {Color.FromArgb(45, 45, 45)};
  1924.             PB1.FocusScales = new PointF(0.9f, 0.5f);
  1925.  
  1926.             G.FillPath(PB1, GP1);
  1927.  
  1928.             G.DrawPath(P1, GP1);
  1929.             G.DrawPath(P2, GP2);
  1930.  
  1931.             G.SmoothingMode = SmoothingMode.None;
  1932.  
  1933.             for (int I = 0; I <= Table.Length - 1; I++)
  1934.             {
  1935.                 int C = Math.Max(Table[I], (byte) 75);
  1936.  
  1937.                 int X = ((I%RowSize)*ItemSize) + WA.X;
  1938.                 int Y = ((I/RowSize)*ItemSize) + WA.Y;
  1939.  
  1940.                 B2 = new SolidBrush(Color.FromArgb(C, C, C));
  1941.  
  1942.                 G.FillRectangle(B1, X + 1, Y + 1, DrawSize, DrawSize);
  1943.                 G.FillRectangle(B2, X, Y, DrawSize, DrawSize);
  1944.  
  1945.                 B2.Dispose();
  1946.             }
  1947.  
  1948.         }
  1949.  
  1950.         private int GetIndex(int x, int y)
  1951.         {
  1952.             return (((y - WA.Y)/ItemSize)*RowSize) + ((x - WA.X)/ItemSize);
  1953.         }
  1954.  
  1955.         private void Randomize(int index)
  1956.         {
  1957.             if (index > -1 && index < Table.Length)
  1958.             {
  1959.                 if (InvertColors)
  1960.                 {
  1961.                     Table[index] = Convert.ToByte(RNG.Next(100));
  1962.                 }
  1963.                 else
  1964.                 {
  1965.                     Table[index] = Convert.ToByte(RNG.Next(100, 256));
  1966.                 }
  1967.             }
  1968.         }
  1969.  
  1970.     }
  1971.  
  1972.     class NSKeyboard : Control
  1973.     {
  1974.  
  1975.         private Bitmap TextBitmap;
  1976.  
  1977.         private Graphics TextGraphics;
  1978.         const string LowerKeys = "1234567890-=qwertyuiop[]asdfghjkl\\;'zxcvbnm,./`";
  1979.  
  1980.         const string UpperKeys = "!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL|:\"ZXCVBNM<>?~";
  1981.  
  1982.         public NSKeyboard()
  1983.         {
  1984.             SetStyle((ControlStyles) 139286, true);
  1985.             SetStyle(ControlStyles.Selectable, false);
  1986.  
  1987.             Font = new Font("Verdana", 8.25f);
  1988.  
  1989.             TextBitmap = new Bitmap(1, 1);
  1990.             TextGraphics = Graphics.FromImage(TextBitmap);
  1991.  
  1992.             MinimumSize = new Size(386, 162);
  1993.             MaximumSize = new Size(386, 162);
  1994.  
  1995.             Lower = LowerKeys.ToCharArray();
  1996.             Upper = UpperKeys.ToCharArray();
  1997.  
  1998.             PrepareCache();
  1999.  
  2000.             P1 = new Pen(Color.FromArgb(45, 45, 45));
  2001.             P2 = new Pen(Color.FromArgb(65, 65, 65));
  2002.             P3 = new Pen(Color.FromArgb(35, 35, 35));
  2003.  
  2004.             B1 = new SolidBrush(Color.FromArgb(100, 100, 100));
  2005.         }
  2006.  
  2007.         private Control _Target;
  2008.  
  2009.         public Control Target
  2010.         {
  2011.             get { return _Target; }
  2012.             set { _Target = value; }
  2013.         }
  2014.  
  2015.  
  2016.         private bool Shift;
  2017.         private int Pressed = -1;
  2018.  
  2019.         private Rectangle[] Buttons;
  2020.         private char[] Lower;
  2021.         private char[] Upper;
  2022.  
  2023.         private string[] Other =
  2024.         {
  2025.             "Shift",
  2026.             "Space",
  2027.             "Back"
  2028.  
  2029.         };
  2030.  
  2031.         private PointF[] UpperCache;
  2032.  
  2033.         private PointF[] LowerCache;
  2034.  
  2035.         private void PrepareCache()
  2036.         {
  2037.             Buttons = new Rectangle[51];
  2038.             UpperCache = new PointF[Upper.Length];
  2039.             LowerCache = new PointF[Lower.Length];
  2040.  
  2041.             int I = 0;
  2042.  
  2043.             SizeF S = default(SizeF);
  2044.             Rectangle R = default(Rectangle);
  2045.  
  2046.             for (int Y = 0; Y <= 3; Y++)
  2047.             {
  2048.                 for (int X = 0; X <= 11; X++)
  2049.                 {
  2050.                     I = (Y*12) + X;
  2051.                     R = new Rectangle(X*32, Y*32, 32, 32);
  2052.  
  2053.                     Buttons[I] = R;
  2054.  
  2055.                     if (!(I == 47) && !char.IsLetter(Upper[I]))
  2056.                     {
  2057.                         S = TextGraphics.MeasureString(Upper[I].ToString(), Font);
  2058.                         UpperCache[I] = new PointF(R.X + (R.Width/2 - S.Width/2), R.Y + R.Height - S.Height - 2);
  2059.  
  2060.                         S = TextGraphics.MeasureString(Lower[I].ToString(), Font);
  2061.                         LowerCache[I] = new PointF(R.X + (R.Width/2 - S.Width/2), R.Y + R.Height - S.Height - 2);
  2062.                     }
  2063.                 }
  2064.             }
  2065.  
  2066.             Buttons[48] = new Rectangle(0, 4*32, 2*32, 32);
  2067.             Buttons[49] = new Rectangle(Buttons[48].Right, 4*32, 8*32, 32);
  2068.             Buttons[50] = new Rectangle(Buttons[49].Right, 4*32, 2*32, 32);
  2069.         }
  2070.  
  2071.  
  2072.         private GraphicsPath GP1;
  2073.         private SizeF SZ1;
  2074.  
  2075.         private PointF PT1;
  2076.         private Pen P1;
  2077.         private Pen P2;
  2078.         private Pen P3;
  2079.  
  2080.         private SolidBrush B1;
  2081.         private PathGradientBrush PB1;
  2082.  
  2083.         private LinearGradientBrush GB1;
  2084.         private Graphics G;
  2085.  
  2086.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2087.         {
  2088.             G = e.Graphics;
  2089.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  2090.  
  2091.             G.Clear(BackColor);
  2092.  
  2093.             Rectangle R = default(Rectangle);
  2094.  
  2095.             int Offset = 0;
  2096.             G.DrawRectangle(P1, 0, 0, (12*32) + 1, (5*32) + 1);
  2097.  
  2098.             for (int I = 0; I <= Buttons.Length - 1; I++)
  2099.             {
  2100.                 R = Buttons[I];
  2101.  
  2102.                 Offset = 0;
  2103.                 if (I == Pressed)
  2104.                 {
  2105.                     Offset = 1;
  2106.  
  2107.                     GP1 = new GraphicsPath();
  2108.                     GP1.AddRectangle(R);
  2109.  
  2110.                     PB1 = new PathGradientBrush(GP1);
  2111.                     PB1.CenterColor = Color.FromArgb(60, 60, 60);
  2112.                     PB1.SurroundColors = new Color[] {Color.FromArgb(55, 55, 55)};
  2113.                     PB1.FocusScales = new PointF(0.8f, 0.5f);
  2114.  
  2115.                     G.FillPath(PB1, GP1);
  2116.                 }
  2117.                 else
  2118.                 {
  2119.                     GB1 = new LinearGradientBrush(R, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  2120.                     G.FillRectangle(GB1, R);
  2121.                 }
  2122.  
  2123.                 switch (I)
  2124.                 {
  2125.                     case 48:
  2126.                     case 49:
  2127.                     case 50:
  2128.                         SZ1 = G.MeasureString(Other[I - 48], Font);
  2129.                         G.DrawString(Other[I - 48], Font, Brushes.Black, R.X + (R.Width/2 - SZ1.Width/2) + Offset + 1,
  2130.                             R.Y + (R.Height/2 - SZ1.Height/2) + Offset + 1);
  2131.                         G.DrawString(Other[I - 48], Font, Brushes.White, R.X + (R.Width/2 - SZ1.Width/2) + Offset,
  2132.                             R.Y + (R.Height/2 - SZ1.Height/2) + Offset);
  2133.                         break;
  2134.                     case 47:
  2135.                         DrawArrow(Color.Black, R.X + Offset + 1, R.Y + Offset + 1);
  2136.                         DrawArrow(Color.White, R.X + Offset, R.Y + Offset);
  2137.                         break;
  2138.                     default:
  2139.                         if (Shift)
  2140.                         {
  2141.                             G.DrawString(Upper[I].ToString(), Font, Brushes.Black, R.X + 3 + Offset + 1,
  2142.                                 R.Y + 2 + Offset + 1);
  2143.                             G.DrawString(Upper[I].ToString(), Font, Brushes.White, R.X + 3 + Offset, R.Y + 2 + Offset);
  2144.  
  2145.                             if (!char.IsLetter(Lower[I]))
  2146.                             {
  2147.                                 PT1 = LowerCache[I];
  2148.                                 G.DrawString(Lower[I].ToString(), Font, B1, PT1.X + Offset, PT1.Y + Offset);
  2149.                             }
  2150.                         }
  2151.                         else
  2152.                         {
  2153.                             G.DrawString(Lower[I].ToString(), Font, Brushes.Black, R.X + 3 + Offset + 1,
  2154.                                 R.Y + 2 + Offset + 1);
  2155.                             G.DrawString(Lower[I].ToString(), Font, Brushes.White, R.X + 3 + Offset, R.Y + 2 + Offset);
  2156.  
  2157.                             if (!char.IsLetter(Upper[I]))
  2158.                             {
  2159.                                 PT1 = UpperCache[I];
  2160.                                 G.DrawString(Upper[I].ToString(), Font, B1, PT1.X + Offset, PT1.Y + Offset);
  2161.                             }
  2162.                         }
  2163.                         break;
  2164.                 }
  2165.  
  2166.                 G.DrawRectangle(P2, R.X + 1 + Offset, R.Y + 1 + Offset, R.Width - 2, R.Height - 2);
  2167.                 G.DrawRectangle(P3, R.X + Offset, R.Y + Offset, R.Width, R.Height);
  2168.  
  2169.                 if (I == Pressed)
  2170.                 {
  2171.                     G.DrawLine(P1, R.X, R.Y, R.Right, R.Y);
  2172.                     G.DrawLine(P1, R.X, R.Y, R.X, R.Bottom);
  2173.                 }
  2174.             }
  2175.         }
  2176.  
  2177.         private void DrawArrow(Color color, int rx, int ry)
  2178.         {
  2179.             Rectangle R = new Rectangle(rx + 8, ry + 8, 16, 16);
  2180.             G.SmoothingMode = SmoothingMode.AntiAlias;
  2181.  
  2182.             Pen P = new Pen(color, 1);
  2183.             AdjustableArrowCap C = new AdjustableArrowCap(3, 2);
  2184.             P.CustomEndCap = C;
  2185.  
  2186.             G.DrawArc(P, R, 0f, 290f);
  2187.  
  2188.             P.Dispose();
  2189.             C.Dispose();
  2190.             G.SmoothingMode = SmoothingMode.None;
  2191.         }
  2192.  
  2193.         protected override void OnMouseDown(MouseEventArgs e)
  2194.         {
  2195.             int Index = ((e.Y/32)*12) + (e.X/32);
  2196.  
  2197.             if (Index > 47)
  2198.             {
  2199.                 for (int I = 48; I <= Buttons.Length - 1; I++)
  2200.                 {
  2201.                     if (Buttons[I].Contains(e.X, e.Y))
  2202.                     {
  2203.                         Pressed = I;
  2204.                         break; // TODO: might not be correct. Was : Exit For
  2205.                     }
  2206.                 }
  2207.             }
  2208.             else
  2209.             {
  2210.                 Pressed = Index;
  2211.             }
  2212.  
  2213.             HandleKey();
  2214.             Invalidate();
  2215.         }
  2216.  
  2217.         protected override void OnMouseUp(MouseEventArgs e)
  2218.         {
  2219.             Pressed = -1;
  2220.             Invalidate();
  2221.         }
  2222.  
  2223.         private void HandleKey()
  2224.         {
  2225.             if (_Target == null)
  2226.                 return;
  2227.             if (Pressed == -1)
  2228.                 return;
  2229.  
  2230.             switch (Pressed)
  2231.             {
  2232.                 case 47:
  2233.                     _Target.Text = string.Empty;
  2234.                     break;
  2235.                 case 48:
  2236.                     Shift = !Shift;
  2237.                     break;
  2238.                 case 49:
  2239.                     _Target.Text += " ";
  2240.                     break;
  2241.                 case 50:
  2242.                     if (!(_Target.Text.Length == 0))
  2243.                     {
  2244.                         _Target.Text = _Target.Text.Remove(_Target.Text.Length - 1);
  2245.                     }
  2246.                     break;
  2247.                 default:
  2248.                     if (Shift)
  2249.                     {
  2250.                         _Target.Text += Upper[Pressed];
  2251.                     }
  2252.                     else
  2253.                     {
  2254.                         _Target.Text += Lower[Pressed];
  2255.                     }
  2256.                     break;
  2257.             }
  2258.         }
  2259.  
  2260.     }
  2261.  
  2262.     [DefaultEvent("SelectedIndexChanged")]
  2263.     class NSPaginator : Control
  2264.     {
  2265.  
  2266.         public event SelectedIndexChangedEventHandler SelectedIndexChanged;
  2267.  
  2268.         public delegate void SelectedIndexChangedEventHandler(object sender, EventArgs e);
  2269.  
  2270.         private Bitmap TextBitmap;
  2271.  
  2272.         private Graphics TextGraphics;
  2273.  
  2274.         public NSPaginator()
  2275.         {
  2276.             SetStyle((ControlStyles) 139286, true);
  2277.             SetStyle(ControlStyles.Selectable, false);
  2278.  
  2279.             Size = new Size(202, 26);
  2280.  
  2281.             TextBitmap = new Bitmap(1, 1);
  2282.             TextGraphics = Graphics.FromImage(TextBitmap);
  2283.  
  2284.             InvalidateItems();
  2285.  
  2286.             B1 = new SolidBrush(Color.FromArgb(50, 50, 50));
  2287.             B2 = new SolidBrush(Color.FromArgb(55, 55, 55));
  2288.  
  2289.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  2290.             P2 = new Pen(Color.FromArgb(55, 55, 55));
  2291.             P3 = new Pen(Color.FromArgb(65, 65, 65));
  2292.         }
  2293.  
  2294.         private int _SelectedIndex;
  2295.  
  2296.         public int SelectedIndex
  2297.         {
  2298.             get { return _SelectedIndex; }
  2299.             set
  2300.             {
  2301.                 _SelectedIndex = Math.Max(Math.Min(value, MaximumIndex), 0);
  2302.                 Invalidate();
  2303.             }
  2304.         }
  2305.  
  2306.         private int _NumberOfPages;
  2307.  
  2308.         public int NumberOfPages
  2309.         {
  2310.             get { return _NumberOfPages; }
  2311.             set
  2312.             {
  2313.                 _NumberOfPages = value;
  2314.                 _SelectedIndex = Math.Max(Math.Min(_SelectedIndex, MaximumIndex), 0);
  2315.                 Invalidate();
  2316.             }
  2317.         }
  2318.  
  2319.         public int MaximumIndex
  2320.         {
  2321.             get { return NumberOfPages - 1; }
  2322.         }
  2323.  
  2324.  
  2325.         private int ItemWidth;
  2326.  
  2327.         public override Font Font
  2328.         {
  2329.             get { return base.Font; }
  2330.             set
  2331.             {
  2332.                 base.Font = value;
  2333.  
  2334.                 InvalidateItems();
  2335.                 Invalidate();
  2336.             }
  2337.         }
  2338.  
  2339.         private void InvalidateItems()
  2340.         {
  2341.             Size S = TextGraphics.MeasureString("000 ..", Font).ToSize();
  2342.             ItemWidth = S.Width + 10;
  2343.         }
  2344.  
  2345.         private GraphicsPath GP1;
  2346.  
  2347.         private GraphicsPath GP2;
  2348.  
  2349.         private Rectangle R1;
  2350.         private Size SZ1;
  2351.  
  2352.         private Point PT1;
  2353.         private Pen P1;
  2354.         private Pen P2;
  2355.         private Pen P3;
  2356.         private SolidBrush B1;
  2357.  
  2358.         private SolidBrush B2;
  2359.         private Graphics G;
  2360.  
  2361.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2362.         {
  2363.             G = e.Graphics;
  2364.             G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
  2365.  
  2366.             G.Clear(BackColor);
  2367.             G.SmoothingMode = SmoothingMode.AntiAlias;
  2368.  
  2369.             bool LeftEllipse = false;
  2370.             bool RightEllipse = false;
  2371.  
  2372.             if (_SelectedIndex < 4)
  2373.             {
  2374.                 for (int I = 0; I <= Math.Min(MaximumIndex, 4); I++)
  2375.                 {
  2376.                     RightEllipse = (I == 4) && (MaximumIndex > 4);
  2377.                     DrawBox(I*ItemWidth, I, false, RightEllipse);
  2378.                 }
  2379.             }
  2380.             else if (_SelectedIndex > 3 && _SelectedIndex < (MaximumIndex - 3))
  2381.             {
  2382.                 for (int I = 0; I <= 4; I++)
  2383.                 {
  2384.                     LeftEllipse = (I == 0);
  2385.                     RightEllipse = (I == 4);
  2386.                     DrawBox(I*ItemWidth, _SelectedIndex + I - 2, LeftEllipse, RightEllipse);
  2387.                 }
  2388.             }
  2389.             else
  2390.             {
  2391.                 for (int I = 0; I <= 4; I++)
  2392.                 {
  2393.                     LeftEllipse = (I == 0) && (MaximumIndex > 4);
  2394.                     DrawBox(I*ItemWidth, MaximumIndex - (4 - I), LeftEllipse, false);
  2395.                 }
  2396.             }
  2397.         }
  2398.  
  2399.         private void DrawBox(int x, int index, bool leftEllipse, bool rightEllipse)
  2400.         {
  2401.             R1 = new Rectangle(x, 0, ItemWidth - 4, Height - 1);
  2402.  
  2403.             GP1 = ThemeModule.CreateRound(R1, 7);
  2404.             GP2 = ThemeModule.CreateRound(R1.X + 1, R1.Y + 1, R1.Width - 2, R1.Height - 2, 7);
  2405.  
  2406.             string T = Convert.ToString(index + 1);
  2407.  
  2408.             if (leftEllipse)
  2409.                 T = ".. " + T;
  2410.             if (rightEllipse)
  2411.                 T = T + " ..";
  2412.  
  2413.             SZ1 = G.MeasureString(T, Font).ToSize();
  2414.             PT1 = new Point(R1.X + (R1.Width/2 - SZ1.Width/2), R1.Y + (R1.Height/2 - SZ1.Height/2));
  2415.  
  2416.             if (index == _SelectedIndex)
  2417.             {
  2418.                 G.FillPath(B1, GP1);
  2419.  
  2420.                 Font F = new Font(Font, FontStyle.Underline);
  2421.                 G.DrawString(T, F, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  2422.                 G.DrawString(T, F, Brushes.White, PT1);
  2423.                 F.Dispose();
  2424.  
  2425.                 G.DrawPath(P1, GP2);
  2426.                 G.DrawPath(P2, GP1);
  2427.             }
  2428.             else
  2429.             {
  2430.                 G.FillPath(B2, GP1);
  2431.  
  2432.                 G.DrawString(T, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
  2433.                 G.DrawString(T, Font, Brushes.White, PT1);
  2434.  
  2435.                 G.DrawPath(P3, GP2);
  2436.                 G.DrawPath(P1, GP1);
  2437.             }
  2438.         }
  2439.  
  2440.         protected override void OnMouseDown(MouseEventArgs e)
  2441.         {
  2442.             if (e.Button == System.Windows.Forms.MouseButtons.Left)
  2443.             {
  2444.                 int NewIndex = 0;
  2445.                 int OldIndex = _SelectedIndex;
  2446.  
  2447.                 if (_SelectedIndex < 4)
  2448.                 {
  2449.                     NewIndex = (e.X/ItemWidth);
  2450.                 }
  2451.                 else if (_SelectedIndex > 3 && _SelectedIndex < (MaximumIndex - 3))
  2452.                 {
  2453.                     NewIndex = (e.X/ItemWidth);
  2454.  
  2455.                     if (NewIndex == 2)
  2456.                     {
  2457.                         NewIndex = OldIndex;
  2458.                     }
  2459.                     else if (NewIndex < 2)
  2460.                     {
  2461.                         NewIndex = OldIndex - (2 - NewIndex);
  2462.                     }
  2463.                     else if (NewIndex > 2)
  2464.                     {
  2465.                         NewIndex = OldIndex + (NewIndex - 2);
  2466.                     }
  2467.                 }
  2468.                 else
  2469.                 {
  2470.                     NewIndex = MaximumIndex - (4 - (e.X/ItemWidth));
  2471.                 }
  2472.  
  2473.                 if ((NewIndex < _NumberOfPages) && (!(NewIndex == OldIndex)))
  2474.                 {
  2475.                     SelectedIndex = NewIndex;
  2476.                     if (SelectedIndexChanged != null)
  2477.                     {
  2478.                         SelectedIndexChanged(this, null);
  2479.                     }
  2480.                 }
  2481.             }
  2482.  
  2483.             base.OnMouseDown(e);
  2484.         }
  2485.  
  2486.     }
  2487.  
  2488.     [DefaultEvent("Scroll")]
  2489.     class NSVScrollBar : Control
  2490.     {
  2491.  
  2492.         public event ScrollEventHandler Scroll;
  2493.  
  2494.         public delegate void ScrollEventHandler(object sender);
  2495.  
  2496.         private int _Minimum;
  2497.  
  2498.         public int Minimum
  2499.         {
  2500.             get { return _Minimum; }
  2501.             set
  2502.             {
  2503.                 if (value < 0)
  2504.                 {
  2505.                     throw new Exception("Property value is not valid.");
  2506.                 }
  2507.  
  2508.                 _Minimum = value;
  2509.                 if (value > _Value)
  2510.                     _Value = value;
  2511.                 if (value > _Maximum)
  2512.                     _Maximum = value;
  2513.  
  2514.                 InvalidateLayout();
  2515.             }
  2516.         }
  2517.  
  2518.         private int _Maximum = 100;
  2519.  
  2520.         public int Maximum
  2521.         {
  2522.             get { return _Maximum; }
  2523.             set
  2524.             {
  2525.                 if (value < 1)
  2526.                     value = 1;
  2527.  
  2528.                 _Maximum = value;
  2529.                 if (value < _Value)
  2530.                     _Value = value;
  2531.                 if (value < _Minimum)
  2532.                     _Minimum = value;
  2533.  
  2534.                 InvalidateLayout();
  2535.             }
  2536.         }
  2537.  
  2538.         private int _Value;
  2539.  
  2540.         public int Value
  2541.         {
  2542.             get
  2543.             {
  2544.                 if (!ShowThumb)
  2545.                     return _Minimum;
  2546.                 return _Value;
  2547.             }
  2548.             set
  2549.             {
  2550.                 if (value == _Value)
  2551.                     return;
  2552.  
  2553.                 if (value > _Maximum || value < _Minimum)
  2554.                 {
  2555.                     throw new Exception("Property value is not valid.");
  2556.                 }
  2557.  
  2558.                 _Value = value;
  2559.                 InvalidatePosition();
  2560.  
  2561.                 if (Scroll != null)
  2562.                 {
  2563.                     Scroll(this);
  2564.                 }
  2565.             }
  2566.         }
  2567.  
  2568.         public double _Percent { get; set; }
  2569.  
  2570.         public double Percent
  2571.         {
  2572.             get
  2573.             {
  2574.                 if (!ShowThumb)
  2575.                     return 0;
  2576.                 return GetProgress();
  2577.             }
  2578.         }
  2579.  
  2580.         private int _SmallChange = 1;
  2581.  
  2582.         public int SmallChange
  2583.         {
  2584.             get { return _SmallChange; }
  2585.             set
  2586.             {
  2587.                 if (value < 1)
  2588.                 {
  2589.                     throw new Exception("Property value is not valid.");
  2590.                 }
  2591.  
  2592.                 _SmallChange = value;
  2593.             }
  2594.         }
  2595.  
  2596.         private int _LargeChange = 10;
  2597.  
  2598.         public int LargeChange
  2599.         {
  2600.             get { return _LargeChange; }
  2601.             set
  2602.             {
  2603.                 if (value < 1)
  2604.                 {
  2605.                     throw new Exception("Property value is not valid.");
  2606.                 }
  2607.  
  2608.                 _LargeChange = value;
  2609.             }
  2610.         }
  2611.  
  2612.         private int ButtonSize = 16;
  2613.         // 14 minimum
  2614.         private int ThumbSize = 24;
  2615.  
  2616.         private Rectangle TSA;
  2617.         private Rectangle BSA;
  2618.         private Rectangle Shaft;
  2619.  
  2620.         private Rectangle Thumb;
  2621.         private bool ShowThumb;
  2622.  
  2623.         private bool ThumbDown;
  2624.  
  2625.         public NSVScrollBar()
  2626.         {
  2627.             SetStyle((ControlStyles) 139286, true);
  2628.             SetStyle(ControlStyles.Selectable, false);
  2629.  
  2630.             Width = 18;
  2631.  
  2632.             B1 = new SolidBrush(Color.FromArgb(55, 55, 55));
  2633.             B2 = new SolidBrush(Color.FromArgb(35, 35, 35));
  2634.  
  2635.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  2636.             P2 = new Pen(Color.FromArgb(65, 65, 65));
  2637.             P3 = new Pen(Color.FromArgb(55, 55, 55));
  2638.             P4 = new Pen(Color.FromArgb(40, 40, 40));
  2639.         }
  2640.  
  2641.         private GraphicsPath GP1;
  2642.         private GraphicsPath GP2;
  2643.         private GraphicsPath GP3;
  2644.  
  2645.         private GraphicsPath GP4;
  2646.         private Pen P1;
  2647.         private Pen P2;
  2648.         private Pen P3;
  2649.         private Pen P4;
  2650.         private SolidBrush B1;
  2651.  
  2652.         private SolidBrush B2;
  2653.  
  2654.         int I1;
  2655.         private Graphics G;
  2656.  
  2657.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2658.         {
  2659.             G = e.Graphics;
  2660.             G.Clear(BackColor);
  2661.  
  2662.             GP1 = DrawArrow(4, 6, false);
  2663.             GP2 = DrawArrow(5, 7, false);
  2664.  
  2665.             G.FillPath(B1, GP2);
  2666.             G.FillPath(B2, GP1);
  2667.  
  2668.             GP3 = DrawArrow(4, Height - 11, true);
  2669.             GP4 = DrawArrow(5, Height - 10, true);
  2670.  
  2671.             G.FillPath(B1, GP4);
  2672.             G.FillPath(B2, GP3);
  2673.  
  2674.             if (ShowThumb)
  2675.             {
  2676.                 G.FillRectangle(B1, Thumb);
  2677.                 G.DrawRectangle(P1, Thumb);
  2678.                 G.DrawRectangle(P2, Thumb.X + 1, Thumb.Y + 1, Thumb.Width - 2, Thumb.Height - 2);
  2679.  
  2680.                 int Y = 0;
  2681.                 int LY = Thumb.Y + (Thumb.Height/2) - 3;
  2682.  
  2683.                 for (int I = 0; I <= 2; I++)
  2684.                 {
  2685.                     Y = LY + (I*3);
  2686.  
  2687.                     G.DrawLine(P1, Thumb.X + 5, Y, Thumb.Right - 5, Y);
  2688.                     G.DrawLine(P2, Thumb.X + 5, Y + 1, Thumb.Right - 5, Y + 1);
  2689.                 }
  2690.             }
  2691.  
  2692.             G.DrawRectangle(P3, 0, 0, Width - 1, Height - 1);
  2693.             G.DrawRectangle(P4, 1, 1, Width - 3, Height - 3);
  2694.         }
  2695.  
  2696.         private GraphicsPath DrawArrow(int x, int y, bool flip)
  2697.         {
  2698.             GraphicsPath GP = new GraphicsPath();
  2699.  
  2700.             int W = 9;
  2701.             int H = 5;
  2702.  
  2703.             if (flip)
  2704.             {
  2705.                 GP.AddLine(x + 1, y, x + W + 1, y);
  2706.                 GP.AddLine(x + W, y, x + H, y + H - 1);
  2707.             }
  2708.             else
  2709.             {
  2710.                 GP.AddLine(x, y + H, x + W, y + H);
  2711.                 GP.AddLine(x + W, y + H, x + H, y);
  2712.             }
  2713.  
  2714.             GP.CloseFigure();
  2715.             return GP;
  2716.         }
  2717.  
  2718.         protected override void OnSizeChanged(EventArgs e)
  2719.         {
  2720.             InvalidateLayout();
  2721.         }
  2722.  
  2723.         private void InvalidateLayout()
  2724.         {
  2725.             TSA = new Rectangle(0, 0, Width, ButtonSize);
  2726.             BSA = new Rectangle(0, Height - ButtonSize, Width, ButtonSize);
  2727.             Shaft = new Rectangle(0, TSA.Bottom + 1, Width, Height - (ButtonSize*2) - 1);
  2728.  
  2729.             ShowThumb = ((_Maximum - _Minimum) > Shaft.Height);
  2730.  
  2731.             if (ShowThumb)
  2732.             {
  2733.                 //ThumbSize = Math.Max(0, 14) 'TODO: Implement this.
  2734.                 Thumb = new Rectangle(1, 0, Width - 3, ThumbSize);
  2735.             }
  2736.  
  2737.             if (Scroll != null)
  2738.             {
  2739.                 Scroll(this);
  2740.             }
  2741.             InvalidatePosition();
  2742.         }
  2743.  
  2744.         private void InvalidatePosition()
  2745.         {
  2746.             Thumb.Y = Convert.ToInt32(GetProgress()*(Shaft.Height - ThumbSize)) + TSA.Height;
  2747.             Invalidate();
  2748.         }
  2749.  
  2750.         protected override void OnMouseDown(MouseEventArgs e)
  2751.         {
  2752.             if (e.Button == System.Windows.Forms.MouseButtons.Left && ShowThumb)
  2753.             {
  2754.                 if (TSA.Contains(e.Location))
  2755.                 {
  2756.                     I1 = _Value - _SmallChange;
  2757.                 }
  2758.                 else if (BSA.Contains(e.Location))
  2759.                 {
  2760.                     I1 = _Value + _SmallChange;
  2761.                 }
  2762.                 else
  2763.                 {
  2764.                     if (Thumb.Contains(e.Location))
  2765.                     {
  2766.                         ThumbDown = true;
  2767.                         base.OnMouseDown(e);
  2768.                         return;
  2769.                     }
  2770.                     else
  2771.                     {
  2772.                         if (e.Y < Thumb.Y)
  2773.                         {
  2774.                             I1 = _Value - _LargeChange;
  2775.                         }
  2776.                         else
  2777.                         {
  2778.                             I1 = _Value + _LargeChange;
  2779.                         }
  2780.                     }
  2781.                 }
  2782.  
  2783.                 Value = Math.Min(Math.Max(I1, _Minimum), _Maximum);
  2784.                 InvalidatePosition();
  2785.             }
  2786.  
  2787.             base.OnMouseDown(e);
  2788.         }
  2789.  
  2790.         protected override void OnMouseMove(MouseEventArgs e)
  2791.         {
  2792.             if (ThumbDown && ShowThumb)
  2793.             {
  2794.                 int ThumbPosition = e.Y - TSA.Height - (ThumbSize/2);
  2795.                 int ThumbBounds = Shaft.Height - ThumbSize;
  2796.  
  2797.                 I1 = Convert.ToInt32(((double) ThumbPosition/(double) ThumbBounds)*(_Maximum - _Minimum)) + _Minimum;
  2798.  
  2799.                 Value = Math.Min(Math.Max(I1, _Minimum), _Maximum);
  2800.                 InvalidatePosition();
  2801.             }
  2802.  
  2803.             base.OnMouseMove(e);
  2804.         }
  2805.  
  2806.         protected override void OnMouseUp(MouseEventArgs e)
  2807.         {
  2808.             ThumbDown = false;
  2809.             base.OnMouseUp(e);
  2810.         }
  2811.  
  2812.         private double GetProgress()
  2813.         {
  2814.             return (double) (_Value - _Minimum)/(double) (_Maximum - _Minimum);
  2815.         }
  2816.  
  2817.     }
  2818.  
  2819.     [DefaultEvent("Scroll")]
  2820.     class NSHScrollBar : Control
  2821.     {
  2822.  
  2823.         public event ScrollEventHandler Scroll;
  2824.  
  2825.         public delegate void ScrollEventHandler(object sender);
  2826.  
  2827.         private int _Minimum;
  2828.  
  2829.         public int Minimum
  2830.         {
  2831.             get { return _Minimum; }
  2832.             set
  2833.             {
  2834.                 if (value < 0)
  2835.                 {
  2836.                     throw new Exception("Property value is not valid.");
  2837.                 }
  2838.  
  2839.                 _Minimum = value;
  2840.                 if (value > _Value)
  2841.                     _Value = value;
  2842.                 if (value > _Maximum)
  2843.                     _Maximum = value;
  2844.  
  2845.                 InvalidateLayout();
  2846.             }
  2847.         }
  2848.  
  2849.         private int _Maximum = 100;
  2850.  
  2851.         public int Maximum
  2852.         {
  2853.             get { return _Maximum; }
  2854.             set
  2855.             {
  2856.                 if (value < 0)
  2857.                 {
  2858.                     throw new Exception("Property value is not valid.");
  2859.                 }
  2860.  
  2861.                 _Maximum = value;
  2862.                 if (value < _Value)
  2863.                     _Value = value;
  2864.                 if (value < _Minimum)
  2865.                     _Minimum = value;
  2866.  
  2867.                 InvalidateLayout();
  2868.             }
  2869.         }
  2870.  
  2871.         private int _Value;
  2872.  
  2873.         public int Value
  2874.         {
  2875.             get
  2876.             {
  2877.                 if (!ShowThumb)
  2878.                     return _Minimum;
  2879.                 return _Value;
  2880.             }
  2881.             set
  2882.             {
  2883.                 if (value == _Value)
  2884.                     return;
  2885.  
  2886.                 if (value > _Maximum || value < _Minimum)
  2887.                 {
  2888.                     throw new Exception("Property value is not valid.");
  2889.                 }
  2890.  
  2891.                 _Value = value;
  2892.                 InvalidatePosition();
  2893.  
  2894.                 if (Scroll != null)
  2895.                 {
  2896.                     Scroll(this);
  2897.                 }
  2898.             }
  2899.         }
  2900.  
  2901.         private int _SmallChange = 1;
  2902.  
  2903.         public int SmallChange
  2904.         {
  2905.             get { return _SmallChange; }
  2906.             set
  2907.             {
  2908.                 if (value < 1)
  2909.                 {
  2910.                     throw new Exception("Property value is not valid.");
  2911.                 }
  2912.  
  2913.                 _SmallChange = value;
  2914.             }
  2915.         }
  2916.  
  2917.         private int _LargeChange = 10;
  2918.  
  2919.         public int LargeChange
  2920.         {
  2921.             get { return _LargeChange; }
  2922.             set
  2923.             {
  2924.                 if (value < 1)
  2925.                 {
  2926.                     throw new Exception("Property value is not valid.");
  2927.                 }
  2928.  
  2929.                 _LargeChange = value;
  2930.             }
  2931.         }
  2932.  
  2933.         private int ButtonSize = 16;
  2934.         // 14 minimum
  2935.         private int ThumbSize = 24;
  2936.  
  2937.         private Rectangle LSA;
  2938.         private Rectangle RSA;
  2939.         private Rectangle Shaft;
  2940.  
  2941.         private Rectangle Thumb;
  2942.         private bool ShowThumb;
  2943.  
  2944.         private bool ThumbDown;
  2945.  
  2946.         public NSHScrollBar()
  2947.         {
  2948.             SetStyle((ControlStyles) 139286, true);
  2949.             SetStyle(ControlStyles.Selectable, false);
  2950.  
  2951.             Height = 18;
  2952.  
  2953.             B1 = new SolidBrush(Color.FromArgb(55, 55, 55));
  2954.             B2 = new SolidBrush(Color.FromArgb(35, 35, 35));
  2955.  
  2956.             P1 = new Pen(Color.FromArgb(35, 35, 35));
  2957.             P2 = new Pen(Color.FromArgb(65, 65, 65));
  2958.             P3 = new Pen(Color.FromArgb(55, 55, 55));
  2959.             P4 = new Pen(Color.FromArgb(40, 40, 40));
  2960.         }
  2961.  
  2962.         private GraphicsPath GP1;
  2963.         private GraphicsPath GP2;
  2964.         private GraphicsPath GP3;
  2965.  
  2966.         private GraphicsPath GP4;
  2967.         private Pen P1;
  2968.         private Pen P2;
  2969.         private Pen P3;
  2970.         private Pen P4;
  2971.         private SolidBrush B1;
  2972.  
  2973.         private SolidBrush B2;
  2974.  
  2975.         int I1;
  2976.         private Graphics G;
  2977.  
  2978.         protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2979.         {
  2980.             G = e.Graphics;
  2981.             G.Clear(BackColor);
  2982.  
  2983.             GP1 = DrawArrow(6, 4, false);
  2984.             GP2 = DrawArrow(7, 5, false);
  2985.  
  2986.             G.FillPath(B1, GP2);
  2987.             G.FillPath(B2, GP1);
  2988.  
  2989.             GP3 = DrawArrow(Width - 11, 4, true);
  2990.             GP4 = DrawArrow(Width - 10, 5, true);
  2991.  
  2992.             G.FillPath(B1, GP4);
  2993.             G.FillPath(B2, GP3);
  2994.  
  2995.             if (ShowThumb)
  2996.             {
  2997.                 G.FillRectangle(B1, Thumb);
  2998.                 G.DrawRectangle(P1, Thumb);
  2999.                 G.DrawRectangle(P2, Thumb.X + 1, Thumb.Y + 1, Thumb.Width - 2, Thumb.Height - 2);
  3000.  
  3001.                 int X = 0;
  3002.                 int LX = Thumb.X + (Thumb.Width/2) - 3;
  3003.  
  3004.                 for (int I = 0; I <= 2; I++)
  3005.                 {
  3006.                     X = LX + (I*3);
  3007.  
  3008.                     G.DrawLine(P1, X, Thumb.Y + 5, X, Thumb.Bottom - 5);
  3009.                     G.DrawLine(P2, X + 1, Thumb.Y + 5, X + 1, Thumb.Bottom - 5);
  3010.                 }
  3011.             }
  3012.  
  3013.             G.DrawRectangle(P3, 0, 0, Width - 1, Height - 1);
  3014.             G.DrawRectangle(P4, 1, 1, Width - 3, Height - 3);
  3015.         }
  3016.  
  3017.         private GraphicsPath DrawArrow(int x, int y, bool flip)
  3018.         {
  3019.             GraphicsPath GP = new GraphicsPath();
  3020.  
  3021.             int W = 5;
  3022.             int H = 9;
  3023.  
  3024.             if (flip)
  3025.             {
  3026.                 GP.AddLine(x, y + 1, x, y + H + 1);
  3027.                 GP.AddLine(x, y + H, x + W - 1, y + W);
  3028.             }
  3029.             else
  3030.             {
  3031.                 GP.AddLine(x + W, y, x + W, y + H);
  3032.                 GP.AddLine(x + W, y + H, x + 1, y + W);
  3033.             }
  3034.  
  3035.             GP.CloseFigure();
  3036.             return GP;
  3037.         }
  3038.  
  3039.         protected override void OnSizeChanged(EventArgs e)
  3040.         {
  3041.             InvalidateLayout();
  3042.         }
  3043.  
  3044.         private void InvalidateLayout()
  3045.         {
  3046.             LSA = new Rectangle(0, 0, ButtonSize, Height);
  3047.             RSA = new Rectangle(Width - ButtonSize, 0, ButtonSize, Height);
  3048.             Shaft = new Rectangle(LSA.Right + 1, 0, Width - (ButtonSize*2) - 1, Height);
  3049.  
  3050.             ShowThumb = ((_Maximum - _Minimum) > Shaft.Width);
  3051.  
  3052.             if (ShowThumb)
  3053.             {
  3054.                 //ThumbSize = Math.Max(0, 14) 'TODO: Implement this.
  3055.                 Thumb = new Rectangle(0, 1, ThumbSize, Height - 3);
  3056.             }
  3057.  
  3058.             if (Scroll != null)
  3059.             {
  3060.                 Scroll(this);
  3061.             }
  3062.             InvalidatePosition();
  3063.         }
  3064.  
  3065.         private void InvalidatePosition()
  3066.         {
  3067.             Thumb.X = Convert.ToInt32(GetProgress()*(Shaft.Width - ThumbSize)) + LSA.Width;
  3068.             Invalidate();
  3069.         }
  3070.  
  3071.         protected override void OnMouseDown(MouseEventArgs e)
  3072.         {
  3073.             if (e.Button == System.Windows.Forms.MouseButtons.Left && ShowThumb)
  3074.             {
  3075.                 if (LSA.Contains(e.Location))
  3076.                 {
  3077.                     I1 = _Value - _SmallChange;
  3078.                 }
  3079.                 else if (RSA.Contains(e.Location))
  3080.                 {
  3081.                     I1 = _Value + _SmallChange;
  3082.                 }
  3083.                 else
  3084.                 {
  3085.                     if (Thumb.Contains(e.Location))
  3086.                     {
  3087.                         ThumbDown = true;
  3088.                         base.OnMouseDown(e);
  3089.                         return;
  3090.                     }
  3091.                     else
  3092.                     {
  3093.                         if (e.X < Thumb.X)
  3094.                         {
  3095.                             I1 = _Value - _LargeChange;
  3096.                         }
  3097.                         else
  3098.                         {
  3099.                             I1 = _Value + _LargeChange;
  3100.                         }
  3101.                     }
  3102.                 }
  3103.  
  3104.                 Value = Math.Min(Math.Max(I1, _Minimum), _Maximum);
  3105.                 InvalidatePosition();
  3106.             }
  3107.  
  3108.             base.OnMouseDown(e);
  3109.         }
  3110.  
  3111.         protected override void OnMouseMove(MouseEventArgs e)
  3112.         {
  3113.             if (ThumbDown && ShowThumb)
  3114.             {
  3115.                 int ThumbPosition = e.X - LSA.Width - (ThumbSize/2);
  3116.                 int ThumbBounds = Shaft.Width - ThumbSize;
  3117.  
  3118.                 I1 = Convert.ToInt32(((double) ThumbPosition/(double) ThumbBounds)*(_Maximum - _Minimum)) + _Minimum;
  3119.  
  3120.                 Value = Math.Min(Math.Max(I1, _Minimum), _Maximum);
  3121.                 InvalidatePosition();
  3122.             }
  3123.  
  3124.             base.OnMouseMove(e);
  3125.         }
  3126.  
  3127.         protected override void OnMouseUp(MouseEventArgs e)
  3128.         {
  3129.             ThumbDown = false;
  3130.             base.OnMouseUp(e);
  3131.         }
  3132.  
  3133.         private double GetProgress()
  3134.         {
  3135.             return (double) (_Value - _Minimum)/(double) (_Maximum - _Minimum);
  3136.         }
  3137.  
  3138.     }
  3139.  
  3140.     class NSContextMenu : ContextMenuStrip
  3141.     {
  3142.  
  3143.         public NSContextMenu()
  3144.         {
  3145.             Renderer = new ToolStripProfessionalRenderer(new NSColorTable());
  3146.             ForeColor = Color.White;
  3147.         }
  3148.  
  3149.         protected override void OnPaint(PaintEventArgs e)
  3150.         {
  3151.             e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  3152.             base.OnPaint(e);
  3153.         }
  3154.  
  3155.     }
  3156.  
  3157.     class NSColorTable : ProfessionalColorTable
  3158.     {
  3159.  
  3160.  
  3161.         private Color BackColor = Color.FromArgb(55, 55, 55);
  3162.  
  3163.         public override Color ButtonSelectedBorder
  3164.         {
  3165.             get { return BackColor; }
  3166.         }
  3167.  
  3168.         public override Color CheckBackground
  3169.         {
  3170.             get { return BackColor; }
  3171.         }
  3172.  
  3173.         public override Color CheckPressedBackground
  3174.         {
  3175.             get { return BackColor; }
  3176.         }
  3177.  
  3178.         public override Color CheckSelectedBackground
  3179.         {
  3180.             get { return BackColor; }
  3181.         }
  3182.  
  3183.         public override Color ImageMarginGradientBegin
  3184.         {
  3185.             get { return BackColor; }
  3186.         }
  3187.  
  3188.         public override Color ImageMarginGradientEnd
  3189.         {
  3190.             get { return BackColor; }
  3191.         }
  3192.  
  3193.         public override Color ImageMarginGradientMiddle
  3194.         {
  3195.             get { return BackColor; }
  3196.         }
  3197.  
  3198.         public override Color MenuBorder
  3199.         {
  3200.             get { return Color.FromArgb(25, 25, 25); }
  3201.         }
  3202.  
  3203.         public override Color MenuItemBorder
  3204.         {
  3205.             get { return BackColor; }
  3206.         }
  3207.  
  3208.         public override Color MenuItemSelected
  3209.         {
  3210.             get { return Color.FromArgb(65, 65, 65); }
  3211.         }
  3212.  
  3213.         public override Color SeparatorDark
  3214.         {
  3215.             get { return Color.FromArgb(35, 35, 35); }
  3216.         }
  3217.  
  3218.         public override Color ToolStripDropDownBackground
  3219.         {
  3220.             get { return BackColor; }
  3221.         }
  3222.  
  3223.     }
  3224.  
  3225. //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
  3226. //sick act of masochism by studying the source of the ListView then, may god have mercy on your soul.
  3227.     class NSListView : Control
  3228.     {
  3229.  
  3230.         public class NSListViewItem
  3231.         {
  3232.             public string Text { get; set; }
  3233.  
  3234.             [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  3235.             public List<NSListViewSubItem> SubItems { get; set; }
  3236.  
  3237.  
  3238.             protected Guid UniqueId;
  3239.  
  3240.             public NSListViewItem()
  3241.             {
  3242.                 UniqueId = Guid.NewGuid();
  3243.             }
  3244.  
  3245.             public override string ToString()
  3246.             {
  3247.                 return Text;
  3248.             }
  3249.  
  3250.             public override bool Equals(object obj)
  3251.             {
  3252.                 if (obj is NSListViewItem)
  3253.                 {
  3254.                     return (((NSListViewItem) obj).UniqueId == UniqueId);
  3255.                 }
  3256.  
  3257.                 return false;
  3258.             }
  3259.  
  3260.             public override int GetHashCode()
  3261.             {
  3262.                 return base.GetHashCode();
  3263.             }
  3264.  
  3265.         }
  3266.  
  3267.         public class NSListViewSubItem
  3268.         {
  3269.             public string Text { get; set; }
  3270.  
  3271.             public override string ToString()
  3272.             {
  3273.                 return Text;
  3274.             }
  3275.         }
  3276.  
  3277.         public class NSListViewColumnHeader
  3278.         {
  3279.             public string Text { get; set; }
  3280.             public int Width { get; set; }
  3281.  
  3282.             public override string ToString()
  3283.             {
  3284.                 return Text;
  3285.             }
  3286.         }
  3287.  
  3288.         private List<NSListViewItem> _Items = new List<NSListViewItem>();
  3289.  
  3290.         [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  3291.         public NSListViewItem[] Items
  3292.         {
  3293.             get { return _Items.ToArray(); }
  3294.             set
  3295.             {
  3296.                 _Items = new List<NSListViewItem>(value);
  3297.                 InvalidateScroll();
  3298.             }
  3299.         }
  3300.  
  3301.         private List<NSListViewItem> _SelectedItems = new List<NSListViewItem>();
  3302.  
  3303.         public NSListViewItem[] SelectedItems
  3304.         {
  3305.             get { return _SelectedItems.ToArray(); }
  3306.         }
  3307.  
  3308.         private List<NSListViewColumnHeader> _Columns = new List<NSListViewColumnHeader>();
  3309.  
  3310.         [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  3311.         public NSListViewColumnHeader[] Columns
  3312.         {
  3313.             get { return _Columns.ToArray(); }
  3314.             set
  3315.             {
  3316.                 _Columns = new List<NSListViewColumnHeader>(value);
  3317.                 InvalidateColumns();
  3318.             }
  3319.         }
  3320.  
  3321.         private bool _MultiSelect = true;
  3322.  
  3323.         public bool MultiSelect
  3324.         {
  3325.             get { return _MultiSelect; }
  3326.             set
  3327.             {
  3328.                 _MultiSelect = value;
  3329.  
  3330.                 if (_SelectedItems.Count > 1)
  3331.                 {
  3332.                     _SelectedItems.RemoveRange(1, _SelectedItems.Count - 1);
  3333.                 }
  3334.  
  3335.                 Invalidate();
  3336.             }
  3337.         }
  3338.  
  3339.         private int ItemHeight = 24;
  3340.  
  3341.         public override Font Font
  3342.         {
  3343.             get { return base.Font; }
  3344.             set
  3345.             {
  3346.                 ItemHeight = Convert.ToInt32(Graphics.FromHwnd(Handle).MeasureString("@", Font).Height) + 6;
  3347.  
  3348.                 if (VS != null)
  3349.                 {
  3350.                     VS.SmallChange = ItemHeight;
  3351.                     VS.LargeChange = ItemHeight;
  3352.                 }
  3353.  
  3354.                 base.Font = value;
  3355.                 InvalidateLayout();
  3356.             }
  3357.         }
  3358.  
  3359.         #region " Item Helper Methods "
  3360.  
  3361.         //Ok, you've seen everything of importance at this point; I am begging you to spare yourself. You must not read any further!
  3362.  
  3363.         public void AddItem(string text, params string[] subItems)
  3364.         {
  3365.             List<NSListViewSubItem> Items = new List<NSListViewSubItem>();
  3366.             foreach (string I in subItems)
  3367.             {
  3368.                 NSListViewSubItem SubItem = new NSListViewSubItem();
  3369.                 SubItem.Text = I;
  3370.                 Items.Add(SubItem);
  3371.             }
  3372.  
  3373.             NSListViewItem Item = new NSListViewItem();
  3374.             Item.Text = text;
  3375.             Item.SubItems = Items;
  3376.  
  3377.             _Items.Add(Item);
  3378.             InvalidateScroll();
  3379.         }
  3380.  
  3381.         public void RemoveItemAt(int index)
  3382.         {
  3383.             _Items.RemoveAt(index);
  3384.             InvalidateScroll();
  3385.         }
  3386.  
  3387.         public void RemoveItem(NSListViewItem item)
  3388.         {
  3389.             _Items.Remove(item);
  3390.             InvalidateScroll();
  3391.         }
  3392.  
  3393.         public void RemoveItems(NSListViewItem[] items)
  3394.         {
  3395.             foreach (NSListViewItem I in items)
  3396.             {
  3397.                 _Items.Remove(I);
  3398.             }
  3399.  
  3400.             InvalidateScroll();
  3401.         }
  3402.  
  3403.         #endregion
  3404.  
  3405.  
  3406.         private NSVScrollBar VS;
  3407.  
  3408.         public NSListView()
  3409.         {
  3410.             SetStyle((ControlStyles) 139286, true);
  3411.             SetStyle(ControlStyles.Selectable, true);
  3412.  
  3413.             P1 = new Pen(Color.FromArgb(55, 55, 55));
  3414.             P2 = new Pen(Color.FromArgb(35, 35, 35));
  3415.             P3 = new Pen(Color.FromArgb(65, 65, 65));
  3416.  
  3417.             B1 = new SolidBrush(Color.FromArgb(62, 62, 62));
  3418.             B2 = new SolidBrush(Color.FromArgb(65, 65, 65));
  3419.             B3 = new SolidBrush(Color.FromArgb(47, 47, 47));
  3420.             B4 = new SolidBrush(Color.FromArgb(50, 50, 50));
  3421.  
  3422.             VS = new NSVScrollBar();
  3423.             VS.SmallChange = ItemHeight;
  3424.             VS.LargeChange = ItemHeight;
  3425.  
  3426.             VS.Scroll += HandleScroll;
  3427.             VS.MouseDown += VS_MouseDown;
  3428.             Controls.Add(VS);
  3429.  
  3430.             InvalidateLayout();
  3431.         }
  3432.  
  3433.         protected override void OnSizeChanged(EventArgs e)
  3434.         {
  3435.             InvalidateLayout();
  3436.             base.OnSizeChanged(e);
  3437.         }
  3438.  
  3439.         private void HandleScroll(object sender)
  3440.         {
  3441.             Invalidate();
  3442.         }
  3443.  
  3444.         private void InvalidateScroll()
  3445.         {
  3446.             VS.Maximum = (_Items.Count*ItemHeight);
  3447.             Invalidate();
  3448.         }
  3449.  
  3450.         private void InvalidateLayout()
  3451.         {
  3452.             VS.Location = new Point(Width - VS.Width - 1, 1);
  3453.             VS.Size = new Size(18, Height - 2);
  3454.  
  3455.             Invalidate();
  3456.         }
  3457.  
  3458.         private int[] ColumnOffsets;
  3459.  
  3460.         private void InvalidateColumns()
  3461.         {
  3462.             int Width = 3;
  3463.             ColumnOffsets = new int[_Columns.Count];
  3464.  
  3465.             for (int I = 0; I <= _Columns.Count - 1; I++)
  3466.             {
  3467.                 ColumnOffsets[I] = Width;
  3468.                 Width += Columns[I].Width;
  3469.             }
  3470.  
  3471.             Invalidate();
  3472.         }
  3473.  
  3474.         private void VS_MouseDown(object sender, MouseEventArgs e)
  3475.         {
  3476.             Focus();
  3477.         }
  3478.  
  3479.         protected override void OnMouseDown(MouseEventArgs e)
  3480.         {
  3481.             Focus();
  3482.  
  3483.             if (e.Button == System.Windows.Forms.MouseButtons.Left)
  3484.             {
  3485.                 int Offset = Convert.ToInt32(VS.Percent*(VS.Maximum - (Height - (ItemHeight*2))));
  3486.                 int Index = ((e.Y + Offset - ItemHeight)/ItemHeight);
  3487.  
  3488.                 if (Index > _Items.Count - 1)
  3489.                     Index = -1;
  3490.  
  3491.                 if (!(Index == -1))
  3492.                 {
  3493.                     //TODO: Handle Shift key
  3494.  
  3495.                     if (ModifierKeys == Keys.Control && _MultiSelect)
  3496.                     {
  3497.                         if (_SelectedItems.Contains(_Items[Index]))
  3498.                         {
  3499.                             _SelectedItems.Remove(_Items[Index]);
  3500.                         }
  3501.                         else
  3502.                         {
  3503.                             _SelectedItems.Add(_Items[Index]);
  3504.                         }
  3505.                     }
  3506.                     else
  3507.                     {
  3508.                         _SelectedItems.Clear();
  3509.                         _SelectedItems.Add(_Items[Index]);
  3510.                     }
  3511.                 }
  3512.  
  3513.                 Invalidate();
  3514.             }
  3515.  
  3516.             base.OnMouseDown(e);
  3517.         }
  3518.  
  3519.         private Pen P1;
  3520.         private Pen P2;
  3521.         private Pen P3;
  3522.         private SolidBrush B1;
  3523.         private SolidBrush B2;
  3524.         private SolidBrush B3;
  3525.         private SolidBrush B4;
  3526.  
  3527.         private LinearGradientBrush GB1;
  3528.         //I am so sorry you have to witness this. I tried warning you. ;.;
  3529.  
  3530.         private Graphics G;
  3531.  
  3532.         protected override void OnPaint(PaintEventArgs e)
  3533.         {
  3534.             G = e.Graphics;
  3535.             G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  3536.  
  3537.             G.Clear(BackColor);
  3538.  
  3539.             int X = 0;
  3540.             int Y = 0;
  3541.             float H = 0;
  3542.  
  3543.             G.DrawRectangle(P1, 1, 1, Width - 3, Height - 3);
  3544.  
  3545.             Rectangle R1 = default(Rectangle);
  3546.             NSListViewItem CI = null;
  3547.  
  3548.             int Offset = Convert.ToInt32(VS.Percent*(VS.Maximum - (Height - (ItemHeight*2))));
  3549.  
  3550.             int StartIndex = 0;
  3551.             if (Offset == 0)
  3552.                 StartIndex = 0;
  3553.             else
  3554.                 StartIndex = (Offset/ItemHeight);
  3555.  
  3556.             int EndIndex = Math.Min(StartIndex + (Height/ItemHeight), _Items.Count - 1);
  3557.  
  3558.             for (int I = StartIndex; I <= EndIndex; I++)
  3559.             {
  3560.                 CI = Items[I];
  3561.  
  3562.                 R1 = new Rectangle(0, ItemHeight + (I*ItemHeight) + 1 - Offset, Width, ItemHeight - 1);
  3563.  
  3564.                 H = G.MeasureString(CI.Text, Font).Height;
  3565.                 Y = R1.Y + Convert.ToInt32((ItemHeight/2) - (H/2));
  3566.  
  3567.                 if (_SelectedItems.Contains(CI))
  3568.                 {
  3569.                     if (I%2 == 0)
  3570.                     {
  3571.                         G.FillRectangle(B1, R1);
  3572.                     }
  3573.                     else
  3574.                     {
  3575.                         G.FillRectangle(B2, R1);
  3576.                     }
  3577.                 }
  3578.                 else
  3579.                 {
  3580.                     if (I%2 == 0)
  3581.                     {
  3582.                         G.FillRectangle(B3, R1);
  3583.                     }
  3584.                     else
  3585.                     {
  3586.                         G.FillRectangle(B4, R1);
  3587.                     }
  3588.                 }
  3589.  
  3590.                 G.DrawLine(P2, 0, R1.Bottom, Width, R1.Bottom);
  3591.  
  3592.                 if (Columns.Length > 0)
  3593.                 {
  3594.                     R1.Width = Columns[0].Width;
  3595.                     G.SetClip(R1);
  3596.                 }
  3597.  
  3598.                 //TODO: Ellipse text that overhangs seperators.
  3599.                 G.DrawString(CI.Text, Font, Brushes.Black, 10, Y + 1);
  3600.                 G.DrawString(CI.Text, Font, Brushes.White, 9, Y);
  3601.  
  3602.                 if (CI.SubItems != null)
  3603.                 {
  3604.                     for (int I2 = 0; I2 <= Math.Min(CI.SubItems.Count, _Columns.Count) - 1; I2++)
  3605.                     {
  3606.                         X = ColumnOffsets[I2 + 1] + 4;
  3607.  
  3608.                         R1.X = X;
  3609.                         R1.Width = Columns[I2].Width;
  3610.                         G.SetClip(R1);
  3611.  
  3612.                         G.DrawString(CI.SubItems[I2].Text, Font, Brushes.Black, X + 1, Y + 1);
  3613.                         G.DrawString(CI.SubItems[I2].Text, Font, Brushes.White, X, Y);
  3614.                     }
  3615.                 }
  3616.  
  3617.                 G.ResetClip();
  3618.             }
  3619.  
  3620.             R1 = new Rectangle(0, 0, Width, ItemHeight);
  3621.  
  3622.             GB1 = new LinearGradientBrush(R1, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f);
  3623.             G.FillRectangle(GB1, R1);
  3624.             G.DrawRectangle(P3, 1, 1, Width - 22, ItemHeight - 2);
  3625.  
  3626.             int LH = Math.Min(VS.Maximum + ItemHeight - Offset, Height);
  3627.  
  3628.             NSListViewColumnHeader CC = null;
  3629.             for (int I = 0; I <= _Columns.Count - 1; I++)
  3630.             {
  3631.                 CC = Columns[I];
  3632.  
  3633.                 H = G.MeasureString(CC.Text, Font).Height;
  3634.                 Y = Convert.ToInt32((ItemHeight/2) - (H/2));
  3635.                 X = ColumnOffsets[I];
  3636.  
  3637.                 G.DrawString(CC.Text, Font, Brushes.Black, X + 1, Y + 1);
  3638.                 G.DrawString(CC.Text, Font, Brushes.White, X, Y);
  3639.  
  3640.                 G.DrawLine(P2, X - 3, 0, X - 3, LH);
  3641.                 G.DrawLine(P3, X - 2, 0, X - 2, ItemHeight);
  3642.             }
  3643.  
  3644.             G.DrawRectangle(P2, 0, 0, Width - 1, Height - 1);
  3645.  
  3646.             G.DrawLine(P2, 0, ItemHeight, Width, ItemHeight);
  3647.             G.DrawLine(P2, VS.Location.X - 1, 0, VS.Location.X - 1, Height);
  3648.         }
  3649.  
  3650.         protected override void OnMouseWheel(MouseEventArgs e)
  3651.         {
  3652.             int Move = -((e.Delta*SystemInformation.MouseWheelScrollLines/120)*(ItemHeight/2));
  3653.  
  3654.             int Value = Math.Max(Math.Min(VS.Value + Move, VS.Maximum), VS.Minimum);
  3655.             VS.Value = Value;
  3656.  
  3657.             base.OnMouseWheel(e);
  3658.         }
  3659.  
  3660.     }
  3661. }
  3662. namespace myForm {
  3663. using System;
  3664. using System.Collections.Generic;
  3665. using System.IO;
  3666. using System.Drawing;
  3667. using System.Drawing.Drawing2D;
  3668. using System.ComponentModel;
  3669. using System.Windows.Forms;
  3670. using System.Runtime.InteropServices;
  3671. using System.Drawing.Imaging;
  3672.  
  3673. //------------------
  3674. //Creator: aeonhack
  3675. //Site: elitevs.net
  3676. //Created: 08/02/2011
  3677. //Changed: 12/06/2011
  3678. //Version: 1.5.4
  3679. //------------------
  3680.  
  3681. abstract class ThemeContainer154 : ContainerControl
  3682. {
  3683.  
  3684.     #region " Initialization "
  3685.  
  3686.     protected Graphics G;
  3687.  
  3688.     protected Bitmap B;
  3689.     public ThemeContainer154()
  3690.     {
  3691.         SetStyle((ControlStyles)139270, true);
  3692.  
  3693.         _ImageSize = Size.Empty;
  3694.         Font = new Font("Verdana", 8);
  3695.  
  3696.         MeasureBitmap = new Bitmap(1, 1);
  3697.         MeasureGraphics = Graphics.FromImage(MeasureBitmap);
  3698.  
  3699.         DrawRadialPath = new GraphicsPath();
  3700.  
  3701.         InvalidateCustimization();
  3702.     }
  3703.  
  3704.     protected override sealed void OnHandleCreated(EventArgs e)
  3705.     {
  3706.         if (DoneCreation)
  3707.             InitializeMessages();
  3708.  
  3709.         InvalidateCustimization();
  3710.         ColorHook();
  3711.  
  3712.         if (!(_LockWidth == 0))
  3713.             Width = _LockWidth;
  3714.         if (!(_LockHeight == 0))
  3715.             Height = _LockHeight;
  3716.         if (!_ControlMode)
  3717.             base.Dock = DockStyle.Fill;
  3718.  
  3719.         Transparent = _Transparent;
  3720.         if (_Transparent && _BackColor)
  3721.             BackColor = Color.Transparent;
  3722.  
  3723.         base.OnHandleCreated(e);
  3724.     }
  3725.  
  3726.     private bool DoneCreation;
  3727.     protected override sealed void OnParentChanged(EventArgs e)
  3728.     {
  3729.         base.OnParentChanged(e);
  3730.  
  3731.         if (Parent == null)
  3732.             return;
  3733.         _IsParentForm = Parent is Form;
  3734.  
  3735.         if (!_ControlMode)
  3736.         {
  3737.             InitializeMessages();
  3738.  
  3739.             if (_IsParentForm)
  3740.             {
  3741.                 ParentForm.FormBorderStyle = _BorderStyle;
  3742.                 ParentForm.TransparencyKey = _TransparencyKey;
  3743.  
  3744.                 if (!DesignMode)
  3745.                 {
  3746.                     ParentForm.Shown += FormShown;
  3747.                 }
  3748.             }
  3749.  
  3750.             Parent.BackColor = BackColor;
  3751.         }
  3752.  
  3753.         OnCreation();
  3754.         DoneCreation = true;
  3755.         InvalidateTimer();
  3756.     }
  3757.  
  3758.     #endregion
  3759.  
  3760.     private void DoAnimation(bool i)
  3761.     {
  3762.         OnAnimation();
  3763.         if (i)
  3764.             Invalidate();
  3765.     }
  3766.  
  3767.     protected override sealed void OnPaint(PaintEventArgs e)
  3768.     {
  3769.         if (Width == 0 || Height == 0)
  3770.             return;
  3771.  
  3772.         if (_Transparent && _ControlMode)
  3773.         {
  3774.             PaintHook();
  3775.             e.Graphics.DrawImage(B, 0, 0);
  3776.         }
  3777.         else
  3778.         {
  3779.             G = e.Graphics;
  3780.             PaintHook();
  3781.         }
  3782.     }
  3783.  
  3784.     protected override void OnHandleDestroyed(EventArgs e)
  3785.     {
  3786.         ThemeShare.RemoveAnimationCallback(DoAnimation);
  3787.         base.OnHandleDestroyed(e);
  3788.     }
  3789.  
  3790.     private bool HasShown;
  3791.     private void FormShown(object sender, EventArgs e)
  3792.     {
  3793.         if (_ControlMode || HasShown)
  3794.             return;
  3795.  
  3796.         if (_StartPosition == FormStartPosition.CenterParent || _StartPosition == FormStartPosition.CenterScreen)
  3797.         {
  3798.             Rectangle SB = Screen.PrimaryScreen.Bounds;
  3799.             Rectangle CB = ParentForm.Bounds;
  3800.             ParentForm.Location = new Point(SB.Width / 2 - CB.Width / 2, SB.Height / 2 - CB.Width / 2);
  3801.         }
  3802.  
  3803.         HasShown = true;
  3804.     }
  3805.  
  3806.  
  3807.     #region " Size Handling "
  3808.  
  3809.     private Rectangle Frame;
  3810.     protected override sealed void OnSizeChanged(EventArgs e)
  3811.     {
  3812.         if (_Movable && !_ControlMode)
  3813.         {
  3814.             Frame = new Rectangle(7, 7, Width - 14, _Header - 7);
  3815.         }
  3816.  
  3817.         InvalidateBitmap();
  3818.         Invalidate();
  3819.  
  3820.         base.OnSizeChanged(e);
  3821.     }
  3822.  
  3823.     protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
  3824.     {
  3825.         if (!(_LockWidth == 0))
  3826.             width = _LockWidth;
  3827.         if (!(_LockHeight == 0))
  3828.             height = _LockHeight;
  3829.         base.SetBoundsCore(x, y, width, height, specified);
  3830.     }
  3831.  
  3832.     #endregion
  3833.  
  3834.     #region " State Handling "
  3835.  
  3836.     protected MouseState State;
  3837.     private void SetState(MouseState current)
  3838.     {
  3839.         State = current;
  3840.         Invalidate();
  3841.     }
  3842.  
  3843.     protected override void OnMouseMove(MouseEventArgs e)
  3844.     {
  3845.         if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized))
  3846.         {
  3847.             if (_Sizable && !_ControlMode)
  3848.                 InvalidateMouse();
  3849.         }
  3850.  
  3851.         base.OnMouseMove(e);
  3852.     }
  3853.  
  3854.     protected override void OnEnabledChanged(EventArgs e)
  3855.     {
  3856.         if (Enabled)
  3857.             SetState(MouseState.None);
  3858.         else
  3859.             SetState(MouseState.Block);
  3860.         base.OnEnabledChanged(e);
  3861.     }
  3862.  
  3863.     protected override void OnMouseEnter(EventArgs e)
  3864.     {
  3865.         SetState(MouseState.Over);
  3866.         base.OnMouseEnter(e);
  3867.     }
  3868.  
  3869.     protected override void OnMouseUp(MouseEventArgs e)
  3870.     {
  3871.         SetState(MouseState.Over);
  3872.         base.OnMouseUp(e);
  3873.     }
  3874.  
  3875.     protected override void OnMouseLeave(EventArgs e)
  3876.     {
  3877.         SetState(MouseState.None);
  3878.  
  3879.         if (GetChildAtPoint(PointToClient(MousePosition)) != null)
  3880.         {
  3881.             if (_Sizable && !_ControlMode)
  3882.             {
  3883.                 Cursor = Cursors.Default;
  3884.                 Previous = 0;
  3885.             }
  3886.         }
  3887.  
  3888.         base.OnMouseLeave(e);
  3889.     }
  3890.  
  3891.     protected override void OnMouseDown(MouseEventArgs e)
  3892.     {
  3893.         if (e.Button == System.Windows.Forms.MouseButtons.Left)
  3894.             SetState(MouseState.Down);
  3895.  
  3896.         if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized || _ControlMode))
  3897.         {
  3898.             if (_Movable && Frame.Contains(e.Location))
  3899.             {
  3900.                 Capture = false;
  3901.                 WM_LMBUTTONDOWN = true;
  3902.                 DefWndProc(ref Messages[0]);
  3903.             }
  3904.             else if (_Sizable && !(Previous == 0))
  3905.             {
  3906.                 Capture = false;
  3907.                 WM_LMBUTTONDOWN = true;
  3908.                 DefWndProc(ref Messages[Previous]);
  3909.             }
  3910.         }
  3911.  
  3912.         base.OnMouseDown(e);
  3913.     }
  3914.  
  3915.     private bool WM_LMBUTTONDOWN;
  3916.     protected override void WndProc(ref Message m)
  3917.     {
  3918.         base.WndProc(ref m);
  3919.  
  3920.         if (WM_LMBUTTONDOWN && m.Msg == 513)
  3921.         {
  3922.             WM_LMBUTTONDOWN = false;
  3923.  
  3924.             SetState(MouseState.Over);
  3925.             if (!_SmartBounds)
  3926.                 return;
  3927.  
  3928.             if (IsParentMdi)
  3929.             {
  3930.                 CorrectBounds(new Rectangle(Point.Empty, Parent.Parent.Size));
  3931.             }
  3932.             else
  3933.             {
  3934.                 CorrectBounds(Screen.FromControl(Parent).WorkingArea);
  3935.             }
  3936.         }
  3937.     }
  3938.  
  3939.     private Point GetIndexPoint;
  3940.     private bool B1;
  3941.     private bool B2;
  3942.     private bool B3;
  3943.     private bool B4;
  3944.     private int GetIndex()
  3945.     {
  3946.         GetIndexPoint = PointToClient(MousePosition);
  3947.         B1 = GetIndexPoint.X < 7;
  3948.         B2 = GetIndexPoint.X > Width - 7;
  3949.         B3 = GetIndexPoint.Y < 7;
  3950.         B4 = GetIndexPoint.Y > Height - 7;
  3951.  
  3952.         if (B1 && B3)
  3953.             return 4;
  3954.         if (B1 && B4)
  3955.             return 7;
  3956.         if (B2 && B3)
  3957.             return 5;
  3958.         if (B2 && B4)
  3959.             return 8;
  3960.         if (B1)
  3961.             return 1;
  3962.         if (B2)
  3963.             return 2;
  3964.         if (B3)
  3965.             return 3;
  3966.         if (B4)
  3967.             return 6;
  3968.         return 0;
  3969.     }
  3970.  
  3971.     private int Current;
  3972.     private int Previous;
  3973.     private void InvalidateMouse()
  3974.     {
  3975.         Current = GetIndex();
  3976.         if (Current == Previous)
  3977.             return;
  3978.  
  3979.         Previous = Current;
  3980.         switch (Previous)
  3981.         {
  3982.             case 0:
  3983.                 Cursor = Cursors.Default;
  3984.                 break;
  3985.             case 1:
  3986.             case 2:
  3987.                 Cursor = Cursors.SizeWE;
  3988.                 break;
  3989.             case 3:
  3990.             case 6:
  3991.                 Cursor = Cursors.SizeNS;
  3992.                 break;
  3993.             case 4:
  3994.             case 8:
  3995.                 Cursor = Cursors.SizeNWSE;
  3996.                 break;
  3997.             case 5:
  3998.             case 7:
  3999.                 Cursor = Cursors.SizeNESW;
  4000.                 break;
  4001.         }
  4002.     }
  4003.  
  4004.     private Message[] Messages = new Message[9];
  4005.     private void InitializeMessages()
  4006.     {
  4007.         Messages[0] = Message.Create(Parent.Handle, 161, new IntPtr(2), IntPtr.Zero);
  4008.         for (int I = 1; I <= 8; I++)
  4009.         {
  4010.             Messages[I] = Message.Create(Parent.Handle, 161, new IntPtr(I + 9), IntPtr.Zero);
  4011.         }
  4012.     }
  4013.  
  4014.     private void CorrectBounds(Rectangle bounds)
  4015.     {
  4016.         if (Parent.Width > bounds.Width)
  4017.             Parent.Width = bounds.Width;
  4018.         if (Parent.Height > bounds.Height)
  4019.             Parent.Height = bounds.Height;
  4020.  
  4021.         int X = Parent.Location.X;
  4022.         int Y = Parent.Location.Y;
  4023.  
  4024.         if (X < bounds.X)
  4025.             X = bounds.X;
  4026.         if (Y < bounds.Y)
  4027.             Y = bounds.Y;
  4028.  
  4029.         int Width = bounds.X + bounds.Width;
  4030.         int Height = bounds.Y + bounds.Height;
  4031.  
  4032.         if (X + Parent.Width > Width)
  4033.             X = Width - Parent.Width;
  4034.         if (Y + Parent.Height > Height)
  4035.             Y = Height - Parent.Height;
  4036.  
  4037.         Parent.Location = new Point(X, Y);
  4038.     }
  4039.  
  4040.     #endregion
  4041.  
  4042.  
  4043.     #region " Base Properties "
  4044.  
  4045.     public override DockStyle Dock
  4046.     {
  4047.         get { return base.Dock; }
  4048.         set
  4049.         {
  4050.             if (!_ControlMode)
  4051.                 return;
  4052.             base.Dock = value;
  4053.         }
  4054.     }
  4055.  
  4056.     private bool _BackColor;
  4057.     [Category("Misc")]
  4058.     public override Color BackColor
  4059.     {
  4060.         get { return base.BackColor; }
  4061.         set
  4062.         {
  4063.             if (value == base.BackColor)
  4064.                 return;
  4065.  
  4066.             if (!IsHandleCreated && _ControlMode && value == Color.Transparent)
  4067.             {
  4068.                 _BackColor = true;
  4069.                 return;
  4070.             }
  4071.  
  4072.             base.BackColor = value;
  4073.             if (Parent != null)
  4074.             {
  4075.                 if (!_ControlMode)
  4076.                     Parent.BackColor = value;
  4077.                 ColorHook();
  4078.             }
  4079.         }
  4080.     }
  4081.  
  4082.     public override Size MinimumSize
  4083.     {
  4084.         get { return base.MinimumSize; }
  4085.         set
  4086.         {
  4087.             base.MinimumSize = value;
  4088.             if (Parent != null)
  4089.                 Parent.MinimumSize = value;
  4090.         }
  4091.     }
  4092.  
  4093.     public override Size MaximumSize
  4094.     {
  4095.         get { return base.MaximumSize; }
  4096.         set
  4097.         {
  4098.             base.MaximumSize = value;
  4099.             if (Parent != null)
  4100.                 Parent.MaximumSize = value;
  4101.         }
  4102.     }
  4103.  
  4104.     public override string Text
  4105.     {
  4106.         get { return base.Text; }
  4107.         set
  4108.         {
  4109.             base.Text = value;
  4110.             Invalidate();
  4111.         }
  4112.     }
  4113.  
  4114.     public override Font Font
  4115.     {
  4116.         get { return base.Font; }
  4117.         set
  4118.         {
  4119.             base.Font = value;
  4120.             Invalidate();
  4121.         }
  4122.     }
  4123.  
  4124.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  4125.     public override Color ForeColor
  4126.     {
  4127.         get { return Color.Empty; }
  4128.         set { }
  4129.     }
  4130.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  4131.     public override Image BackgroundImage
  4132.     {
  4133.         get { return null; }
  4134.         set { }
  4135.     }
  4136.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  4137.     public override ImageLayout BackgroundImageLayout
  4138.     {
  4139.         get { return ImageLayout.None; }
  4140.         set { }
  4141.     }
  4142.  
  4143.     #endregion
  4144.  
  4145.     #region " Public Properties "
  4146.  
  4147.     private bool _SmartBounds = true;
  4148.     public bool SmartBounds
  4149.     {
  4150.         get { return _SmartBounds; }
  4151.         set { _SmartBounds = value; }
  4152.     }
  4153.  
  4154.     private bool _Movable = true;
  4155.     public bool Movable
  4156.     {
  4157.         get { return _Movable; }
  4158.         set { _Movable = value; }
  4159.     }
  4160.  
  4161.     private bool _Sizable = true;
  4162.     public bool Sizable
  4163.     {
  4164.         get { return _Sizable; }
  4165.         set { _Sizable = value; }
  4166.     }
  4167.  
  4168.     private Color _TransparencyKey;
  4169.     public Color TransparencyKey
  4170.     {
  4171.         get
  4172.         {
  4173.             if (_IsParentForm && !_ControlMode)
  4174.                 return ParentForm.TransparencyKey;
  4175.             else
  4176.                 return _TransparencyKey;
  4177.         }
  4178.         set
  4179.         {
  4180.             if (value == _TransparencyKey)
  4181.                 return;
  4182.             _TransparencyKey = value;
  4183.  
  4184.             if (_IsParentForm && !_ControlMode)
  4185.             {
  4186.                 ParentForm.TransparencyKey = value;
  4187.                 ColorHook();
  4188.             }
  4189.         }
  4190.     }
  4191.  
  4192.     private FormBorderStyle _BorderStyle;
  4193.     public FormBorderStyle BorderStyle
  4194.     {
  4195.         get
  4196.         {
  4197.             if (_IsParentForm && !_ControlMode)
  4198.                 return ParentForm.FormBorderStyle;
  4199.             else
  4200.                 return _BorderStyle;
  4201.         }
  4202.         set
  4203.         {
  4204.             _BorderStyle = value;
  4205.  
  4206.             if (_IsParentForm && !_ControlMode)
  4207.             {
  4208.                 ParentForm.FormBorderStyle = value;
  4209.  
  4210.                 if (!(value == FormBorderStyle.None))
  4211.                 {
  4212.                     Movable = false;
  4213.                     Sizable = false;
  4214.                 }
  4215.             }
  4216.         }
  4217.     }
  4218.  
  4219.     private FormStartPosition _StartPosition;
  4220.     public FormStartPosition StartPosition
  4221.     {
  4222.         get
  4223.         {
  4224.             if (_IsParentForm && !_ControlMode)
  4225.                 return ParentForm.StartPosition;
  4226.             else
  4227.                 return _StartPosition;
  4228.         }
  4229.         set
  4230.         {
  4231.             _StartPosition = value;
  4232.  
  4233.             if (_IsParentForm && !_ControlMode)
  4234.             {
  4235.                 ParentForm.StartPosition = value;
  4236.             }
  4237.         }
  4238.     }
  4239.  
  4240.     private bool _NoRounding;
  4241.     public bool NoRounding
  4242.     {
  4243.         get { return _NoRounding; }
  4244.         set
  4245.         {
  4246.             _NoRounding = value;
  4247.             Invalidate();
  4248.         }
  4249.     }
  4250.  
  4251.     private Image _Image;
  4252.     public Image Image
  4253.     {
  4254.         get { return _Image; }
  4255.         set
  4256.         {
  4257.             if (value == null)
  4258.                 _ImageSize = Size.Empty;
  4259.             else
  4260.                 _ImageSize = value.Size;
  4261.  
  4262.             _Image = value;
  4263.             Invalidate();
  4264.         }
  4265.     }
  4266.  
  4267.     private Dictionary<string, Color> Items = new Dictionary<string, Color>();
  4268.     public Bloom[] Colors
  4269.     {
  4270.         get
  4271.         {
  4272.             List<Bloom> T = new List<Bloom>();
  4273.             Dictionary<string, Color>.Enumerator E = Items.GetEnumerator();
  4274.  
  4275.             while (E.MoveNext())
  4276.             {
  4277.                 T.Add(new Bloom(E.Current.Key, E.Current.Value));
  4278.             }
  4279.  
  4280.             return T.ToArray();
  4281.         }
  4282.         set
  4283.         {
  4284.             foreach (Bloom B in value)
  4285.             {
  4286.                 if (Items.ContainsKey(B.Name))
  4287.                     Items[B.Name] = B.Value;
  4288.             }
  4289.  
  4290.             InvalidateCustimization();
  4291.             ColorHook();
  4292.             Invalidate();
  4293.         }
  4294.     }
  4295.  
  4296.     private string _Customization;
  4297.     public string Customization
  4298.     {
  4299.         get { return _Customization; }
  4300.         set
  4301.         {
  4302.             if (value == _Customization)
  4303.                 return;
  4304.  
  4305.             byte[] Data = null;
  4306.             Bloom[] Items = Colors;
  4307.  
  4308.             try
  4309.             {
  4310.                 Data = Convert.FromBase64String(value);
  4311.                 for (int I = 0; I <= Items.Length - 1; I++)
  4312.                 {
  4313.                     Items[I].Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
  4314.                 }
  4315.             }
  4316.             catch
  4317.             {
  4318.                 return;
  4319.             }
  4320.  
  4321.             _Customization = value;
  4322.  
  4323.             Colors = Items;
  4324.             ColorHook();
  4325.             Invalidate();
  4326.         }
  4327.     }
  4328.  
  4329.     private bool _Transparent;
  4330.     public bool Transparent
  4331.     {
  4332.         get { return _Transparent; }
  4333.         set
  4334.         {
  4335.             _Transparent = value;
  4336.             if (!(IsHandleCreated || _ControlMode))
  4337.                 return;
  4338.  
  4339.             if (!value && !(BackColor.A == 255))
  4340.             {
  4341.                 throw new Exception("Unable to change value to false while a transparent BackColor is in use.");
  4342.             }
  4343.  
  4344.             SetStyle(ControlStyles.Opaque, !value);
  4345.             SetStyle(ControlStyles.SupportsTransparentBackColor, value);
  4346.  
  4347.             InvalidateBitmap();
  4348.             Invalidate();
  4349.         }
  4350.     }
  4351.  
  4352.     #endregion
  4353.  
  4354.     #region " Private Properties "
  4355.  
  4356.     private Size _ImageSize;
  4357.     protected Size ImageSize
  4358.     {
  4359.         get { return _ImageSize; }
  4360.     }
  4361.  
  4362.     private bool _IsParentForm;
  4363.     protected bool IsParentForm
  4364.     {
  4365.         get { return _IsParentForm; }
  4366.     }
  4367.  
  4368.     protected bool IsParentMdi
  4369.     {
  4370.         get
  4371.         {
  4372.             if (Parent == null)
  4373.                 return false;
  4374.             return Parent.Parent != null;
  4375.         }
  4376.     }
  4377.  
  4378.     private int _LockWidth;
  4379.     protected int LockWidth
  4380.     {
  4381.         get { return _LockWidth; }
  4382.         set
  4383.         {
  4384.             _LockWidth = value;
  4385.             if (!(LockWidth == 0) && IsHandleCreated)
  4386.                 Width = LockWidth;
  4387.         }
  4388.     }
  4389.  
  4390.     private int _LockHeight;
  4391.     protected int LockHeight
  4392.     {
  4393.         get { return _LockHeight; }
  4394.         set
  4395.         {
  4396.             _LockHeight = value;
  4397.             if (!(LockHeight == 0) && IsHandleCreated)
  4398.                 Height = LockHeight;
  4399.         }
  4400.     }
  4401.  
  4402.     private int _Header = 24;
  4403.     protected int Header
  4404.     {
  4405.         get { return _Header; }
  4406.         set
  4407.         {
  4408.             _Header = value;
  4409.  
  4410.             if (!_ControlMode)
  4411.             {
  4412.                 Frame = new Rectangle(7, 7, Width - 14, value - 7);
  4413.                 Invalidate();
  4414.             }
  4415.         }
  4416.     }
  4417.  
  4418.     private bool _ControlMode;
  4419.     protected bool ControlMode
  4420.     {
  4421.         get { return _ControlMode; }
  4422.         set
  4423.         {
  4424.             _ControlMode = value;
  4425.  
  4426.             Transparent = _Transparent;
  4427.             if (_Transparent && _BackColor)
  4428.                 BackColor = Color.Transparent;
  4429.  
  4430.             InvalidateBitmap();
  4431.             Invalidate();
  4432.         }
  4433.     }
  4434.  
  4435.     private bool _IsAnimated;
  4436.     protected bool IsAnimated
  4437.     {
  4438.         get { return _IsAnimated; }
  4439.         set
  4440.         {
  4441.             _IsAnimated = value;
  4442.             InvalidateTimer();
  4443.         }
  4444.     }
  4445.  
  4446.     #endregion
  4447.  
  4448.  
  4449.     #region " Property Helpers "
  4450.  
  4451.     protected Pen GetPen(string name)
  4452.     {
  4453.         return new Pen(Items[name]);
  4454.     }
  4455.     protected Pen GetPen(string name, float width)
  4456.     {
  4457.         return new Pen(Items[name], width);
  4458.     }
  4459.  
  4460.     protected SolidBrush GetBrush(string name)
  4461.     {
  4462.         return new SolidBrush(Items[name]);
  4463.     }
  4464.  
  4465.     protected Color GetColor(string name)
  4466.     {
  4467.         return Items[name];
  4468.     }
  4469.  
  4470.     protected void SetColor(string name, Color value)
  4471.     {
  4472.         if (Items.ContainsKey(name))
  4473.             Items[name] = value;
  4474.         else
  4475.             Items.Add(name, value);
  4476.     }
  4477.     protected void SetColor(string name, byte r, byte g, byte b)
  4478.     {
  4479.         SetColor(name, Color.FromArgb(r, g, b));
  4480.     }
  4481.     protected void SetColor(string name, byte a, byte r, byte g, byte b)
  4482.     {
  4483.         SetColor(name, Color.FromArgb(a, r, g, b));
  4484.     }
  4485.     protected void SetColor(string name, byte a, Color value)
  4486.     {
  4487.         SetColor(name, Color.FromArgb(a, value));
  4488.     }
  4489.  
  4490.     private void InvalidateBitmap()
  4491.     {
  4492.         if (_Transparent && _ControlMode)
  4493.         {
  4494.             if (Width == 0 || Height == 0)
  4495.                 return;
  4496.             B = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
  4497.             G = Graphics.FromImage(B);
  4498.         }
  4499.         else
  4500.         {
  4501.             G = null;
  4502.             B = null;
  4503.         }
  4504.     }
  4505.  
  4506.     private void InvalidateCustimization()
  4507.     {
  4508.         MemoryStream M = new MemoryStream(Items.Count * 4);
  4509.  
  4510.         foreach (Bloom B in Colors)
  4511.         {
  4512.             M.Write(BitConverter.GetBytes(B.Value.ToArgb()), 0, 4);
  4513.         }
  4514.  
  4515.         M.Close();
  4516.         _Customization = Convert.ToBase64String(M.ToArray());
  4517.     }
  4518.  
  4519.     private void InvalidateTimer()
  4520.     {
  4521.         if (DesignMode || !DoneCreation)
  4522.             return;
  4523.  
  4524.         if (_IsAnimated)
  4525.         {
  4526.             ThemeShare.AddAnimationCallback(DoAnimation);
  4527.         }
  4528.         else
  4529.         {
  4530.             ThemeShare.RemoveAnimationCallback(DoAnimation);
  4531.         }
  4532.     }
  4533.  
  4534.     #endregion
  4535.  
  4536.  
  4537.     #region " User Hooks "
  4538.  
  4539.     protected abstract void ColorHook();
  4540.     protected abstract void PaintHook();
  4541.  
  4542.     protected virtual void OnCreation()
  4543.     {
  4544.     }
  4545.  
  4546.     protected virtual void OnAnimation()
  4547.     {
  4548.     }
  4549.  
  4550.     #endregion
  4551.  
  4552.  
  4553.     #region " Offset "
  4554.  
  4555.     private Rectangle OffsetReturnRectangle;
  4556.     protected Rectangle Offset(Rectangle r, int amount)
  4557.     {
  4558.         OffsetReturnRectangle = new Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2));
  4559.         return OffsetReturnRectangle;
  4560.     }
  4561.  
  4562.     private Size OffsetReturnSize;
  4563.     protected Size Offset(Size s, int amount)
  4564.     {
  4565.         OffsetReturnSize = new Size(s.Width + amount, s.Height + amount);
  4566.         return OffsetReturnSize;
  4567.     }
  4568.  
  4569.     private Point OffsetReturnPoint;
  4570.     protected Point Offset(Point p, int amount)
  4571.     {
  4572.         OffsetReturnPoint = new Point(p.X + amount, p.Y + amount);
  4573.         return OffsetReturnPoint;
  4574.     }
  4575.  
  4576.     #endregion
  4577.  
  4578.     #region " Center "
  4579.  
  4580.  
  4581.     private Point CenterReturn;
  4582.     protected Point Center(Rectangle p, Rectangle c)
  4583.     {
  4584.         CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X + c.X, (p.Height / 2 - c.Height / 2) + p.Y + c.Y);
  4585.         return CenterReturn;
  4586.     }
  4587.     protected Point Center(Rectangle p, Size c)
  4588.     {
  4589.         CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X, (p.Height / 2 - c.Height / 2) + p.Y);
  4590.         return CenterReturn;
  4591.     }
  4592.  
  4593.     protected Point Center(Rectangle child)
  4594.     {
  4595.         return Center(Width, Height, child.Width, child.Height);
  4596.     }
  4597.     protected Point Center(Size child)
  4598.     {
  4599.         return Center(Width, Height, child.Width, child.Height);
  4600.     }
  4601.     protected Point Center(int childWidth, int childHeight)
  4602.     {
  4603.         return Center(Width, Height, childWidth, childHeight);
  4604.     }
  4605.  
  4606.     protected Point Center(Size p, Size c)
  4607.     {
  4608.         return Center(p.Width, p.Height, c.Width, c.Height);
  4609.     }
  4610.  
  4611.     protected Point Center(int pWidth, int pHeight, int cWidth, int cHeight)
  4612.     {
  4613.         CenterReturn = new Point(pWidth / 2 - cWidth / 2, pHeight / 2 - cHeight / 2);
  4614.         return CenterReturn;
  4615.     }
  4616.  
  4617.     #endregion
  4618.  
  4619.     #region " Measure "
  4620.  
  4621.     private Bitmap MeasureBitmap;
  4622.  
  4623.     private Graphics MeasureGraphics;
  4624.     protected Size Measure()
  4625.     {
  4626.         lock (MeasureGraphics)
  4627.         {
  4628.             return MeasureGraphics.MeasureString(Text, Font, Width).ToSize();
  4629.         }
  4630.     }
  4631.     protected Size Measure(string text)
  4632.     {
  4633.         lock (MeasureGraphics)
  4634.         {
  4635.             return MeasureGraphics.MeasureString(text, Font, Width).ToSize();
  4636.         }
  4637.     }
  4638.  
  4639.     #endregion
  4640.  
  4641.  
  4642.     #region " DrawPixel "
  4643.  
  4644.  
  4645.     private SolidBrush DrawPixelBrush;
  4646.     protected void DrawPixel(Color c1, int x, int y)
  4647.     {
  4648.         if (_Transparent)
  4649.         {
  4650.             B.SetPixel(x, y, c1);
  4651.         }
  4652.         else
  4653.         {
  4654.             DrawPixelBrush = new SolidBrush(c1);
  4655.             G.FillRectangle(DrawPixelBrush, x, y, 1, 1);
  4656.         }
  4657.     }
  4658.  
  4659.     #endregion
  4660.  
  4661.     #region " DrawCorners "
  4662.  
  4663.  
  4664.     private SolidBrush DrawCornersBrush;
  4665.     protected void DrawCorners(Color c1, int offset)
  4666.     {
  4667.         DrawCorners(c1, 0, 0, Width, Height, offset);
  4668.     }
  4669.     protected void DrawCorners(Color c1, Rectangle r1, int offset)
  4670.     {
  4671.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset);
  4672.     }
  4673.     protected void DrawCorners(Color c1, int x, int y, int width, int height, int offset)
  4674.     {
  4675.         DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  4676.     }
  4677.  
  4678.     protected void DrawCorners(Color c1)
  4679.     {
  4680.         DrawCorners(c1, 0, 0, Width, Height);
  4681.     }
  4682.     protected void DrawCorners(Color c1, Rectangle r1)
  4683.     {
  4684.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
  4685.     }
  4686.     protected void DrawCorners(Color c1, int x, int y, int width, int height)
  4687.     {
  4688.         if (_NoRounding)
  4689.             return;
  4690.  
  4691.         if (_Transparent)
  4692.         {
  4693.             B.SetPixel(x, y, c1);
  4694.             B.SetPixel(x + (width - 1), y, c1);
  4695.             B.SetPixel(x, y + (height - 1), c1);
  4696.             B.SetPixel(x + (width - 1), y + (height - 1), c1);
  4697.         }
  4698.         else
  4699.         {
  4700.             DrawCornersBrush = new SolidBrush(c1);
  4701.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
  4702.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
  4703.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
  4704.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
  4705.         }
  4706.     }
  4707.  
  4708.     #endregion
  4709.  
  4710.     #region " DrawBorders "
  4711.  
  4712.     protected void DrawBorders(Pen p1, int offset)
  4713.     {
  4714.         DrawBorders(p1, 0, 0, Width, Height, offset);
  4715.     }
  4716.     protected void DrawBorders(Pen p1, Rectangle r, int offset)
  4717.     {
  4718.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
  4719.     }
  4720.     protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
  4721.     {
  4722.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  4723.     }
  4724.  
  4725.     protected void DrawBorders(Pen p1)
  4726.     {
  4727.         DrawBorders(p1, 0, 0, Width, Height);
  4728.     }
  4729.     protected void DrawBorders(Pen p1, Rectangle r)
  4730.     {
  4731.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
  4732.     }
  4733.     protected void DrawBorders(Pen p1, int x, int y, int width, int height)
  4734.     {
  4735.         G.DrawRectangle(p1, x, y, width - 1, height - 1);
  4736.     }
  4737.  
  4738.     #endregion
  4739.  
  4740.     #region " DrawText "
  4741.  
  4742.     private Point DrawTextPoint;
  4743.  
  4744.     private Size DrawTextSize;
  4745.     protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
  4746.     {
  4747.         DrawText(b1, Text, a, x, y);
  4748.     }
  4749.     protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
  4750.     {
  4751.         if (text.Length == 0)
  4752.             return;
  4753.  
  4754.         DrawTextSize = Measure(text);
  4755.         DrawTextPoint = new Point(Width / 2 - DrawTextSize.Width / 2, Header / 2 - DrawTextSize.Height / 2);
  4756.  
  4757.         switch (a)
  4758.         {
  4759.             case HorizontalAlignment.Left:
  4760.                 G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y);
  4761.                 break;
  4762.             case HorizontalAlignment.Center:
  4763.                 G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y);
  4764.                 break;
  4765.             case HorizontalAlignment.Right:
  4766.                 G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
  4767.                 break;
  4768.         }
  4769.     }
  4770.  
  4771.     protected void DrawText(Brush b1, Point p1)
  4772.     {
  4773.         if (Text.Length == 0)
  4774.             return;
  4775.         G.DrawString(Text, Font, b1, p1);
  4776.     }
  4777.     protected void DrawText(Brush b1, int x, int y)
  4778.     {
  4779.         if (Text.Length == 0)
  4780.             return;
  4781.         G.DrawString(Text, Font, b1, x, y);
  4782.     }
  4783.  
  4784.     #endregion
  4785.  
  4786.     #region " DrawImage "
  4787.  
  4788.  
  4789.     private Point DrawImagePoint;
  4790.     protected void DrawImage(HorizontalAlignment a, int x, int y)
  4791.     {
  4792.         DrawImage(_Image, a, x, y);
  4793.     }
  4794.     protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
  4795.     {
  4796.         if (image == null)
  4797.             return;
  4798.         DrawImagePoint = new Point(Width / 2 - image.Width / 2, Header / 2 - image.Height / 2);
  4799.  
  4800.         switch (a)
  4801.         {
  4802.             case HorizontalAlignment.Left:
  4803.                 G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height);
  4804.                 break;
  4805.             case HorizontalAlignment.Center:
  4806.                 G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height);
  4807.                 break;
  4808.             case HorizontalAlignment.Right:
  4809.                 G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height);
  4810.                 break;
  4811.         }
  4812.     }
  4813.  
  4814.     protected void DrawImage(Point p1)
  4815.     {
  4816.         DrawImage(_Image, p1.X, p1.Y);
  4817.     }
  4818.     protected void DrawImage(int x, int y)
  4819.     {
  4820.         DrawImage(_Image, x, y);
  4821.     }
  4822.  
  4823.     protected void DrawImage(Image image, Point p1)
  4824.     {
  4825.         DrawImage(image, p1.X, p1.Y);
  4826.     }
  4827.     protected void DrawImage(Image image, int x, int y)
  4828.     {
  4829.         if (image == null)
  4830.             return;
  4831.         G.DrawImage(image, x, y, image.Width, image.Height);
  4832.     }
  4833.  
  4834.     #endregion
  4835.  
  4836.     #region " DrawGradient "
  4837.  
  4838.     private LinearGradientBrush DrawGradientBrush;
  4839.  
  4840.     private Rectangle DrawGradientRectangle;
  4841.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
  4842.     {
  4843.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  4844.         DrawGradient(blend, DrawGradientRectangle);
  4845.     }
  4846.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
  4847.     {
  4848.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  4849.         DrawGradient(blend, DrawGradientRectangle, angle);
  4850.     }
  4851.  
  4852.     protected void DrawGradient(ColorBlend blend, Rectangle r)
  4853.     {
  4854.         DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, 90f);
  4855.         DrawGradientBrush.InterpolationColors = blend;
  4856.         G.FillRectangle(DrawGradientBrush, r);
  4857.     }
  4858.     protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
  4859.     {
  4860.         DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
  4861.         DrawGradientBrush.InterpolationColors = blend;
  4862.         G.FillRectangle(DrawGradientBrush, r);
  4863.     }
  4864.  
  4865.  
  4866.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
  4867.     {
  4868.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  4869.         DrawGradient(c1, c2, DrawGradientRectangle);
  4870.     }
  4871.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
  4872.     {
  4873.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  4874.         DrawGradient(c1, c2, DrawGradientRectangle, angle);
  4875.     }
  4876.  
  4877.     protected void DrawGradient(Color c1, Color c2, Rectangle r)
  4878.     {
  4879.         DrawGradientBrush = new LinearGradientBrush(r, c1, c2, 90f);
  4880.         G.FillRectangle(DrawGradientBrush, r);
  4881.     }
  4882.     protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
  4883.     {
  4884.         DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
  4885.         G.FillRectangle(DrawGradientBrush, r);
  4886.     }
  4887.  
  4888.     #endregion
  4889.  
  4890.     #region " DrawRadial "
  4891.  
  4892.     private GraphicsPath DrawRadialPath;
  4893.     private PathGradientBrush DrawRadialBrush1;
  4894.     private LinearGradientBrush DrawRadialBrush2;
  4895.  
  4896.     private Rectangle DrawRadialRectangle;
  4897.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height)
  4898.     {
  4899.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  4900.         DrawRadial(blend, DrawRadialRectangle, width / 2, height / 2);
  4901.     }
  4902.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, Point center)
  4903.     {
  4904.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  4905.         DrawRadial(blend, DrawRadialRectangle, center.X, center.Y);
  4906.     }
  4907.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, int cx, int cy)
  4908.     {
  4909.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  4910.         DrawRadial(blend, DrawRadialRectangle, cx, cy);
  4911.     }
  4912.  
  4913.     public void DrawRadial(ColorBlend blend, Rectangle r)
  4914.     {
  4915.         DrawRadial(blend, r, r.Width / 2, r.Height / 2);
  4916.     }
  4917.     public void DrawRadial(ColorBlend blend, Rectangle r, Point center)
  4918.     {
  4919.         DrawRadial(blend, r, center.X, center.Y);
  4920.     }
  4921.     public void DrawRadial(ColorBlend blend, Rectangle r, int cx, int cy)
  4922.     {
  4923.         DrawRadialPath.Reset();
  4924.         DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1);
  4925.  
  4926.         DrawRadialBrush1 = new PathGradientBrush(DrawRadialPath);
  4927.         DrawRadialBrush1.CenterPoint = new Point(r.X + cx, r.Y + cy);
  4928.         DrawRadialBrush1.InterpolationColors = blend;
  4929.  
  4930.         if (G.SmoothingMode == SmoothingMode.AntiAlias)
  4931.         {
  4932.             G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3);
  4933.         }
  4934.         else
  4935.         {
  4936.             G.FillEllipse(DrawRadialBrush1, r);
  4937.         }
  4938.     }
  4939.  
  4940.  
  4941.     protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height)
  4942.     {
  4943.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  4944.         DrawRadial(c1, c2, DrawGradientRectangle);
  4945.     }
  4946.     protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height, float angle)
  4947.     {
  4948.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  4949.         DrawRadial(c1, c2, DrawGradientRectangle, angle);
  4950.     }
  4951.  
  4952.     protected void DrawRadial(Color c1, Color c2, Rectangle r)
  4953.     {
  4954.         DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, 90f);
  4955.         G.FillRectangle(DrawGradientBrush, r);
  4956.     }
  4957.     protected void DrawRadial(Color c1, Color c2, Rectangle r, float angle)
  4958.     {
  4959.         DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, angle);
  4960.         G.FillEllipse(DrawGradientBrush, r);
  4961.     }
  4962.  
  4963.     #endregion
  4964.  
  4965.     #region " CreateRound "
  4966.  
  4967.     private GraphicsPath CreateRoundPath;
  4968.  
  4969.     private Rectangle CreateRoundRectangle;
  4970.     public GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
  4971.     {
  4972.         CreateRoundRectangle = new Rectangle(x, y, width, height);
  4973.         return CreateRound(CreateRoundRectangle, slope);
  4974.     }
  4975.  
  4976.     public GraphicsPath CreateRound(Rectangle r, int slope)
  4977.     {
  4978.         CreateRoundPath = new GraphicsPath(FillMode.Winding);
  4979.         CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
  4980.         CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
  4981.         CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
  4982.         CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
  4983.         CreateRoundPath.CloseFigure();
  4984.         return CreateRoundPath;
  4985.     }
  4986.  
  4987.     #endregion
  4988.  
  4989. }
  4990.  
  4991. abstract class ThemeControl154 : Control
  4992. {
  4993.  
  4994.  
  4995.     #region " Initialization "
  4996.  
  4997.     protected Graphics G;
  4998.  
  4999.     protected Bitmap B;
  5000.     public ThemeControl154()
  5001.     {
  5002.         SetStyle((ControlStyles)139270, true);
  5003.  
  5004.         _ImageSize = Size.Empty;
  5005.         Font = new Font("Verdana", 8);
  5006.  
  5007.         MeasureBitmap = new Bitmap(1, 1);
  5008.         MeasureGraphics = Graphics.FromImage(MeasureBitmap);
  5009.  
  5010.         DrawRadialPath = new GraphicsPath();
  5011.  
  5012.         InvalidateCustimization();
  5013.         //Remove?
  5014.     }
  5015.  
  5016.     protected override sealed void OnHandleCreated(EventArgs e)
  5017.     {
  5018.         InvalidateCustimization();
  5019.         ColorHook();
  5020.  
  5021.         if (!(_LockWidth == 0))
  5022.             Width = _LockWidth;
  5023.         if (!(_LockHeight == 0))
  5024.             Height = _LockHeight;
  5025.  
  5026.         Transparent = _Transparent;
  5027.         if (_Transparent && _BackColor)
  5028.             BackColor = Color.Transparent;
  5029.  
  5030.         base.OnHandleCreated(e);
  5031.     }
  5032.  
  5033.     private bool DoneCreation;
  5034.     protected override sealed void OnParentChanged(EventArgs e)
  5035.     {
  5036.         if (Parent != null)
  5037.         {
  5038.             OnCreation();
  5039.             DoneCreation = true;
  5040.             InvalidateTimer();
  5041.         }
  5042.  
  5043.         base.OnParentChanged(e);
  5044.     }
  5045.  
  5046.     #endregion
  5047.  
  5048.     private void DoAnimation(bool i)
  5049.     {
  5050.         OnAnimation();
  5051.         if (i)
  5052.             Invalidate();
  5053.     }
  5054.  
  5055.     protected override sealed void OnPaint(PaintEventArgs e)
  5056.     {
  5057.         if (Width == 0 || Height == 0)
  5058.             return;
  5059.  
  5060.         if (_Transparent)
  5061.         {
  5062.             PaintHook();
  5063.             e.Graphics.DrawImage(B, 0, 0);
  5064.         }
  5065.         else
  5066.         {
  5067.             G = e.Graphics;
  5068.             PaintHook();
  5069.         }
  5070.     }
  5071.  
  5072.     protected override void OnHandleDestroyed(EventArgs e)
  5073.     {
  5074.         ThemeShare.RemoveAnimationCallback(DoAnimation);
  5075.         base.OnHandleDestroyed(e);
  5076.     }
  5077.  
  5078.     #region " Size Handling "
  5079.  
  5080.     protected override sealed void OnSizeChanged(EventArgs e)
  5081.     {
  5082.         if (_Transparent)
  5083.         {
  5084.             InvalidateBitmap();
  5085.         }
  5086.  
  5087.         Invalidate();
  5088.         base.OnSizeChanged(e);
  5089.     }
  5090.  
  5091.     protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
  5092.     {
  5093.         if (!(_LockWidth == 0))
  5094.             width = _LockWidth;
  5095.         if (!(_LockHeight == 0))
  5096.             height = _LockHeight;
  5097.         base.SetBoundsCore(x, y, width, height, specified);
  5098.     }
  5099.  
  5100.     #endregion
  5101.  
  5102.     #region " State Handling "
  5103.  
  5104.     private bool InPosition;
  5105.     protected override void OnMouseEnter(EventArgs e)
  5106.     {
  5107.         InPosition = true;
  5108.         SetState(MouseState.Over);
  5109.         base.OnMouseEnter(e);
  5110.     }
  5111.  
  5112.     protected override void OnMouseUp(MouseEventArgs e)
  5113.     {
  5114.         if (InPosition)
  5115.             SetState(MouseState.Over);
  5116.         base.OnMouseUp(e);
  5117.     }
  5118.  
  5119.     protected override void OnMouseDown(MouseEventArgs e)
  5120.     {
  5121.         if (e.Button == System.Windows.Forms.MouseButtons.Left)
  5122.             SetState(MouseState.Down);
  5123.         base.OnMouseDown(e);
  5124.     }
  5125.  
  5126.     protected override void OnMouseLeave(EventArgs e)
  5127.     {
  5128.         InPosition = false;
  5129.         SetState(MouseState.None);
  5130.         base.OnMouseLeave(e);
  5131.     }
  5132.  
  5133.     protected override void OnEnabledChanged(EventArgs e)
  5134.     {
  5135.         if (Enabled)
  5136.             SetState(MouseState.None);
  5137.         else
  5138.             SetState(MouseState.Block);
  5139.         base.OnEnabledChanged(e);
  5140.     }
  5141.  
  5142.     protected MouseState State;
  5143.     private void SetState(MouseState current)
  5144.     {
  5145.         State = current;
  5146.         Invalidate();
  5147.     }
  5148.  
  5149.     #endregion
  5150.  
  5151.  
  5152.     #region " Base Properties "
  5153.  
  5154.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  5155.     public override Color ForeColor
  5156.     {
  5157.         get { return Color.Empty; }
  5158.         set { }
  5159.     }
  5160.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  5161.     public override Image BackgroundImage
  5162.     {
  5163.         get { return null; }
  5164.         set { }
  5165.     }
  5166.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  5167.     public override ImageLayout BackgroundImageLayout
  5168.     {
  5169.         get { return ImageLayout.None; }
  5170.         set { }
  5171.     }
  5172.  
  5173.     public override string Text
  5174.     {
  5175.         get { return base.Text; }
  5176.         set
  5177.         {
  5178.             base.Text = value;
  5179.             Invalidate();
  5180.         }
  5181.     }
  5182.     public override Font Font
  5183.     {
  5184.         get { return base.Font; }
  5185.         set
  5186.         {
  5187.             base.Font = value;
  5188.             Invalidate();
  5189.         }
  5190.     }
  5191.  
  5192.     private bool _BackColor;
  5193.     [Category("Misc")]
  5194.     public override Color BackColor
  5195.     {
  5196.         get { return base.BackColor; }
  5197.         set
  5198.         {
  5199.             if (!IsHandleCreated && value == Color.Transparent)
  5200.             {
  5201.                 _BackColor = true;
  5202.                 return;
  5203.             }
  5204.  
  5205.             base.BackColor = value;
  5206.             if (Parent != null)
  5207.                 ColorHook();
  5208.         }
  5209.     }
  5210.  
  5211.     #endregion
  5212.  
  5213.     #region " Public Properties "
  5214.  
  5215.     private bool _NoRounding;
  5216.     public bool NoRounding
  5217.     {
  5218.         get { return _NoRounding; }
  5219.         set
  5220.         {
  5221.             _NoRounding = value;
  5222.             Invalidate();
  5223.         }
  5224.     }
  5225.  
  5226.     private Image _Image;
  5227.     public Image Image
  5228.     {
  5229.         get { return _Image; }
  5230.         set
  5231.         {
  5232.             if (value == null)
  5233.             {
  5234.                 _ImageSize = Size.Empty;
  5235.             }
  5236.             else
  5237.             {
  5238.                 _ImageSize = value.Size;
  5239.             }
  5240.  
  5241.             _Image = value;
  5242.             Invalidate();
  5243.         }
  5244.     }
  5245.  
  5246.     private bool _Transparent;
  5247.     public bool Transparent
  5248.     {
  5249.         get { return _Transparent; }
  5250.         set
  5251.         {
  5252.             _Transparent = value;
  5253.             if (!IsHandleCreated)
  5254.                 return;
  5255.  
  5256.             if (!value && !(BackColor.A == 255))
  5257.             {
  5258.                 throw new Exception("Unable to change value to false while a transparent BackColor is in use.");
  5259.             }
  5260.  
  5261.             SetStyle(ControlStyles.Opaque, !value);
  5262.             SetStyle(ControlStyles.SupportsTransparentBackColor, value);
  5263.  
  5264.             if (value)
  5265.                 InvalidateBitmap();
  5266.             else
  5267.                 B = null;
  5268.             Invalidate();
  5269.         }
  5270.     }
  5271.  
  5272.     private Dictionary<string, Color> Items = new Dictionary<string, Color>();
  5273.     public Bloom[] Colors
  5274.     {
  5275.         get
  5276.         {
  5277.             List<Bloom> T = new List<Bloom>();
  5278.             Dictionary<string, Color>.Enumerator E = Items.GetEnumerator();
  5279.  
  5280.             while (E.MoveNext())
  5281.             {
  5282.                 T.Add(new Bloom(E.Current.Key, E.Current.Value));
  5283.             }
  5284.  
  5285.             return T.ToArray();
  5286.         }
  5287.         set
  5288.         {
  5289.             foreach (Bloom B in value)
  5290.             {
  5291.                 if (Items.ContainsKey(B.Name))
  5292.                     Items[B.Name] = B.Value;
  5293.             }
  5294.  
  5295.             InvalidateCustimization();
  5296.             ColorHook();
  5297.             Invalidate();
  5298.         }
  5299.     }
  5300.  
  5301.     private string _Customization;
  5302.     public string Customization
  5303.     {
  5304.         get { return _Customization; }
  5305.         set
  5306.         {
  5307.             if (value == _Customization)
  5308.                 return;
  5309.  
  5310.             byte[] Data = null;
  5311.             Bloom[] Items = Colors;
  5312.  
  5313.             try
  5314.             {
  5315.                 Data = Convert.FromBase64String(value);
  5316.                 for (int I = 0; I <= Items.Length - 1; I++)
  5317.                 {
  5318.                     Items[I].Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
  5319.                 }
  5320.             }
  5321.             catch
  5322.             {
  5323.                 return;
  5324.             }
  5325.  
  5326.             _Customization = value;
  5327.  
  5328.             Colors = Items;
  5329.             ColorHook();
  5330.             Invalidate();
  5331.         }
  5332.     }
  5333.  
  5334.     #endregion
  5335.  
  5336.     #region " Private Properties "
  5337.  
  5338.     private Size _ImageSize;
  5339.     protected Size ImageSize
  5340.     {
  5341.         get { return _ImageSize; }
  5342.     }
  5343.  
  5344.     private int _LockWidth;
  5345.     protected int LockWidth
  5346.     {
  5347.         get { return _LockWidth; }
  5348.         set
  5349.         {
  5350.             _LockWidth = value;
  5351.             if (!(LockWidth == 0) && IsHandleCreated)
  5352.                 Width = LockWidth;
  5353.         }
  5354.     }
  5355.  
  5356.     private int _LockHeight;
  5357.     protected int LockHeight
  5358.     {
  5359.         get { return _LockHeight; }
  5360.         set
  5361.         {
  5362.             _LockHeight = value;
  5363.             if (!(LockHeight == 0) && IsHandleCreated)
  5364.                 Height = LockHeight;
  5365.         }
  5366.     }
  5367.  
  5368.     private bool _IsAnimated;
  5369.     protected bool IsAnimated
  5370.     {
  5371.         get { return _IsAnimated; }
  5372.         set
  5373.         {
  5374.             _IsAnimated = value;
  5375.             InvalidateTimer();
  5376.         }
  5377.     }
  5378.  
  5379.     #endregion
  5380.  
  5381.  
  5382.     #region " Property Helpers "
  5383.  
  5384.     protected Pen GetPen(string name)
  5385.     {
  5386.         return new Pen(Items[name]);
  5387.     }
  5388.     protected Pen GetPen(string name, float width)
  5389.     {
  5390.         return new Pen(Items[name], width);
  5391.     }
  5392.  
  5393.     protected SolidBrush GetBrush(string name)
  5394.     {
  5395.         return new SolidBrush(Items[name]);
  5396.     }
  5397.  
  5398.     protected Color GetColor(string name)
  5399.     {
  5400.         return Items[name];
  5401.     }
  5402.  
  5403.     protected void SetColor(string name, Color value)
  5404.     {
  5405.         if (Items.ContainsKey(name))
  5406.             Items[name] = value;
  5407.         else
  5408.             Items.Add(name, value);
  5409.     }
  5410.     protected void SetColor(string name, byte r, byte g, byte b)
  5411.     {
  5412.         SetColor(name, Color.FromArgb(r, g, b));
  5413.     }
  5414.     protected void SetColor(string name, byte a, byte r, byte g, byte b)
  5415.     {
  5416.         SetColor(name, Color.FromArgb(a, r, g, b));
  5417.     }
  5418.     protected void SetColor(string name, byte a, Color value)
  5419.     {
  5420.         SetColor(name, Color.FromArgb(a, value));
  5421.     }
  5422.  
  5423.     private void InvalidateBitmap()
  5424.     {
  5425.         if (Width == 0 || Height == 0)
  5426.             return;
  5427.         B = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
  5428.         G = Graphics.FromImage(B);
  5429.     }
  5430.  
  5431.     private void InvalidateCustimization()
  5432.     {
  5433.         MemoryStream M = new MemoryStream(Items.Count * 4);
  5434.  
  5435.         foreach (Bloom B in Colors)
  5436.         {
  5437.             M.Write(BitConverter.GetBytes(B.Value.ToArgb()), 0, 4);
  5438.         }
  5439.  
  5440.         M.Close();
  5441.         _Customization = Convert.ToBase64String(M.ToArray());
  5442.     }
  5443.  
  5444.     private void InvalidateTimer()
  5445.     {
  5446.         if (DesignMode || !DoneCreation)
  5447.             return;
  5448.  
  5449.         if (_IsAnimated)
  5450.         {
  5451.             ThemeShare.AddAnimationCallback(DoAnimation);
  5452.         }
  5453.         else
  5454.         {
  5455.             ThemeShare.RemoveAnimationCallback(DoAnimation);
  5456.         }
  5457.     }
  5458.     #endregion
  5459.  
  5460.  
  5461.     #region " User Hooks "
  5462.  
  5463.     protected abstract void ColorHook();
  5464.     protected abstract void PaintHook();
  5465.  
  5466.     protected virtual void OnCreation()
  5467.     {
  5468.     }
  5469.  
  5470.     protected virtual void OnAnimation()
  5471.     {
  5472.     }
  5473.  
  5474.     #endregion
  5475.  
  5476.  
  5477.     #region " Offset "
  5478.  
  5479.     private Rectangle OffsetReturnRectangle;
  5480.     protected Rectangle Offset(Rectangle r, int amount)
  5481.     {
  5482.         OffsetReturnRectangle = new Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2));
  5483.         return OffsetReturnRectangle;
  5484.     }
  5485.  
  5486.     private Size OffsetReturnSize;
  5487.     protected Size Offset(Size s, int amount)
  5488.     {
  5489.         OffsetReturnSize = new Size(s.Width + amount, s.Height + amount);
  5490.         return OffsetReturnSize;
  5491.     }
  5492.  
  5493.     private Point OffsetReturnPoint;
  5494.     protected Point Offset(Point p, int amount)
  5495.     {
  5496.         OffsetReturnPoint = new Point(p.X + amount, p.Y + amount);
  5497.         return OffsetReturnPoint;
  5498.     }
  5499.  
  5500.     #endregion
  5501.  
  5502.     #region " Center "
  5503.  
  5504.  
  5505.     private Point CenterReturn;
  5506.     protected Point Center(Rectangle p, Rectangle c)
  5507.     {
  5508.         CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X + c.X, (p.Height / 2 - c.Height / 2) + p.Y + c.Y);
  5509.         return CenterReturn;
  5510.     }
  5511.     protected Point Center(Rectangle p, Size c)
  5512.     {
  5513.         CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X, (p.Height / 2 - c.Height / 2) + p.Y);
  5514.         return CenterReturn;
  5515.     }
  5516.  
  5517.     protected Point Center(Rectangle child)
  5518.     {
  5519.         return Center(Width, Height, child.Width, child.Height);
  5520.     }
  5521.     protected Point Center(Size child)
  5522.     {
  5523.         return Center(Width, Height, child.Width, child.Height);
  5524.     }
  5525.     protected Point Center(int childWidth, int childHeight)
  5526.     {
  5527.         return Center(Width, Height, childWidth, childHeight);
  5528.     }
  5529.  
  5530.     protected Point Center(Size p, Size c)
  5531.     {
  5532.         return Center(p.Width, p.Height, c.Width, c.Height);
  5533.     }
  5534.  
  5535.     protected Point Center(int pWidth, int pHeight, int cWidth, int cHeight)
  5536.     {
  5537.         CenterReturn = new Point(pWidth / 2 - cWidth / 2, pHeight / 2 - cHeight / 2);
  5538.         return CenterReturn;
  5539.     }
  5540.  
  5541.     #endregion
  5542.  
  5543.     #region " Measure "
  5544.  
  5545.     private Bitmap MeasureBitmap;
  5546.     //TODO: Potential issues during multi-threading.
  5547.     private Graphics MeasureGraphics;
  5548.  
  5549.     protected Size Measure()
  5550.     {
  5551.         return MeasureGraphics.MeasureString(Text, Font, Width).ToSize();
  5552.     }
  5553.     protected Size Measure(string text)
  5554.     {
  5555.         return MeasureGraphics.MeasureString(text, Font, Width).ToSize();
  5556.     }
  5557.  
  5558.     #endregion
  5559.  
  5560.  
  5561.     #region " DrawPixel "
  5562.  
  5563.  
  5564.     private SolidBrush DrawPixelBrush;
  5565.     protected void DrawPixel(Color c1, int x, int y)
  5566.     {
  5567.         if (_Transparent)
  5568.         {
  5569.             B.SetPixel(x, y, c1);
  5570.         }
  5571.         else
  5572.         {
  5573.             DrawPixelBrush = new SolidBrush(c1);
  5574.             G.FillRectangle(DrawPixelBrush, x, y, 1, 1);
  5575.         }
  5576.     }
  5577.  
  5578.     #endregion
  5579.  
  5580.     #region " DrawCorners "
  5581.  
  5582.  
  5583.     private SolidBrush DrawCornersBrush;
  5584.     protected void DrawCorners(Color c1, int offset)
  5585.     {
  5586.         DrawCorners(c1, 0, 0, Width, Height, offset);
  5587.     }
  5588.     protected void DrawCorners(Color c1, Rectangle r1, int offset)
  5589.     {
  5590.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset);
  5591.     }
  5592.     protected void DrawCorners(Color c1, int x, int y, int width, int height, int offset)
  5593.     {
  5594.         DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  5595.     }
  5596.  
  5597.     protected void DrawCorners(Color c1)
  5598.     {
  5599.         DrawCorners(c1, 0, 0, Width, Height);
  5600.     }
  5601.     protected void DrawCorners(Color c1, Rectangle r1)
  5602.     {
  5603.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
  5604.     }
  5605.     protected void DrawCorners(Color c1, int x, int y, int width, int height)
  5606.     {
  5607.         if (_NoRounding)
  5608.             return;
  5609.  
  5610.         if (_Transparent)
  5611.         {
  5612.             B.SetPixel(x, y, c1);
  5613.             B.SetPixel(x + (width - 1), y, c1);
  5614.             B.SetPixel(x, y + (height - 1), c1);
  5615.             B.SetPixel(x + (width - 1), y + (height - 1), c1);
  5616.         }
  5617.         else
  5618.         {
  5619.             DrawCornersBrush = new SolidBrush(c1);
  5620.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
  5621.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
  5622.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
  5623.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
  5624.         }
  5625.     }
  5626.  
  5627.     #endregion
  5628.  
  5629.     #region " DrawBorders "
  5630.  
  5631.     protected void DrawBorders(Pen p1, int offset)
  5632.     {
  5633.         DrawBorders(p1, 0, 0, Width, Height, offset);
  5634.     }
  5635.     protected void DrawBorders(Pen p1, Rectangle r, int offset)
  5636.     {
  5637.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
  5638.     }
  5639.     protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
  5640.     {
  5641.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  5642.     }
  5643.  
  5644.     protected void DrawBorders(Pen p1)
  5645.     {
  5646.         DrawBorders(p1, 0, 0, Width, Height);
  5647.     }
  5648.     protected void DrawBorders(Pen p1, Rectangle r)
  5649.     {
  5650.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
  5651.     }
  5652.     protected void DrawBorders(Pen p1, int x, int y, int width, int height)
  5653.     {
  5654.         G.DrawRectangle(p1, x, y, width - 1, height - 1);
  5655.     }
  5656.  
  5657.     #endregion
  5658.  
  5659.     #region " DrawText "
  5660.  
  5661.     private Point DrawTextPoint;
  5662.  
  5663.     private Size DrawTextSize;
  5664.     protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
  5665.     {
  5666.         DrawText(b1, Text, a, x, y);
  5667.     }
  5668.     protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
  5669.     {
  5670.         if (text.Length == 0)
  5671.             return;
  5672.  
  5673.         DrawTextSize = Measure(text);
  5674.         DrawTextPoint = Center(DrawTextSize);
  5675.  
  5676.         switch (a)
  5677.         {
  5678.             case HorizontalAlignment.Left:
  5679.                 G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y);
  5680.                 break;
  5681.             case HorizontalAlignment.Center:
  5682.                 G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y);
  5683.                 break;
  5684.             case HorizontalAlignment.Right:
  5685.                 G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
  5686.                 break;
  5687.         }
  5688.     }
  5689.  
  5690.     protected void DrawText(Brush b1, Point p1)
  5691.     {
  5692.         if (Text.Length == 0)
  5693.             return;
  5694.         G.DrawString(Text, Font, b1, p1);
  5695.     }
  5696.     protected void DrawText(Brush b1, int x, int y)
  5697.     {
  5698.         if (Text.Length == 0)
  5699.             return;
  5700.         G.DrawString(Text, Font, b1, x, y);
  5701.     }
  5702.  
  5703.     #endregion
  5704.  
  5705.     #region " DrawImage "
  5706.  
  5707.  
  5708.     private Point DrawImagePoint;
  5709.     protected void DrawImage(HorizontalAlignment a, int x, int y)
  5710.     {
  5711.         DrawImage(_Image, a, x, y);
  5712.     }
  5713.     protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
  5714.     {
  5715.         if (image == null)
  5716.             return;
  5717.         DrawImagePoint = Center(image.Size);
  5718.  
  5719.         switch (a)
  5720.         {
  5721.             case HorizontalAlignment.Left:
  5722.                 G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height);
  5723.                 break;
  5724.             case HorizontalAlignment.Center:
  5725.                 G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height);
  5726.                 break;
  5727.             case HorizontalAlignment.Right:
  5728.                 G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height);
  5729.                 break;
  5730.         }
  5731.     }
  5732.  
  5733.     protected void DrawImage(Point p1)
  5734.     {
  5735.         DrawImage(_Image, p1.X, p1.Y);
  5736.     }
  5737.     protected void DrawImage(int x, int y)
  5738.     {
  5739.         DrawImage(_Image, x, y);
  5740.     }
  5741.  
  5742.     protected void DrawImage(Image image, Point p1)
  5743.     {
  5744.         DrawImage(image, p1.X, p1.Y);
  5745.     }
  5746.     protected void DrawImage(Image image, int x, int y)
  5747.     {
  5748.         if (image == null)
  5749.             return;
  5750.         G.DrawImage(image, x, y, image.Width, image.Height);
  5751.     }
  5752.  
  5753.     #endregion
  5754.  
  5755.     #region " DrawGradient "
  5756.  
  5757.     private LinearGradientBrush DrawGradientBrush;
  5758.  
  5759.     private Rectangle DrawGradientRectangle;
  5760.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
  5761.     {
  5762.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  5763.         DrawGradient(blend, DrawGradientRectangle);
  5764.     }
  5765.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
  5766.     {
  5767.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  5768.         DrawGradient(blend, DrawGradientRectangle, angle);
  5769.     }
  5770.  
  5771.     protected void DrawGradient(ColorBlend blend, Rectangle r)
  5772.     {
  5773.         DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, 90f);
  5774.         DrawGradientBrush.InterpolationColors = blend;
  5775.         G.FillRectangle(DrawGradientBrush, r);
  5776.     }
  5777.     protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
  5778.     {
  5779.         DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
  5780.         DrawGradientBrush.InterpolationColors = blend;
  5781.         G.FillRectangle(DrawGradientBrush, r);
  5782.     }
  5783.  
  5784.  
  5785.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
  5786.     {
  5787.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  5788.         DrawGradient(c1, c2, DrawGradientRectangle);
  5789.     }
  5790.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
  5791.     {
  5792.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  5793.         DrawGradient(c1, c2, DrawGradientRectangle, angle);
  5794.     }
  5795.  
  5796.     protected void DrawGradient(Color c1, Color c2, Rectangle r)
  5797.     {
  5798.         DrawGradientBrush = new LinearGradientBrush(r, c1, c2, 90f);
  5799.         G.FillRectangle(DrawGradientBrush, r);
  5800.     }
  5801.     protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
  5802.     {
  5803.         DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
  5804.         G.FillRectangle(DrawGradientBrush, r);
  5805.     }
  5806.  
  5807.     #endregion
  5808.  
  5809.     #region " DrawRadial "
  5810.  
  5811.     private GraphicsPath DrawRadialPath;
  5812.     private PathGradientBrush DrawRadialBrush1;
  5813.     private LinearGradientBrush DrawRadialBrush2;
  5814.  
  5815.     private Rectangle DrawRadialRectangle;
  5816.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height)
  5817.     {
  5818.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  5819.         DrawRadial(blend, DrawRadialRectangle, width / 2, height / 2);
  5820.     }
  5821.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, Point center)
  5822.     {
  5823.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  5824.         DrawRadial(blend, DrawRadialRectangle, center.X, center.Y);
  5825.     }
  5826.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, int cx, int cy)
  5827.     {
  5828.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  5829.         DrawRadial(blend, DrawRadialRectangle, cx, cy);
  5830.     }
  5831.  
  5832.     public void DrawRadial(ColorBlend blend, Rectangle r)
  5833.     {
  5834.         DrawRadial(blend, r, r.Width / 2, r.Height / 2);
  5835.     }
  5836.     public void DrawRadial(ColorBlend blend, Rectangle r, Point center)
  5837.     {
  5838.         DrawRadial(blend, r, center.X, center.Y);
  5839.     }
  5840.     public void DrawRadial(ColorBlend blend, Rectangle r, int cx, int cy)
  5841.     {
  5842.         DrawRadialPath.Reset();
  5843.         DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1);
  5844.  
  5845.         DrawRadialBrush1 = new PathGradientBrush(DrawRadialPath);
  5846.         DrawRadialBrush1.CenterPoint = new Point(r.X + cx, r.Y + cy);
  5847.         DrawRadialBrush1.InterpolationColors = blend;
  5848.  
  5849.         if (G.SmoothingMode == SmoothingMode.AntiAlias)
  5850.         {
  5851.             G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3);
  5852.         }
  5853.         else
  5854.         {
  5855.             G.FillEllipse(DrawRadialBrush1, r);
  5856.         }
  5857.     }
  5858.  
  5859.  
  5860.     protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height)
  5861.     {
  5862.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  5863.         DrawRadial(c1, c2, DrawRadialRectangle);
  5864.     }
  5865.     protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height, float angle)
  5866.     {
  5867.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  5868.         DrawRadial(c1, c2, DrawRadialRectangle, angle);
  5869.     }
  5870.  
  5871.     protected void DrawRadial(Color c1, Color c2, Rectangle r)
  5872.     {
  5873.         DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, 90f);
  5874.         G.FillEllipse(DrawRadialBrush2, r);
  5875.     }
  5876.     protected void DrawRadial(Color c1, Color c2, Rectangle r, float angle)
  5877.     {
  5878.         DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, angle);
  5879.         G.FillEllipse(DrawRadialBrush2, r);
  5880.     }
  5881.  
  5882.     #endregion
  5883.  
  5884.     #region " CreateRound "
  5885.  
  5886.     private GraphicsPath CreateRoundPath;
  5887.  
  5888.     private Rectangle CreateRoundRectangle;
  5889.     public GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
  5890.     {
  5891.         CreateRoundRectangle = new Rectangle(x, y, width, height);
  5892.         return CreateRound(CreateRoundRectangle, slope);
  5893.     }
  5894.  
  5895.     public GraphicsPath CreateRound(Rectangle r, int slope)
  5896.     {
  5897.         CreateRoundPath = new GraphicsPath(FillMode.Winding);
  5898.         CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
  5899.         CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
  5900.         CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
  5901.         CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
  5902.         CreateRoundPath.CloseFigure();
  5903.         return CreateRoundPath;
  5904.     }
  5905.  
  5906.     #endregion
  5907.  
  5908. }
  5909.  
  5910. static class ThemeShare
  5911. {
  5912.  
  5913.     #region " Animation "
  5914.  
  5915.     private static int Frames;
  5916.     private static bool Invalidate;
  5917.  
  5918.     public static PrecisionTimer ThemeTimer = new PrecisionTimer();
  5919.     //1000 / 50 = 20 FPS
  5920.     private const int FPS = 50;
  5921.  
  5922.     private const int Rate = 10;
  5923.     public delegate void AnimationDelegate(bool invalidate);
  5924.  
  5925.  
  5926.     private static List<AnimationDelegate> Callbacks = new List<AnimationDelegate>();
  5927.     private static void HandleCallbacks(IntPtr state, bool reserve)
  5928.     {
  5929.         Invalidate = (Frames >= FPS);
  5930.         if (Invalidate)
  5931.             Frames = 0;
  5932.  
  5933.         lock (Callbacks)
  5934.         {
  5935.             for (int I = 0; I <= Callbacks.Count - 1; I++)
  5936.             {
  5937.                 Callbacks[I].Invoke(Invalidate);
  5938.             }
  5939.         }
  5940.  
  5941.         Frames += Rate;
  5942.     }
  5943.  
  5944.     private static void InvalidateThemeTimer()
  5945.     {
  5946.         if (Callbacks.Count == 0)
  5947.         {
  5948.             ThemeTimer.Delete();
  5949.         }
  5950.         else
  5951.         {
  5952.             ThemeTimer.Create(0, Rate, HandleCallbacks);
  5953.         }
  5954.     }
  5955.  
  5956.     public static void AddAnimationCallback(AnimationDelegate callback)
  5957.     {
  5958.         lock (Callbacks)
  5959.         {
  5960.             if (Callbacks.Contains(callback))
  5961.                 return;
  5962.  
  5963.             Callbacks.Add(callback);
  5964.             InvalidateThemeTimer();
  5965.         }
  5966.     }
  5967.  
  5968.     public static void RemoveAnimationCallback(AnimationDelegate callback)
  5969.     {
  5970.         lock (Callbacks)
  5971.         {
  5972.             if (!Callbacks.Contains(callback))
  5973.                 return;
  5974.  
  5975.             Callbacks.Remove(callback);
  5976.             InvalidateThemeTimer();
  5977.         }
  5978.     }
  5979.  
  5980.     #endregion
  5981.  
  5982. }
  5983.  
  5984. enum MouseState : byte
  5985. {
  5986.     None = 0,
  5987.     Over = 1,
  5988.     Down = 2,
  5989.     Block = 3
  5990. }
  5991.  
  5992. struct Bloom
  5993. {
  5994.  
  5995.     public string _Name;
  5996.     public string Name
  5997.     {
  5998.         get { return _Name; }
  5999.     }
  6000.  
  6001.     private Color _Value;
  6002.     public Color Value
  6003.     {
  6004.         get { return _Value; }
  6005.         set { _Value = value; }
  6006.     }
  6007.  
  6008.     public string ValueHex
  6009.     {
  6010.         get { return string.Concat("#", _Value.R.ToString("X2", null), _Value.G.ToString("X2", null), _Value.B.ToString("X2", null)); }
  6011.         set
  6012.         {
  6013.             try
  6014.             {
  6015.                 _Value = ColorTranslator.FromHtml(value);
  6016.             }
  6017.             catch
  6018.             {
  6019.                 return;
  6020.             }
  6021.         }
  6022.     }
  6023.  
  6024.  
  6025.     public Bloom(string name, Color value)
  6026.     {
  6027.         _Name = name;
  6028.         _Value = value;
  6029.     }
  6030. }
  6031.  
  6032. //------------------
  6033. //Creator: aeonhack
  6034. //Site: elitevs.net
  6035. //Created: 11/30/2011
  6036. //Changed: 11/30/2011
  6037. //Version: 1.0.0
  6038. //------------------
  6039. class PrecisionTimer : IDisposable
  6040. {
  6041.  
  6042.     private bool _Enabled;
  6043.     public bool Enabled
  6044.     {
  6045.         get { return _Enabled; }
  6046.     }
  6047.  
  6048.     private IntPtr Handle;
  6049.  
  6050.     private TimerDelegate TimerCallback;
  6051.     [DllImport("kernel32.dll", EntryPoint = "CreateTimerQueueTimer")]
  6052.     private static extern bool CreateTimerQueueTimer(ref IntPtr handle, IntPtr queue, TimerDelegate callback, IntPtr state, uint dueTime, uint period, uint flags);
  6053.  
  6054.     [DllImport("kernel32.dll", EntryPoint = "DeleteTimerQueueTimer")]
  6055.     private static extern bool DeleteTimerQueueTimer(IntPtr queue, IntPtr handle, IntPtr callback);
  6056.  
  6057.     public delegate void TimerDelegate(IntPtr r1, bool r2);
  6058.  
  6059.     public void Create(uint dueTime, uint period, TimerDelegate callback)
  6060.     {
  6061.         if (_Enabled)
  6062.             return;
  6063.  
  6064.         TimerCallback = callback;
  6065.         bool Success = CreateTimerQueueTimer(ref Handle, IntPtr.Zero, TimerCallback, IntPtr.Zero, dueTime, period, 0);
  6066.  
  6067.         if (!Success)
  6068.             ThrowNewException("CreateTimerQueueTimer");
  6069.         _Enabled = Success;
  6070.     }
  6071.  
  6072.     public void Delete()
  6073.     {
  6074.         if (!_Enabled)
  6075.             return;
  6076.         bool Success = DeleteTimerQueueTimer(IntPtr.Zero, Handle, IntPtr.Zero);
  6077.  
  6078.         if (!Success && !(Marshal.GetLastWin32Error() == 997))
  6079.         {
  6080.             ThrowNewException("DeleteTimerQueueTimer");
  6081.         }
  6082.  
  6083.         _Enabled = !Success;
  6084.     }
  6085.  
  6086.     private void ThrowNewException(string name)
  6087.     {
  6088.         throw new Exception(string.Format("{0} failed. Win32Error: {1}", name, Marshal.GetLastWin32Error()));
  6089.     }
  6090.  
  6091.     public void Dispose()
  6092.     {
  6093.         Delete();
  6094.     }
  6095. }
  6096. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement