Alex-Trader

C# NETSEAL THEME

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