<|start_filename|>Assets/System/Windows/Forms/TrackBar.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public enum TickStyle 
    {
        None = 0,
        TopLeft = 1,
        BottomRight = 2,
        Both = 3,
    }
    
    public class TrackBar : Control
    {
        private int         largeChange = 5;
        private int         maximum     = 10;
        private int         minimum     = 0;
        private Orientation orientation = Orientation.Horizontal;
        private int         requestedDim;
        private int         smallChange   = 1;
        private int         value         = 0;
        
        // GUI
        private Pen backBarBorderPen = new Pen(Color.FromArgb(214, 214, 214));
        private Color backBarColor = Color.FromArgb(231, 234, 234);
        private int backBarWH = 4;
        private Padding padding = new Padding(8, 2, 8, 2);
        private Color sliderBorderColor = Color.FromArgb(172, 172, 172);
        private Color sliderBorderColorHovered = Color.FromArgb(126, 180, 234);
        private Pen sliderBorderPen = new Pen(Color.Transparent);
        private Color sliderColor = Color.FromArgb(236, 236, 236);
        private Color sliderColorHovered = Color.FromArgb(228, 240, 252);
        private bool sliderHovered;
        private int sliderLength = 10; // Use sliderHeight for vertical orientation.
        private int sliderHeight = 21; // ^
        private int sliderX;
        private int sliderY;
        private bool sliderDragStarted;
        private int tickWH = 4;
        private Pen tickPen = new Pen(Color.FromArgb(196, 196, 196));

        public TrackBar()
        {
            TickStyle = TickStyle.BottomRight;
            TickFrequency = 1;
            requestedDim = PreferredDimension;
            
            MouseHook.MouseUp += MouseHookOnMouseUp;
        }
        
        public event EventHandler ValueChanged;
        
        public override Color ForeColor
        {
            get { return SystemColors.WindowText; }
            set { }
        }
        public int LargeChange
        {
            get { return largeChange; }
            set
            {
                if (value < 0)
                    throw new ArgumentOutOfRangeException("value");
                
                largeChange = value;
            }
        }
        public int Maximum
        {
            get { return maximum; }
            set
            {
                if (maximum == value)
                    return;

                if (minimum > value)
                    minimum = value;
                
                SetRange(minimum, value);
            }
        }
        public int Minimum
        {
            get { return minimum; }
            set
            {
                if (minimum == value)
                    return;

                if (maximum < value)
                    maximum = value;
                
                SetRange(value, maximum);
            }
        }
        /// <summary>
        /// Vertical orientation uses Minimum value at top and Maximum at bottom, it's seems
        /// more logical to me. Can be changed in future.
        /// </summary>
        public Orientation Orientation
        {
            get { return orientation; }
            set
            {
                if (orientation == value)
                    return;
                
                orientation = value;
                if (orientation == Orientation.Horizontal)
                    Width = requestedDim;
                else
                    Height = requestedDim;
                
                SetBoundsCore(Location.X, Location.Y, Height, Width, BoundsSpecified.All);
                AdjustSize();
            }
        }
        public int SmallChange
        {
            get { return smallChange; }
            set
            {
                if (value < 0)
                    throw new ArgumentOutOfRangeException("value");
                
                smallChange = value;
            }
        }
        public int TickFrequency { get; set; }
        public TickStyle TickStyle { get; set; }
        public int Value
        {
            get { return value; }
            set
            {
                if (this.value == value)
                    return;
                
                if (value < minimum || value > maximum)
                    throw new ArgumentOutOfRangeException("value");

                this.value = value;
                SetTrackBarPosition();
                OnValueChanged(EventArgs.Empty);
            }
        }

        protected override Size DefaultSize
        {
            get { return new Size(104, PreferredDimension); }
        }

        private int PreferredDimension
        {
            get
            {
                int cyhscroll = 17;

                return (cyhscroll * 8) / 3;
            }
        }

        public void SetRange(int minValue, int maxValue)
        {
            if (minimum == minValue && maximum == maxValue) 
                return;
            
            if (minValue > maxValue)
                maxValue = minValue;

            minimum = minValue;
            maximum = maxValue;

            value = MathHelper.Clamp(value, minimum, maximum);
            
            SetTrackBarPosition();
        }
        public override string ToString()
        {
            return base.ToString() + ", Minimum: " + Minimum + ", Maximum: " + Maximum + ", Value: " + Value;
        }

        protected override void Dispose(bool release_all)
        {
            base.Dispose(release_all);
            
            MouseHook.MouseUp -= MouseHookOnMouseUp;
        }
        protected override void OnMouseClick(MouseEventArgs e)
        {
            if (!sliderDragStarted)
            {
                var sliderAreaClicked = IsPointOverSliderArea(e.Location);
                if (sliderAreaClicked)
                {
                    bool descrease;
                    if (Orientation == Orientation.Horizontal)
                        descrease = e.Location.X < sliderX + sliderLength / 2;
                    else
                        descrease = e.Location.Y < sliderY + sliderLength / 2;

                    var newValue = Value;
                    if (descrease)
                        newValue -= LargeChange;
                    else
                        newValue += LargeChange;

                    SetNewValue(newValue);
                }
            }
            
            base.OnMouseClick(e);
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            sliderDragStarted = IsPointOverSlider(e.Location);
        }
        protected override void OnMouseHover(EventArgs e)
        {
            base.OnMouseHover(e);

            var mclient = PointToClient(MousePosition);

            sliderHovered = IsPointOverSlider(mclient);
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (sliderDragStarted)
            {
                if (Orientation == Orientation.Horizontal)
                {
                    var relativeX = e.X - padding.Left;
                    var barWidth = Width - padding.Horizontal - sliderLength;
                    var coef = (float)relativeX / barWidth;
                    var newValue = (int)((Maximum - Minimum) * coef); // Transform coefficient to value.

                    SetNewValue(newValue);
                }
                else
                {
                    var relativeY = e.Y - padding.Left;
                    var barWidth = Height - padding.Horizontal - sliderLength;
                    var coef = (float)relativeY / barWidth;
                    var newValue = (int)((Maximum - Minimum) * coef); // Transform coefficient to value.

                    SetNewValue(newValue);
                }
            }
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);
            
            if (e.Button != MouseButtons.None)
                return;

            var scrollLines = SystemInformation.MouseWheelScrollLines;
            if (scrollLines == -1)
                scrollLines = TickFrequency;
            
            if (e.Delta > 0)
                SetNewValue(Value - scrollLines);
            else if (e.Delta < 0)
                SetNewValue(Value + scrollLines);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            switch (e.KeyCode)
            {
                case Keys.Down:
                case Keys.Right:
                    SetNewValue(Value + SmallChange);
                    break;
                
                case Keys.Up:
                case Keys.Left:
                    SetNewValue(Value - SmallChange);
                    break;
                
                case Keys.PageDown:
                    SetNewValue(Value + LargeChange);
                    break;
                case Keys.PageUp:
                    SetNewValue(Value - LargeChange);
                    break;
                
                case Keys.End:
                    SetNewValue(Maximum);
                    break;
                case Keys.Home:
                    SetNewValue(Minimum);
                    break;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            int backBarX = 0;
            int backBarY = 0;
            int backBarW = 0;
            int backBarH = 0;
            
            if (Orientation == Orientation.Horizontal)
            {
                backBarX = padding.Left;
                backBarH = backBarWH;
                backBarW = Width - padding.Horizontal;
                
                sliderLength = 10;
                sliderHeight = 21;

                var disPerValue = (float)(backBarW - sliderLength) / (Maximum - Minimum);
                sliderX = (int)(backBarX + value * disPerValue);
                
                float ticks = maximum;
                float tickDistance = backBarW - sliderLength;
                if (TickFrequency > 0)
                {
                    ticks /= TickFrequency;
                    tickDistance /= ticks;
                }
                int ticksStartX = backBarX + sliderLength / 2;
                int ticksStartY1 = padding.Top + 3;
                int ticksTotalWidth = backBarW - sliderLength;
                
                switch (TickStyle)
                {
                    case TickStyle.Both:
                        backBarY = (PreferredDimension - backBarWH - padding.Vertical) / 2 + 1;
                        sliderY = padding.Top + tickWH + 4;
                        
                        DrawTicksH(e.Graphics, ticksStartX, ticksStartY1, ticksTotalWidth, ticks, tickDistance);
                        DrawTicksH(e.Graphics, ticksStartX, sliderY + sliderHeight + 2, ticksTotalWidth, ticks, tickDistance);
                        break;
                    case TickStyle.BottomRight:
                        sliderHeight -= 2;
                        backBarY = (sliderHeight - backBarWH) / 2 + padding.Top;
                        sliderY = padding.Top;
                        
                        DrawTicksH(e.Graphics, ticksStartX, sliderY + sliderHeight + 1, ticksTotalWidth, ticks, tickDistance);
                        break;
                    case TickStyle.None:
                        sliderHeight -= 2;
                        backBarY = (sliderHeight - backBarWH) / 2 + padding.Top;
                        sliderY = padding.Top;
                        break;
                    case TickStyle.TopLeft:
                        backBarY = (sliderHeight - backBarWH) / 2 + padding.Top + tickWH + 4;
                        sliderY = padding.Top + tickWH + 4;
                        
                        DrawTicksH(e.Graphics, ticksStartX, ticksStartY1, ticksTotalWidth, ticks, tickDistance);
                        break;
                }
            }
            else
            {
                backBarY = padding.Left;
                backBarW = backBarWH;
                backBarH = Height - padding.Horizontal;
                
                sliderLength = 10;
                sliderHeight = 21;
                
                var disPerValue = (float)(backBarH - sliderLength) / (Maximum - Minimum);
                sliderY = (int)(backBarY + value * disPerValue);

                float ticks = maximum;
                float tickDistance = backBarH - sliderLength;
                if (TickFrequency > 0)
                {
                    ticks /= TickFrequency;
                    tickDistance /= ticks;
                }
                int ticksStartX = padding.Top + 3;
                int ticksStartY1 = backBarY + sliderLength / 2;
                int ticksTotalWidth = backBarH - sliderLength;
                
                switch (TickStyle)
                {
                    case TickStyle.Both:
                        backBarX = (PreferredDimension - backBarWH - padding.Vertical) / 2 + 1;
                        sliderX = padding.Top + tickWH + 4;
                        
                        DrawTicksV(e.Graphics, ticksStartX, ticksStartY1, ticksTotalWidth, ticks, tickDistance);
                        DrawTicksV(e.Graphics, sliderX + sliderHeight + 2, ticksStartY1, ticksTotalWidth, ticks, tickDistance);
                        break;
                    case TickStyle.BottomRight:
                        sliderHeight -= 2;
                        backBarX = (sliderHeight - backBarWH) / 2 + padding.Top;
                        sliderX = padding.Top;
                        
                        DrawTicksV(e.Graphics, sliderX + sliderHeight + 1, ticksStartY1, ticksTotalWidth, ticks, tickDistance);
                        break;
                    case TickStyle.None:
                        sliderHeight -= 2;
                        backBarX = (sliderHeight - backBarWH) / 2 + padding.Top;
                        sliderX = padding.Top;
                        break;
                    case TickStyle.TopLeft:
                        backBarX = (sliderHeight - backBarWH) / 2 + padding.Top + tickWH + 4;
                        sliderX = padding.Top + tickWH + 4;
                        
                        DrawTicksV(e.Graphics, ticksStartX, ticksStartY1, ticksTotalWidth, ticks, tickDistance);
                        break;
                }
            }
            
            DrawBackBar(e.Graphics, backBarX, backBarY, backBarW, backBarH);
            
            if (Orientation == Orientation.Horizontal)
                DrawSlider(e.Graphics, sliderX, sliderY, sliderLength, sliderHeight);
            else
                DrawSlider(e.Graphics, sliderX, sliderY, sliderHeight, sliderLength);

            if (uwfCanDrawTabDots && uwfDrawTabDots)
                e.Graphics.DrawRectangle(uwfTabPen, 0, 0, Width, Height);
        }
        protected virtual void OnValueChanged(EventArgs e)
        {
            var handler = ValueChanged;
            if (handler != null) 
                handler(this, e);
        }
        protected override void SetBoundsCore(int argX, int argY, int argWidth, int argHeight, BoundsSpecified specified)
        {
            requestedDim = orientation == Orientation.Horizontal ? argHeight : argWidth;

            if (AutoSize)
            {
                if (orientation == Orientation.Horizontal)
                {
                    if ((specified & BoundsSpecified.Height) != BoundsSpecified.None)
                        argHeight = PreferredDimension;
                }
                else
                {
                    if ((specified & BoundsSpecified.Width) != BoundsSpecified.None)
                        Width = PreferredDimension;
                }
            }
            
            base.SetBoundsCore(argX, argY, argWidth, argHeight, specified);
        }

        private void AdjustSize()
        {
            var dim = requestedDim;
            if (Orientation == Orientation.Horizontal)
                Height = AutoSize ? PreferredDimension : dim;
            else
                Width = AutoSize ? PreferredDimension : dim;

            requestedDim = dim;
        }
        private void DrawBackBar(Graphics g, int x, int y, int width, int height)
        {
            if (width == 0 || height == 0)
                return;
            
            g.uwfFillRectangle(backBarColor, x + 1, y + 1, width - 2, height - 2);
            g.DrawRectangle(backBarBorderPen, x, y, width, height);
        }
        private void DrawSlider(Graphics g, int x, int y, int width, int height)
        {
            if (width == 0 || height == 0)
                return;

            var highlightSlider = sliderHovered || sliderDragStarted;
            
            sliderBorderPen.Color = highlightSlider ? sliderBorderColorHovered : sliderBorderColor;
            
            g.uwfFillRectangle(highlightSlider ? sliderColorHovered : sliderColor, x + 1, y + 1, width - 2, height - 2);
            g.DrawRectangle(sliderBorderPen, x, y, width, height);
        }
        private void DrawTicksH(Graphics g, int x, int y, int width, float count, float distance)
        {
            var tickWHLineFix = tickWH - 1; // g.DrawLine is not pixel perfect.
            
            // Big ones.
            g.DrawLine(tickPen, x, y, x, y + tickWHLineFix);
            g.DrawLine(tickPen, x + width, y, x + width, y + tickWHLineFix);
            
            // Other.
            for (int i = 0; i < count; i++)
            {
                var tx = x + distance * i;
                if (tx > x + width)
                    continue;
                
                g.DrawLine(tickPen, tx, y + 1, tx, y + tickWHLineFix);
            }
        }
        private void DrawTicksV(Graphics g, int x, int y, int width, float count, float distance)
        {
            var tickWHLineFix = tickWH - 1; // g.DrawLine is not pixel perfect.
            
            // Big ones.
            g.DrawLine(tickPen, x, y, x + tickWHLineFix, y);
            g.DrawLine(tickPen, x, y + width, x + tickWHLineFix, y + width);
            
            // Other.
            for (int i = 0; i < count; i++)
            {
                var ty = y + distance * i;
                if (ty > y + width)
                    continue;
                
                g.DrawLine(tickPen, x + 1, ty, x + tickWHLineFix, ty);
            }
        }
        private bool IsPointOverSlider(Point p)
        {
            if (Orientation == Orientation.Horizontal)
                return new Rectangle(sliderX, sliderY, sliderLength, sliderHeight).Contains(p);
            
            return new Rectangle(sliderX, sliderY, sliderHeight, sliderLength).Contains(p);
        }
        private bool IsPointOverSliderArea(Point p)
        {
            if (Orientation == Orientation.Horizontal)
                return new Rectangle(padding.Left, sliderY, Width - padding.Horizontal, sliderHeight).Contains(p);
            
            return new Rectangle(sliderX, padding.Left, sliderHeight, Height - padding.Horizontal).Contains(p);
        }
        private void MouseHookOnMouseUp(object sender, MouseEventArgs e)
        {
            sliderDragStarted = false;
        }
        private void SetNewValue(int newValue)
        {
            Value = MathHelper.Clamp(newValue, Minimum, Maximum);
        }
        private void SetTrackBarPosition()
        {
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/IContainerControl.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public interface IContainerControl
    {
        Control ActiveControl { get; set; }

        bool ActivateControl(Control active);
    }
}


<|start_filename|>Assets/System/Windows/Forms/CheckState.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum CheckState
    {
        Unchecked = 0,
        Checked = 1,
        Indeterminate = 2,
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripItem.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.ComponentModel;
    using System.Drawing;

    public abstract class ToolStripItem : Component
    {
        internal bool boundsChanged;
        internal bool locationChanged;
        internal Color disabledForeColor = SystemColors.InactiveCaption;
        internal Color hoverColor = Color.FromArgb(196, 225, 255);
        internal Pen selectPen = new Pen(Color.FromArgb(51, 153, 255));

        private Color backColor = SystemColors.Control;
        private Rectangle bounds = Rectangle.Empty;
        private ToolStrip owner;
        private Padding padding;
        private bool paddingExists;
        private ToolStrip parent;
        private bool stateAutoSize = true;
        private bool stateAutoToolTip = true;
        private bool stateContstructing;
        private bool statePressed;
        private bool stateSelected;
        private bool stateVisible = true;
        private string text;
        private ContentAlignment textAlign = ContentAlignment.MiddleCenter;
        private string toolTipText;

        protected ToolStripItem()
        {
            stateContstructing = true;

            BackgroundImageLayout = ImageLayout.Stretch; // tile default?
            Enabled = true;
            Font = SystemFonts.uwfArial_12;
            ForeColor = Control.defaultForeColor;
            Size = DefaultSize;

            uwfImageColor = Color.White;

            stateContstructing = false;
        }
        protected ToolStripItem(string text, Image image, EventHandler onClick) : this(text, image, onClick, null)
        {
        }
        protected ToolStripItem(string text, Image image, EventHandler onClick, string name) : this()
        {
            Image = image;
            Name = name;
            Text = text;
            if (onClick != null)
                Click += onClick;
        }

        public event EventHandler AvailableChanged;
        public event EventHandler BackColorChanged;
        public event EventHandler Click;
        public event EventHandler LocationChanged;
        public event EventHandler TextChanged;
        public event EventHandler VisibleChanged;

        public bool Available
        {
            get { return stateVisible; }
            set { SetVisibleCore(value); }
        }
        public bool AutoSize
        {
            get { return stateAutoSize; }
            set { stateAutoSize = value; }
        }
        public bool AutoToolTip
        {
            get { return stateAutoToolTip; }
            set { stateAutoToolTip = value; }
        }
        public virtual Color BackColor
        {
            get
            {
                var c = RawBackColor;
                if (c.IsEmpty == false)
                    return c;

                var p = ParentInternal;
                if (p != null)
                    return p.BackColor;

                return Color.Transparent; // Control.DefaultColor?
            }
            set
            {
                if (backColor == value || value.IsEmpty)
                    return;

                backColor = value;
                OnBackColorChanged(EventArgs.Empty);
            }
        }
        public virtual Image BackgroundImage { get; set; }
        public virtual ImageLayout BackgroundImageLayout { get; set; }
        public virtual Rectangle Bounds { get { return bounds; } }
        public virtual bool CanSelect { get { return true; } }
        public virtual bool Enabled { get; set; }
        public virtual Font Font { get; set; }
        public virtual Color ForeColor { get; set; }
        public int Height
        {
            get { return Bounds.Height; }
            set
            {
                var currentBounds = Bounds;
                SetBounds(currentBounds.X, currentBounds.Y, currentBounds.Width, value);
            }
        }
        public virtual Image Image { get; set; }
        public bool IsOnDropDown
        {
            get
            {
                if (ParentInternal != null)
                    return ParentInternal.IsDropDown;

                if (Owner != null && Owner.IsDropDown)
                    return true;

                return false;
            }
        }
        public string Name { get; set; }
        public ToolStrip Owner
        {
            get { return owner; }
            set
            {
                if (owner == value)
                    return;

                if (owner != null)
                    owner.Items.Remove(this);
                if (value != null)
                    value.Items.Add(this);
            }
        }
        public ToolStripItem OwnerItem
        {
            get
            {
                ToolStripDropDown currentParent = null;
                var parentInternal = ParentInternal;
                if (parentInternal != null)
                    currentParent = parentInternal as ToolStripDropDown;
                else if (Owner != null)
                    currentParent = Owner as ToolStripDropDown;

                if (currentParent != null)
                    return currentParent.OwnerItem;
                return null;
            }
        }
        public virtual Padding Padding
        {
            get
            {
                if (paddingExists)
                    return padding;
                return DefaultPadding;
            }
            set
            {
                padding = value;
                paddingExists = true;
            }
        }
        public virtual bool Pressed { get { return false; } }
        public virtual bool Selected { get { return stateSelected; } }
        public Size Size
        {
            get { return Bounds.Size; }
            set
            {
                var currentBounds = Bounds;
                currentBounds.Size = value;
                SetBounds(currentBounds);
            }
        }
        public object Tag { get; set; }
        public virtual string Text
        {
            get { return text; }
            set
            {
                if (text == value)
                    return;

                text = value;
                OnTextChanged(EventArgs.Empty);
            }
        }
        public virtual ContentAlignment TextAlign
        {
            get { return textAlign; }
            set { textAlign = value; }
        }
        public string ToolTipText
        {
            get
            {
                if (AutoToolTip == false || string.IsNullOrEmpty(toolTipText) == false)
                    return toolTipText;

                string toolText = Text;
                if (WindowsFormsUtils.ContainsMnemonic(toolText))
                    toolText = string.Join("", toolText.Split('&'));
                
                return toolText;
            }
            set { toolTipText = value; }
        }
        public bool Visible
        {
            get { return ParentInternal != null && ParentInternal.Visible && Available; }
            set { SetVisibleCore(value); }
        }
        public int Width
        {
            get { return Bounds.Width; }
            set
            {
                var currentBounds = Bounds;
                SetBounds(currentBounds.X, currentBounds.Y, value, currentBounds.Height);
            }
        }

        internal ToolStrip ParentInternal
        {
            get { return parent; }
            set
            {
                if (parent == value) return;

                var oldParent = parent;
                parent = value;
                OnParentChanged(oldParent, value);
            }
        }
        internal Color RawBackColor
        {
            get { return backColor; }
        }
        internal Color uwfImageColor { get; set; }

        protected internal ToolStrip Parent
        {
            get { return ParentInternal; }
            set { ParentInternal = value; }
        }
        protected virtual Padding DefaultPadding
        {
            get { return Padding.Empty; }
        }
        protected virtual Size DefaultSize
        {
            get { return new Size(23, 23); }
        }

        public void Invalidate()
        {
            if (this.ParentInternal != null)
                ParentInternal.Invalidate(this.Bounds, true);
        }
        public void Select()
        {
            if (CanSelect == false)
                return;

            stateSelected = true;
        }
        public override string ToString()
        {
            var text = Text;
            if (string.IsNullOrEmpty(text) == false)
                return text;
            return base.ToString();
        }

        internal void Push(bool push)
        {
            if (!CanSelect || !Enabled)
                return;

            statePressed = push;
            if (Available)
                Invalidate();
        }
        internal void RaiseClick()
        {
            OnClick(EventArgs.Empty);
        }
        internal void RaiseOnMouseDown(MouseEventArgs e)
        {
            OnMouseDown(e);
        }
        internal void RaiseOnMouseEnter(EventArgs e)
        {
            OnMouseEnter(e);
        }
        internal void RaiseOnMouseHover(EventArgs e)
        {
            OnMouseHover(e);
        }
        internal void RaiseOnMouseLeave(EventArgs e)
        {
            OnMouseLeave(e);
        }
        internal void RaiseOnMouseMove(MouseEventArgs mea)
        {
            OnMouseMove(mea);
        }
        internal void RaiseOnMouseUp(MouseEventArgs e)
        {
            OnMouseUp(e);
        }
        internal void RaiseOnPaint(PaintEventArgs e)
        {
            OnPaint(e);
        }
        internal void SetBounds(int x, int y, int width, int height)
        {
            SetBounds(new Rectangle(x, y, width, height));
        }
        internal void SetOwner(ToolStrip newOwner)
        {
            if (owner == newOwner) return;

            owner = newOwner;
            if (newOwner == null)
                ParentInternal = null;
        }
        internal virtual void Unselect()
        {
            if (stateSelected == false)
                return;

            stateSelected = false;

            if (Available && ParentInternal != null)
                ParentInternal.NotifySelectionChange(this);
        }
        internal void UpdateBounds(int x, int y)
        {
            var currentOwner = Owner;
            if (currentOwner == null)
                return;

            var currentBounds = Bounds;
            var nx = 0;
            var ny = y;
            var nw = currentBounds.Width;
            var nh = currentBounds.Height;
            if (currentOwner.Orientation == Orientation.Vertical)
            {
                nx = 2; // Border + 1 pixel offset (padding?).
                ny = y;
                if (AutoSize)
                    nh = DefaultSize.Height + Padding.Vertical + 1; // Dunno where 1 pixel is missing.
            }
            else
            {
                nx = x;
                if (AutoSize)
                    nh = Height;
            }

            SetBounds(nx, ny, nw, nh);
        }

        protected internal virtual void DrawImage(Graphics graphics)
        {
            var image = Image;

            // TODO: image align.
            if (image != null)
            {
                var imageColor = Enabled ? uwfImageColor : Color.Gray;
                var rect = Bounds;
                graphics.uwfDrawImage(
                    image,
                    imageColor,
                    rect.X + rect.Width / 2 - image.Width / 2,
                    rect.Y + rect.Height / 2 - image.Height / 2,
                    image.Width,
                    image.Height);
            }
        }
        protected internal virtual int GetEstimatedWidth(Graphics graphics) // OnPaint only.
        {
            // ToolStripSeparator?
            if (string.IsNullOrEmpty(Text))
                return 0; 
            
            return (int)graphics.MeasureString(Text, Font).Width;
        }
        protected internal virtual void SetBounds(Rectangle nbounds)
        {
            var oldBounds = bounds;
            bounds = nbounds;

            if (stateContstructing)
                return;

            if (bounds != oldBounds)
                OnBoundsChanged();

            if (bounds.Location != oldBounds.Location)
                OnLocationChanged(EventArgs.Empty);
        }

        protected override void Dispose(bool disposing)
        {
        }
        protected virtual void OnAvailableChanged(System.EventArgs e)
        {
            var handler = AvailableChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnBackColorChanged(EventArgs e)
        {
            var handler = BackColorChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnBoundsChanged()
        {
            boundsChanged = true;
        }
        protected virtual void OnClick(EventArgs e)
        {
            var handler = Click;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnLocationChanged(EventArgs e)
        {
            var handler = LocationChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnMouseDown(MouseEventArgs e)
        {
        }
        protected virtual void OnMouseEnter(EventArgs e)
        {
            Select();
        }
        protected virtual void OnMouseHover(EventArgs e)
        {
        }
        protected virtual void OnMouseLeave(EventArgs e)
        {
            Unselect();
        }
        protected virtual void OnMouseMove(MouseEventArgs mea)
        {
        }
        protected virtual void OnMouseUp(MouseEventArgs e)
        {
            if (!Enabled) return;

            OnClick(EventArgs.Empty);
        }
        protected virtual void OnPaint(PaintEventArgs e)
        {
            var localBackColor = stateSelected && Enabled ? hoverColor : BackColor;
            var rect = Bounds;
            var graphics = e.Graphics;
            var textColor = Enabled ? ForeColor : disabledForeColor;

            // Text left offset for vertical ToolStrip.
            var leftOffset = 0;
            if (Owner != null && Owner.Orientation == Orientation.Vertical)
                leftOffset = Owner.Padding.Left;

            // Paint back + backImage.
            if (BackgroundImage != null)
                ControlPaint.DrawBackgroundImage(graphics, BackgroundImage, localBackColor, BackgroundImageLayout, rect, rect);
            else
                e.Graphics.uwfFillRectangle(localBackColor, rect);

            // Draw border for selected state.
            if (stateSelected && Enabled)
                graphics.DrawRectangle(selectPen, rect);

            // Image.
            DrawImage(graphics);

            // Text.
            graphics.uwfDrawString(Text, Font, textColor, rect.X + leftOffset, rect.Y, rect.Width - leftOffset, rect.Height, TextAlign);
            ////graphics.DrawRectangle(new Pen(Color.Red), rect); // Debug.
        }
        protected virtual void OnParentChanged(ToolStrip oldParent, ToolStrip newParent)
        {
        }
        protected virtual void OnTextChanged(EventArgs e)
        {
            var handler = TextChanged;
            if (handler != null)
                handler(this, e);

            boundsChanged = true;
        }
        protected virtual void OnVisibleChanged(EventArgs e)
        {
            var handler = VisibleChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void SetVisibleCore(bool visible)
        {
            if (stateVisible == visible)
                return;

            stateVisible = visible;
            Unselect();
            Push(false);

            OnAvailableChanged(EventArgs.Empty);
            OnVisibleChanged(EventArgs.Empty);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/TreeView.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;

    public class TreeView : Control
    {
        internal int       arrowSize = 16;
        internal TreeNode  hoveredNode;
        internal TreeNode  root;
        
        internal float uwfScrollSpeed = 2;
        internal Color uwfArrowImageColor = Color.FromArgb(0x26, 0x26, 0x26);
        internal Color uwfArrowImageHoveredColor = Color.FromArgb(0x27, 0xC7, 0xF7);
        internal Color uwfItemHoveredColor = Color.FromArgb(221, 238, 253);
        internal Color uwfItemSelectedColor = Color.FromArgb(187, 222, 251); // Default is SystemColors.Highlight.
        internal Color uwfItemSelectedUnfocusedColor = Color.FromArgb(187, 222, 251);

        private readonly DrawTreeNodeEventArgs nodeArgs = new DrawTreeNodeEventArgs(null, null, Rectangle.Empty, TreeNodeStates.Default);
        private readonly List<TreeNode> nodeList = new List<TreeNode>();
        private readonly DrawTreeNodeEventHandler onDrawNode;
        private readonly List<TreeNode> scrollNodeList = new List<TreeNode>();

        private bool      drag;
        private TreeNode  dragNode;
        private Point     dragPosition;
        private string    filter;
        private TreeNode  mouseDownAtNode;
        private ToolTip   nodeToolTip;
        private TreeNode  nodeToolTipLast;
        private TreeNode  selectedNode;
        private float     resetFilterTime;
        private ScrollBar vScrollBar;

        public TreeView()
        {
            BackColor = Color.White;
            BorderStyle = BorderStyle.Fixed3D;
            ItemHeight = 22;
            Padding = new Padding(4);

            root = new TreeNode(this);
            root.IsExpanded = true;

            Nodes = new TreeNodeCollection(root);

            onDrawNode = DrawNodeDefault;

            MouseHook.MouseUp += Application_UpClick;
        }

        public event TreeViewEventHandler AfterSelect;
        public event DrawTreeNodeEventHandler DrawNode;
        public event ItemDragEventHandler ItemDrag;
        public event TreeNodeMouseClickEventHandler NodeMouseClick;
        public event TreeNodeMouseClickEventHandler NodeMouseDoubleClick;
        public event TreeNodeMouseHoverEventHandler NodeMouseHover;

        public BorderStyle BorderStyle { get; set; }
        public bool FullRowSelect { get; set; }
        public ImageList ImageList { get; set; }
        public int ItemHeight { get; set; }
        public TreeNodeCollection Nodes { get; private set; }
        public TreeNode SelectedNode
        {
            get { return selectedNode;}
            set
            {
                if (selectedNode == value)
                    return;

                selectedNode = value;

                if (value != null)
                {
                    EnsureVisible(value);
                    OnAfterSelect(new TreeViewEventArgs(value));
                }
            }
        }
        public bool ShowNodeToolTips { get; set; }

        internal ScrollBar uwfVScrollBar
        {
            get
            {
                if (vScrollBar == null)
                    uwfVScrollBar = new VScrollBar();

                return vScrollBar;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                
                if (vScrollBar != null)
                    vScrollBar.Dispose();
                
                vScrollBar = value;
                vScrollBar.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                vScrollBar.Location = new Point(Width - vScrollBar.Width, 0);
                vScrollBar.Height = Height;
                vScrollBar.ValueChanged += VScrollBarOnValueChanged;
                Controls.Add(vScrollBar);
            }
        }

        protected override Size DefaultSize
        {
            get { return new Size(121, 97); }
        }

        private int nodesOnScreen
        {
            get { return Height / ItemHeight; } 
        }
        private float scrollIndex
        {
            get
            {
                if (!uwfVScrollBar.Visible)
                    return 0;
                
                return uwfVScrollBar.Value;
            }
            set
            {
                if (uwfVScrollBar.Visible)
                    uwfVScrollBar.Value = (int)value;
            }
        }
        
        public void CollapseAll()
        {
            var nodesCount = Nodes.Count;
            for (int i = 0; i < nodesCount; i++)
                Nodes[i].CollapseInternal();
            Refresh();
        }
        public TreeNode GetNodeAt(int x, int y)
        {
            var scrollNodeListCount = scrollNodeList.Count;
            for (int i = 0; i < scrollNodeListCount; i++)
            {
                var node = scrollNodeList[i];
                var nodeY = node.Bounds.Y;
                var nodeH = node.Bounds.Height;

                if (y >= nodeY && y < nodeY + nodeH)
                    return node;
            }

            return null;
        }
        public TreeNode GetNodeAt(Point pt)
        {
            return GetNodeAt(pt.X, pt.Y);
        }
        public void ExpandAll()
        {
            var nodesCount = Nodes.Count;
            for (int i = 0; i < nodesCount; i++)
                Nodes[i].ExpandAllInternal();
            Refresh();
        }
        public override void Refresh()
        {
            nodeList.Clear();
            
            UpdateNodeList(root);
            UpdateScrollList();
        }

        internal void EnsureVisible(TreeNode node)
        {
            if (node == null)
                return;
            
            var nodeIsInScrollList = scrollNodeList.Find(x => x == node);
            if (nodeIsInScrollList != null) return;

            AdjustScrollIndexToNode(node);

            UpdateScrollList();
        }
        /// <summary>
        /// only for visible nodes.
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        internal TreeNode Find(Predicate<TreeNode> match)
        {
            return nodeList.Find(match);
        }

        protected internal override void uwfOnLatePaint(PaintEventArgs e)
        {
            ControlPaint.PrintBorder(e.Graphics, ClientRectangle, BorderStyle, Border3DStyle.Flat);
        }

        protected override void Dispose(bool release_all)
        {
            MouseHook.MouseUp -= Application_UpClick;

            base.Dispose(release_all);
        }
        protected virtual void OnAfterSelect(TreeViewEventArgs e)
        {
            var handler = AfterSelect;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnDrawNode(DrawTreeNodeEventArgs e)
        {
            if (onDrawNode != null) onDrawNode(this, e);
        }
        protected virtual void OnItemDrag(ItemDragEventArgs e)
        {
            var handler = ItemDrag;
            if (handler != null)
                handler(this, e);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Modifiers == Keys.None)
            {
                switch (e.KeyCode)
                {
                    case Keys.Space:
                    case Keys.Return:
                        if (SelectedNode != null)
                            SelectedNode.Toggle();
                        break;

                    case Keys.Down:
                        SelectNext();
                        break;
                    case Keys.Left:
                        if (SelectedNode != null)
                            SelectedNode.Collapse();
                        break;
                    case Keys.Right:
                        if (SelectedNode != null)
                            SelectedNode.Expand();
                        break;
                    case Keys.Up:
                        SelectPrevious();
                        break;

                    case Keys.PageDown:
                        if (nodeList.Count > 0)
                        {
                            var lNodesOnScreen = nodesOnScreen;
                            var nextIndex = 0;
                            if (SelectedNode != null)
                                nextIndex = nodeList.IndexOf(SelectedNode);
                            nextIndex = MathHelper.Clamp(nextIndex + lNodesOnScreen, 0, nodeList.Count - 1);
                            SelectedNode = nodeList[nextIndex];
                        }
                        break;
                    case Keys.PageUp:
                        if (nodeList.Count > 0)
                        {
                            var lNodesOnScreen = nodesOnScreen;
                            var nextIndex = 0;
                            if (SelectedNode != null)
                                nextIndex = nodeList.IndexOf(SelectedNode);
                            nextIndex = MathHelper.Clamp(nextIndex - lNodesOnScreen, 0, nodeList.Count - 1);
                            SelectedNode = nodeList[nextIndex];
                        }
                        break;
                    case Keys.End:
                        if (nodeList.Count > 0)
                            SelectedNode = nodeList[nodeList.Count - 1];
                        break;
                    case Keys.Home:
                        if (nodeList.Count > 0)
                            SelectedNode = nodeList[0];
                        break;
                }
            }
            else if (e.Control)
            {
                switch (e.KeyCode)
                {
                    case Keys.Down:
                        if (uwfVScrollBar.Visible)
                            uwfVScrollBar.DoScroll(ScrollEventType.SmallIncrement);
                        break;
                    case Keys.Up:
                        if (uwfVScrollBar.Visible)
                            uwfVScrollBar.DoScroll(ScrollEventType.SmallDecrement);
                        break;
                }
            }
            

            char c = KeyHelper.GetLastInputChar();
            if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
            {
                filter += c;
                resetFilterTime = 3; // sec.
                SelectNodeWText(filter);
            }
        }
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            
            var sNode = SelectAtPosition(e);
            if (sNode != null)
            {
                sNode.Toggle();
                OnNodeMouseDoubleClick(new TreeNodeMouseClickEventArgs(sNode, e.Button, e.Clicks, e.X, e.Y));
            }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            mouseDownAtNode = GetNodeAt(e.Location);
            if (mouseDownAtNode == null)
                return;

            // Try to toggle node with mouse.
            if (mouseDownAtNode.Nodes.Count > 0 && 
                e.X >= mouseDownAtNode.Bounds.X && 
                e.X <= mouseDownAtNode.Bounds.X + arrowSize)
            {
                mouseDownAtNode.Toggle();
                mouseDownAtNode = null; // Prevent node from being selected.
                return;
            }
            
            drag = true;
            dragNode = mouseDownAtNode;
            dragPosition = e.Location;
        }
        protected override void OnMouseHover(EventArgs e)
        {
            base.OnMouseHover(e);
            
            var mclient = PointToClient(MousePosition);

            hoveredNode = GetNodeAt(mclient);
            if (hoveredNode != null)
            {
                if (ShowNodeToolTips)
                {
                    if (!string.IsNullOrEmpty(hoveredNode.ToolTipText))
                    {
                        if (nodeToolTip == null)
                        {
                            nodeToolTip = new ToolTip();
                            nodeToolTip.InitialDelay = 0;
                        }

                        if (hoveredNode != nodeToolTipLast)
                            nodeToolTip.Show(hoveredNode.ToolTipText, mclient);

                        nodeToolTipLast = hoveredNode;
                    }
                    else
                        nodeToolTipLast = null;
                }

                // Tooltip will show previous ToolTipText. Override OnMouseHover if necessary.
                OnNodeMouseHover(new TreeNodeMouseHoverEventArgs(hoveredNode));
            }
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (!drag) return;
            if (dragPosition.Distance(e.Location) < 4) return;
            
            OnItemDrag(new ItemDragEventArgs(e.Button, dragNode));
                    
            dragPosition = Point.Empty;
            drag = false;
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);
            
            if (uwfVScrollBar.Visible)
                scrollIndex -= e.Delta * uwfScrollSpeed;
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            var mouseUpAtNode = GetNodeAt(e.Location);
            if (mouseUpAtNode != mouseDownAtNode)
                return;
            
            if (SelectAtPosition(e) == null)
                return;

            OnNodeMouseClick(new TreeNodeMouseClickEventArgs(SelectedNode, e.Button, e.Clicks, e.X, e.Y));
        }
        protected virtual void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
        {
            var nodeMouseClick = NodeMouseClick;
            if (nodeMouseClick != null)
                nodeMouseClick(this, e);
        }
        protected virtual void OnNodeMouseDoubleClick(TreeNodeMouseClickEventArgs e)
        {
            var nodeMouseDoubleClick = NodeMouseDoubleClick;
            if (nodeMouseDoubleClick != null)
                nodeMouseDoubleClick(this, e);
        }
        protected virtual void OnNodeMouseHover(TreeNodeMouseHoverEventArgs e)
        {
            var handler = NodeMouseHover;
            if (handler != null)
                handler(this, e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            // Reset filter.
            if (resetFilterTime > 0)
            {
                resetFilterTime -= swfHelper.GetDeltaTime();
                if (resetFilterTime <= 0)
                    filter = string.Empty;
            }

            e.Graphics.uwfFillRectangle(BackColor, 0, 0, Width, Height);

            for (int i = 0; i < scrollNodeList.Count; i++)
            {
                var scrollNode = scrollNodeList[i];

                // Instead of creating new args every frame for each node, we will use only cached one to prevent
                // additional memory allocations.
                // The problem is that you can't cache it somewhere else cause data in it will be always changing.
                nodeArgs.Graphics = e.Graphics;
                nodeArgs.Node = scrollNode;
                nodeArgs.Bounds = scrollNode.Bounds;
                nodeArgs.State = TreeNodeStates.Default;

                OnDrawNode(nodeArgs);
            }
        }
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            Refresh();
        }
        
        private void AdjustScrollIndexToNode(TreeNode node)
        {
            if (node == null) return;

            UpdateNodesBounds(node);
            
            var nodeY = node.Bounds.Y + scrollIndex;

            if (scrollIndex > nodeY)
                scrollIndex = nodeY;

            if (scrollIndex + Height < nodeY + ItemHeight)
                scrollIndex = nodeY + ItemHeight - Height;
        }
        private void Application_UpClick(object sender, MouseEventArgs e)
        {
            drag = false;
            dragNode = null;
            dragPosition = Point.Empty;
        }
        private Rectangle GetNodeBounds(TreeNode node)
        {
            int x = Padding.Left + 2;
            int y = Padding.Top - (int)scrollIndex;
            int width = Width;
            int height = ItemHeight;

            x += (node.GetXIndex() - 1) * 8;
            y += node.indexY * ItemHeight;

            return new Rectangle(x, y, width, height);
        }
        private void DrawNodeDefault(object sender, DrawTreeNodeEventArgs e)
        {
            const int TEXT_SELECTION_MARGIN_LEFT = 4;
            const int TEXT_SELECTION_MARGIN_RIGHT = 4;
            const int TEXT_SELECTION_HMARGIN = TEXT_SELECTION_MARGIN_LEFT + TEXT_SELECTION_MARGIN_RIGHT;
            const int TEXT_MARGIN_TOP = 2;
            const int TEXT_MARGIN_BOTTOM = 2;
            
            var node = e.Node;
            var nodeBounds = node.Bounds;
            var nodeX = nodeBounds.X;
            var nodeY = nodeBounds.Y;
            var nodeWidth = nodeBounds.Width;
            var nodeContainsArrow = node.Nodes.Count > 0;
            var nodeContainsImage = node.ImageIndex > -1 && ImageList != null;
            
            var graphics = e.Graphics;

            // Node drawing.
            graphics.uwfFillRectangle(node.BackColor, nodeBounds.X, nodeY, nodeWidth, nodeBounds.Height);
            
            // Draw selection.
            if (node.IsSelected || node == hoveredNode)
            {
                var selectX = 0;
                var selectY = nodeY;
                var selectWidth = Width;
                var selectHeight = ItemHeight;

                if (!FullRowSelect)
                {
                    selectX = nodeX + arrowSize;
                    selectWidth = node.textWidth;

                    if (nodeContainsImage)
                        selectWidth += nodeBounds.Height - TEXT_SELECTION_MARGIN_LEFT;
                    else
                        selectX -= TEXT_SELECTION_MARGIN_LEFT;
                }

                graphics.uwfFillRectangle(node.SelectColorInternal, selectX, selectY, selectWidth, selectHeight);
            }
            
            int xOffset = nodeBounds.X;

            // Draw collapsed/expanded arrow.
            if (nodeContainsArrow)
            {
                var arrowTexture = (Bitmap) null;
                
                if (node.IsExpanded)
                {
                    if (node.ImageIndex_Expanded > -1 && ImageList != null)
                    {
                        var img = ImageList.Images[node.ImageIndex_Expanded];
                        if (img != null)
                            arrowTexture = img as Bitmap;
                    }
                    else
                        arrowTexture = uwfAppOwner.Resources.TreeNodeExpanded;
                }
                else
                {
                    if (node.ImageIndex_Collapsed > -1 && ImageList != null)
                    {
                        var img = ImageList.Images[node.ImageIndex_Collapsed];
                        if (img != null)
                            arrowTexture = img as Bitmap;
                    }
                    else
                        arrowTexture = uwfAppOwner.Resources.TreeNodeCollapsed;
                }

                if (arrowTexture != null)
                {
                    var mouseClient = PointToClient(MousePosition);
                    var arrowWidth = arrowSize;
                    var arrowHeight = arrowSize;
                    var arrowX = xOffset;
                    var arrowY = nodeY + nodeBounds.Height / 2f - arrowHeight / 2f;
                    var arrowColor = uwfArrowImageColor;

                    // Check if arrow is hovered.
                    if (nodeBounds.Contains(mouseClient) && mouseClient.X <= arrowX + arrowWidth)
                        arrowColor = uwfArrowImageHoveredColor;
                    
                    graphics.uwfDrawImage(arrowTexture, arrowColor, arrowX, arrowY, arrowWidth, arrowHeight);
                }
            }

            xOffset += arrowSize;
            
            // Draw image.
            if (nodeContainsImage)
            {
                var image = ImageList.Images[node.ImageIndex];
                if (image != null && image.Texture != null)
                {
                    var imageSize = Math.Min(nodeBounds.Height - 2, image.Height);
                    var imageX = xOffset + (nodeBounds.Height - imageSize) / 2f;
                    var imageY = nodeY + (nodeBounds.Height - imageSize) / 2f;
                    
                    graphics.uwfDrawImage(image, node.ImageColor, imageX, imageY, imageSize, imageSize);
                    
                    xOffset += nodeBounds.Height;
                }
            }

            // Draw text.
            var nodeText = node.Text;
            if (nodeText == null && node.Tag != null)
            {
                nodeText = node.Tag.ToString();
                if (nodeText != node.tagString)
                {
                    node.textWidth = 0;
                    node.tagString = nodeText;
                }
            }

            if (node.textWidth == 0)
                node.textWidth = (int) graphics.MeasureString(nodeText, Font).Width + TEXT_SELECTION_HMARGIN;

            var nodeTextX = xOffset;
            var nodeTextY = nodeY - TEXT_MARGIN_TOP;
            var nodeTextWidth = node.textWidth;
            var nodeTextHeight = e.Bounds.Height + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM;
            var nodeColor = node.ForeColorInternal;
            var nodeFont = node.NodeFontInternal;
            
            graphics.uwfDrawString(nodeText, nodeFont, nodeColor, nodeTextX, nodeTextY, nodeTextWidth, nodeTextHeight, ContentAlignment.MiddleLeft);
            
            // End of drawing.

            // TODO: raise when DrawNodeMode is Normal.
            var drawNode = DrawNode;
            if (drawNode != null)
                drawNode(this, e);
        }
        private TreeNode SelectAtPosition(MouseEventArgs e)
        {
            var node = GetNodeAt(e.Location);
            if (node == null || !node.Enabled) return null;

            SelectedNode = node;

            OnAfterSelect(new TreeViewEventArgs(SelectedNode));

            return SelectedNode;
        }
        private void SelectNext()
        {
            var nextNode = nodeList.FindIndex(x => x == SelectedNode); // TODO: this is slow implementation. Should remember current selectedIndex.
            
            while (!SelectNext(nextNode))
            {
                nextNode++;
            }
        }
        private bool SelectNext(int fromIndex)
        {
            if (fromIndex + 1 >= nodeList.Count) return true;
            if (!nodeList[fromIndex + 1].Enabled) return false;

            SelectedNode = nodeList[fromIndex + 1];
            AdjustScrollIndexToNode(SelectedNode);

            OnAfterSelect(new TreeViewEventArgs(SelectedNode));
            return true;

        }
        private void SelectNodeWText(string text, bool caseSensitive = false)
        {
            var lowerText = text;
            if (!caseSensitive) lowerText = text.ToLower();

            for (int i = 0; i < nodeList.Count; i++)
            {
                var node = nodeList[i];
                var nodeText = node.Text;
                
                if (string.IsNullOrEmpty(nodeText) && node.Tag != null)
                    nodeText = node.Tag.ToString();

                if (nodeText == null || nodeText.Length < text.Length) continue;

                var clippedNodeText = nodeText.Substring(0, text.Length);
                if (!caseSensitive) clippedNodeText = clippedNodeText.ToLower();

                if (clippedNodeText == lowerText)
                {
                    SelectedNode = node;
                    break;
                }
            }
        }
        private void SelectPrevious()
        {
            var prevNode = nodeList.FindIndex(x => x == SelectedNode);
            while (!SelectPrevious(prevNode))
            {
                prevNode--;
            }
        }
        private bool SelectPrevious(int fromIndex)
        {
            if (fromIndex - 1 >= 0)
            {
                if (!nodeList[fromIndex - 1].Enabled) return false;

                SelectedNode = nodeList[fromIndex - 1];
                AdjustScrollIndexToNode(SelectedNode);

                OnAfterSelect(new TreeViewEventArgs(SelectedNode));
                return true;
            }

            return true;
        }
        private void UpdateNodeList(TreeNode node)
        {
            if (!node.IsVisible)
                return;

            if (node != root)
            {
                node.indexY = nodeList.Count;
                nodeList.Add(node);
            }
            
            if (node.IsExpanded)
                for (int i = 0; i < node.Nodes.Count; i++)
                    UpdateNodeList(node.Nodes[i]);
        }
        private void UpdateNodesBounds(TreeNode node)
        {
            if (!node.IsVisible) return;
            
            if (node != root) 
                node.Bounds = GetNodeBounds(node);
        }
        private void UpdateScrollBar()
        {
            var scrollMaximum = ItemHeight * nodeList.Count - 1 + Padding.Vertical;
            var scrollVisible = scrollMaximum > Height;

            if (scrollVisible)
            {
                uwfVScrollBar.ValueChanged -= VScrollBarOnValueChanged;
                uwfVScrollBar.Maximum = scrollMaximum;
                uwfVScrollBar.SmallChange = ItemHeight;
                uwfVScrollBar.LargeChange = Height;
                uwfVScrollBar.Visible = true;
                uwfVScrollBar.ValueChanged += VScrollBarOnValueChanged;
            }
            else
            {
                if (uwfVScrollBar.Visible)
                {
                    uwfVScrollBar.Visible = false; // we can dispose scrollbar, but I think it's not effective.
                    uwfVScrollBar.ValueChanged -= VScrollBarOnValueChanged;
                    uwfVScrollBar.Value = 0;
                    uwfVScrollBar.ValueChanged += VScrollBarOnValueChanged;
                }
            }
        }
        private void UpdateScrollList()
        {
            scrollNodeList.Clear();

            // Update maximum before calculations.
            if (uwfVScrollBar.Visible)
            {
                uwfVScrollBar.ValueChanged -= VScrollBarOnValueChanged;
                uwfVScrollBar.Maximum = ItemHeight * nodeList.Count - 1 + Padding.Vertical;
                uwfVScrollBar.ValueChanged += VScrollBarOnValueChanged;
            }

            UpdateScrollBar();

            int startNode = (int)(scrollIndex / ItemHeight) - 1;
            if (startNode < 0) startNode = 0;
            int lNodesOnScreen = nodesOnScreen + 3;

            var nodeListCount = nodeList.Count;
            for (int i = startNode; i < startNode + lNodesOnScreen && i < nodeListCount; i++)
            {
                var node = nodeList[i];
                
                UpdateNodesBounds(node);
                
                var nodeBounds = node.Bounds;
                if (nodeBounds.Y + nodeBounds.Height > 0 && nodeBounds.Y - (int)scrollIndex < Height)
                    scrollNodeList.Add(node);
            }

            filter = string.Empty; // reset filter.
            resetFilterTime = 0;
        }
        private void VScrollBarOnValueChanged(object sender, EventArgs eventArgs)
        {
            UpdateScrollList();
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/DataFormats.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public static class DataFormats
    {
        public static readonly string FileDrop = "FileDrop";
    }
}


<|start_filename|>Assets/System/Windows/Forms/NumericUpDown.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;
    using System.Globalization;

    public class NumericUpDown : Control
    {
        internal static Func<CultureInfo> uwfGetCulture = () => Application.CurrentCulture;
        
        internal Pen borderPen = new Pen(Color.Transparent);
        internal Button uwfButtonDecrease;
        internal Button uwfButtonIncrease;
        internal Color uwfBorderColor;
        internal Color uwfBorderDisabledColor;
        internal Color uwfBorderFocusedColor;
        internal Color uwfBorderHoverColor;
        internal Color uwfDisabledBackColor;
        internal Color uwfDisabledForeColor;

        protected decimal value;
        protected string valueText = "0";
        
        private static readonly Padding defaultPadding = new Padding(4, 0, 4, 0);
        private bool hexadecimal;
        private decimal minimum;
        private decimal maximum;

        public NumericUpDown() : this(true)
        {
        }
        internal NumericUpDown(bool initButtons)
        {
            BackColor = SystemColors.Window;
            Increment = 1;
            InterceptArrowKeys = true;
            Maximum = 100;
            Minimum = 0;
            Padding = defaultPadding;
            TextAlign = HorizontalAlignment.Left;

            uwfBorderColor = SystemColors.ActiveBorder;
            uwfBorderDisabledColor = Color.FromArgb(0xAB, 0xAD, 0xB3);
            uwfBorderHoverColor = SystemColors.ActiveBorder;
            uwfBorderFocusedColor = SystemColors.ActiveBorder;
            uwfDisabledBackColor = SystemColors.Control;
            uwfDisabledForeColor = SystemColors.ActiveBorder;

            if (initButtons)
            {
                uwfButtonIncrease = new UpDownButton(this, true);
                uwfButtonIncrease.Location = new Point(Width - 16, Height / 2 - 8);
                uwfButtonIncrease.Image = uwfAppOwner.Resources.NumericUp;
                uwfButtonIncrease.uwfImageColor = Color.FromArgb(0x40, 0x40, 0x40);
                uwfButtonIncrease.uwfImageHoverColor = uwfButtonIncrease.uwfImageColor; 
                
                uwfButtonDecrease = new UpDownButton(this, false);
                uwfButtonDecrease.Location = new Point(Width - 16, Height / 2);
                uwfButtonDecrease.Image = uwfAppOwner.Resources.NumericDown;
                uwfButtonDecrease.uwfImageColor = Color.FromArgb(0x40, 0x40, 0x40);
                uwfButtonDecrease.uwfImageHoverColor = uwfButtonDecrease.uwfImageColor;
                
                Controls.Add(uwfButtonIncrease);
                Controls.Add(uwfButtonDecrease);
            }
        }

        public event EventHandler ValueChanged;

        public decimal Increment { get; set; }
        public bool InterceptArrowKeys { get; set; }
        public bool Hexadecimal
        {
            get { return hexadecimal; }
            set
            {
                hexadecimal = value;
                UpdateEditText();
            }
        }
        public decimal Maximum
        {
            get { return maximum; }
            set
            {
                if (value < minimum) minimum = value;
                
                maximum = value;
                
                if (this.value < minimum)
                {
                    this.value = minimum;
                    UpdateEditText();
                }

                if (this.value > maximum)
                {
                    this.value = maximum;
                    UpdateEditText();
                }
            }
        }
        public decimal Minimum
        {
            get { return minimum; }
            set
            {
                if (value > maximum) maximum = value;
                
                minimum = value;
                
                if (this.value < minimum)
                {
                    this.value = minimum;
                    UpdateEditText();
                }

                if (this.value > maximum)
                {
                    this.value = maximum;
                    UpdateEditText();
                }
            }
        }
        public HorizontalAlignment TextAlign { get; set; }
        public decimal Value
        {
            get { return value; }
            set
            {
                if (this.value == value)
                    return;

                this.value = Constrain(value);
                UpdateEditText();

                OnValueChanged(EventArgs.Empty);
            }
        }

        protected override Size DefaultSize
        {
            get { return new Size(120, 20); }
        }

        public virtual void DownButton()
        {
            Value -= Increment;
        }
        public virtual void UpButton()
        {
            Value += Increment;
        }

        protected internal override void uwfOnLatePaint(PaintEventArgs e)
        {
            base.uwfOnLatePaint(e);

            borderPen.Color = uwfBorderColor;
            if (!Enabled)
                borderPen.Color = uwfBorderDisabledColor;
            else if (Focused)
                borderPen.Color = uwfBorderFocusedColor;
            else if (hovered)
                borderPen.Color = uwfBorderHoverColor;
            
            e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
        }

        protected void ConfirmValue()
        {
            if (string.IsNullOrEmpty(valueText))
                return;

            try
            {
                if (Hexadecimal)
                    Value = Constrain(Convert.ToDecimal(Convert.ToInt32(valueText, 16)));
                else
                    Value = Constrain(decimal.Parse(valueText, uwfGetCulture()));
            }
            catch
            {
                UpdateEditText();
            }
        }
        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);

            ConfirmValue();
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (InterceptArrowKeys)
            {
                if (e.KeyCode == Keys.Up)
                    UpButton();
                else if (e.KeyCode == Keys.Down)
                    DownButton();
            }
            
            base.OnKeyDown(e);

            if (e.KeyCode == Keys.Return)
                ConfirmValue();
        }
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            if (Enabled)
                Cursor.Current = Cursors.IBeam;
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            
            Cursor.Current = Cursors.Default;
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            if (!Focused) return;

            if (e.Delta < 0)
                Value -= Increment;
            if (e.Delta > 0)
                Value += Increment;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var g = e.Graphics;

            int textPaddingRight = 0;
            if (uwfButtonIncrease != null && uwfButtonIncrease.Visible)
                textPaddingRight = -16;

            var backColor = Enabled ? BackColor : uwfDisabledBackColor;
            var foreColor = Enabled ? ForeColor : uwfDisabledForeColor;

            g.uwfFillRectangle(backColor, 0, 0, Width, Height);

            if (Focused)
                valueText = g.uwfDrawTextField(valueText, Font, foreColor, Padding.Left - 2, 0, Width + textPaddingRight + 4, Height, TextAlign);
            else
                g.uwfDrawString(valueText, Font, foreColor, Padding.Left, 0, Width + textPaddingRight, Height, TextAlign);
        }
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            UpdateButtonsLocation();
        }
        protected virtual void OnValueChanged(EventArgs e)
        {
            var handler = ValueChanged;
            if (handler != null) handler(this, e);
        }

        private decimal Constrain(decimal avalue)
        {
            if (avalue < minimum)
                avalue = minimum;

            if (avalue > maximum)
                avalue = maximum;

            return avalue;
        }
        private void UpdateButtonsLocation()
        {
            var width = Width;
            var height = Height;
            if (uwfButtonIncrease != null)
                uwfButtonIncrease.Location = new Point(width - 16, height / 2 - 8);
            if (uwfButtonDecrease != null)
                uwfButtonDecrease.Location = new Point(width - 16, height / 2);
        }
        private void UpdateEditText()
        {
            valueText = Hexadecimal 
                ? Convert.ToInt64(value).ToString("X") 
                : value.ToString(uwfGetCulture());
        }

        internal class UpDownButton : RepeatButton
        {
            private static readonly Color defaultBorderColor = Color.FromArgb(172, 172, 172);
            private static readonly Color defaultBorderHoverColor = Color.FromArgb(126, 180, 234);
            private static readonly Color defaultHoverColor = Color.FromArgb(228, 241, 252);
            private readonly NumericUpDown owner;
            private readonly bool upButton;

            internal UpDownButton(NumericUpDown owner, bool upButton)
            {
                this.owner = owner;
                this.upButton = upButton;

                Anchor = AnchorStyles.Right | AnchorStyles.Top;
                BackColor = SystemColors.Control;
                TabStop = false;

                uwfBorderColor = defaultBorderColor;
                uwfHoverColor = defaultHoverColor;
                uwfBorderHoverColor = defaultBorderHoverColor;
            }

            protected override Size DefaultSize
            {
                get { return new Size(14, 8); }
            }

            protected override void OnClick(EventArgs e)
            {
                base.OnClick(e);

                if (upButton)
                    owner.UpButton();
                else
                    owner.DownButton();
            }
        }
    }
}


<|start_filename|>Assets/System/Drawing/Font.cs<|end_filename|>
﻿namespace System.Drawing
{
    [Flags]
    public enum FontStyle
    {
        Regular = 0,
        Bold = 1,
        Italic = 2,
        Underline = 4,
        Strikeout = 8,
    }
    
    public sealed class Font
    {
        internal object fontObject;

        private readonly string name;
        private readonly FontStyle style;

        public Font(string familyName, float emSize)
        {
            name = familyName;
            Size = emSize;
        }
        public Font(string familyName, float emSize, FontStyle style)
        {
            name = familyName;
            this.style = style;
            Size = emSize;
        }

        public string Name { get { return name; } }
        public float Size { get; set; }
        public FontStyle Style { get { return style; } }

        public override string ToString()
        {
            return string.Format("[{0}, {1}, {2}]", Name, Size, Style);
        }
    }
}


<|start_filename|>Assets/Unity/Views/IObjectDesigner.cs<|end_filename|>
﻿namespace Unity.Views
{
    public interface IObjectDesigner
    {
        object Value { get; }

        object Draw(int width, int height);
    }
}


<|start_filename|>Assets/Controls/Highcharts/SeriesPaint.cs<|end_filename|>
namespace Highcharts
{
    using System.Drawing;
    
    public static class SeriesPaint
    {
        private static readonly SolidBrush pointBrush = new SolidBrush(Color.Black);
        
        public static void PaintPoint(Series s, Graphics g, Rectangle clipRectangle, int dataIndex)
        {
            pointBrush.Color = s.color;

            var valueRange = s.GetValueRange();
            var xStep = s.GetXStep();
            
            var valueX = s.GetXFromIndex(dataIndex, xStep, clipRectangle);
            var valueY = s.GetYFromValue(s.data[dataIndex], valueRange, clipRectangle);
            var valueDiameter = s.collection.chart.circleRadius * 2;

            g.FillEllipse(pointBrush, valueX, valueY, valueDiameter, valueDiameter);
        }

        public static void PaintHoveredValueRect(Series s, Graphics g, float currentValueX, float currentValueY, float xStep)
        {
            if (s.collection.chart.hovered && 
                s.collection.chart.mouseX - s.collection.chart.cachedPlotLeft > currentValueX &&
                s.collection.chart.mouseX - s.collection.chart.cachedPlotLeft < currentValueX + xStep)
                g.uwfFillRectangle(s.color, currentValueX - 2, currentValueY - 2, 4, 4);
        }
    }
}

<|start_filename|>Assets/Core/ApplicationResources.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections.Generic;
    
    internal static class ApplicationResources
    {
        public static AppGdiImages Images { get; set; }
        public static List<string> Fonts { get; set; }
    }
}


<|start_filename|>Assets/Utility/KeyHelper.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public static class KeyHelper
    {
        /// <summary>
        /// Get last char from UnityEngine.Input.inputString.
        /// </summary>
        /// <returns>\0 if no chars was found</returns>
        public static char GetLastInputChar()
        {
            int len = UnityEngine.Input.inputString.Length;
            if (len == 0) return '\0';
            return UnityEngine.Input.inputString[len - 1];
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripDropDownDirection.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum ToolStripDropDownDirection
    {
        AboveLeft = 0x0000, 
        AboveRight = 0x0001, 
        BelowLeft = 0x0002, 
        BelowRight = 0x0003,
        Left = 0x0004, 
        Right = 0x0005, 
        Default = 0x0007 
    }
}


<|start_filename|>Assets/System/Windows/Forms/TreeViewEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void TreeViewEventHandler(object sender, TreeViewEventArgs e);
}


<|start_filename|>Assets/System/Windows/Forms/CreateParams.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Text;

    public class CreateParams
    {
        public string Caption { get; set; }
        public string ClassName { get; set; }
        public int ClassStyle { get; set; }
        public int ExStyle { get; set; }
        public int Height { get; set; }
        public object Param { get; set; }
        public IntPtr Parent { get; set; }
        /// <summary>
        /// TODO: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
        /// </summary>
        public int Style { get; set; }
        public int Width { get; set; }
        public int X { get; set; }
        public int Y { get; set; }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder(64);
            sb.Append("CreateParams {'");
            sb.Append(ClassName);
            sb.Append("', '");
            sb.Append(Caption);
            sb.Append("', 0x");
            sb.Append(Convert.ToString(Style, 16));
            sb.Append(", 0x");
            sb.Append(Convert.ToString(ExStyle, 16));
            sb.Append(", {");
            sb.Append(X);
            sb.Append(", ");
            sb.Append(Y);
            sb.Append(", ");
            sb.Append(Width);
            sb.Append(", ");
            sb.Append(Height);
            sb.Append("}");
            sb.Append("}");
            return sb.ToString();
        }
    }
}


<|start_filename|>Assets/System/Drawing/Brush.cs<|end_filename|>
﻿namespace System.Drawing
{
    public abstract class Brush : ICloneable, IDisposable
    {
        ~Brush() 
        {
            Dispose(false);
        }
        
        public abstract object Clone();
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/DrawItemEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class DrawItemEventArgs : EventArgs
    {
        private readonly Color backColor;
        private readonly DrawItemState state;
        private readonly Color foreColor;

        public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state)
        {
            Graphics = graphics;
            Font = font;
            Bounds = rect;
            Index = index;
            this.state = state;
        }
        public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state,
                                 Color foreColor, Color backColor) : this(graphics, font, rect, index, state)
        {
            this.foreColor = foreColor;
            this.backColor = backColor;
        }

        public Color BackColor
        {
            get
            {
                return backColor;
            }
        }
        public Rectangle Bounds { get; private set; }
        public Font Font { get; private set; }
        public Color ForeColor
        {
            get
            {
                return foreColor;
            }
        }
        public Graphics Graphics { get; private set; }
        public int Index { get; private set; }
        public DrawItemState State
        {
            get { return state; }
        }

        public virtual void DrawBackground()
        {
            Graphics.uwfFillRectangle(BackColor, Bounds);
        }
        public virtual void DrawFocusRectangle()
        {

        }
    }
}


<|start_filename|>Assets/Utility/swfHelper.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public static class swfHelper
    {
        public static float GetDeltaTime()
        {
            if (ApiHolder.Timing == null)
                return 1f / 60f;
            return ApiHolder.Timing.DeltaTime;
        }
        public static void DoScroll(this ScrollBar sb, ScrollEventType type)
        {
            var value = sb.Value;
            int newValue = value;

            switch (type)
            {
                case ScrollEventType.First:
                    newValue = sb.Minimum;
                    break;

                case ScrollEventType.Last:
                    newValue = sb.Maximum - sb.LargeChange + 1;
                    break;

                case ScrollEventType.SmallDecrement:
                    newValue = Math.Max(value - sb.SmallChange, sb.Minimum);
                    break;

                case ScrollEventType.SmallIncrement:
                    newValue = Math.Min(value + sb.SmallChange, sb.Maximum - sb.LargeChange + 1);
                    break;

                case ScrollEventType.LargeDecrement:
                    newValue = Math.Max(value - sb.LargeChange, sb.Minimum);
                    break;

                case ScrollEventType.LargeIncrement:
                    newValue = Math.Min(value + sb.LargeChange, sb.Maximum - sb.LargeChange + 1);
                    break;

                case ScrollEventType.ThumbPosition:
                case ScrollEventType.ThumbTrack:

                    // not implemented yet.
                    break;
            }
            
            sb.Value = newValue;
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelSplitContainer.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Drawing;
    using System.Windows.Forms;
    
    public class PanelSplitContainer : BaseExamplePanel
    {
        public override void Initialize()
        {
            var checkOrientation = this.Create<CheckBox>("Vertical");
            checkOrientation.Checked = true;
            
            var container = this.Create<SplitContainer>();
            container.Size = new Size(260, 200);
            container.BorderStyle = BorderStyle.Fixed3D;
            container.Panel1.BackColor = Color.CornflowerBlue;
            container.Panel2.BackColor = Color.LightCoral;
            container.Panel1.Create<Label>("Panel1");
            container.Panel2.Create<Label>("Panel2");
            
            checkOrientation.CheckedChanged += (sender, args) =>
            {
                if (checkOrientation.Checked)
                    container.Orientation = Orientation.Vertical;
                else
                    container.Orientation = Orientation.Horizontal;
            };
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/TabControlEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void TabControlEventHandler(object sender, TabControlEventArgs e);

    public enum TabControlAction
    {
        Selecting,
        Selected,
        Deselecting,
        Deselected
    }

    public class TabControlEventArgs : EventArgs
    {
        public TabControlEventArgs(TabPage tabPage, int tabPageIndex, TabControlAction action)
        {
            Action = action;
            TabPage = tabPage;
            TabPageIndex = tabPageIndex;
        }

        public TabControlAction Action { get; private set; }
        public TabPage TabPage { get; private set; }
        public int TabPageIndex { get; private set; }
    }
}


<|start_filename|>Assets/Controls/Highcharts/PlotOptions.cs<|end_filename|>
﻿namespace Highcharts
{
    public class PlotOptions
    {
        public bool linearGradient { get; set; }
        public object linearGradientMaterial { get; set; } // Gradient material for areaSolidOutline series type.
    }
}


<|start_filename|>Assets/System/Windows/Forms/ButtonBase.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class ButtonBase : Control
    {
        // Back colors.
        internal Color uwfDisabledColor = SystemColors.Control;
        internal Color uwfHoverColor = Color.FromArgb(223, 238, 252);
        
        // Border colors.
        internal Color uwfBorderColor = SystemColors.ActiveBorder;
        internal Color uwfBorderDisableColor = Color.FromArgb(217, 217, 217);
        internal Color uwfBorderHoverColor = Color.FromArgb(126, 180, 234);
        internal Color uwfBorderSelectColor = SystemColors.Highlight;
        
        // Fore colors.
        internal Color uwfForeDisabledColor = SystemColors.InactiveCaption;
        
        // Image colors.
        internal Bitmap uwfImageHover;
        internal Color uwfImageColor = Color.White;
        internal Color uwfImageDisabledColor = Color.White;
        internal Color uwfImageHoverColor = Color.White;

        private const float IMAGE_BORDER_OFFSET = 2f;

        private readonly Pen borderPen = new Pen(Color.Transparent);

        private Bitmap imageFromList;
        private int imageIndex;
        private ImageList imageList;
        
        public ButtonBase()
        {
            BackgroundImageLayout = ImageLayout.Center;
            FlatStyle = FlatStyle.Standard;
            ImageAlign = ContentAlignment.MiddleCenter;
            TextAlign = ContentAlignment.MiddleCenter;
        }

        public FlatStyle FlatStyle { get; set; }
        public Bitmap Image { get; set; }
        public ContentAlignment ImageAlign { get; set; }
        public int ImageIndex
        {
            get { return imageIndex; }
            set
            {
                imageIndex = value;
                if (ImageList != null && imageIndex >= 0 && imageIndex < ImageList.Images.Count)
                    imageFromList = ImageList.Images[imageIndex] as Bitmap;
            }
        }
        public ImageList ImageList
        {
            get { return imageList; }
            set
            {
                imageList = value;
                if (ImageList != null && imageIndex >= 0 && imageIndex < ImageList.Images.Count)
                    imageFromList = ImageList.Images[imageIndex] as Bitmap;
            }
        }
        public virtual ContentAlignment TextAlign { get; set; }

        protected override Size DefaultSize
        {
            get { return new Size(75, 23); }
        }

        internal override void RaiseOnMouseClick(MouseEventArgs e)
        {
            var iButtonControl = this as IButtonControl;
            if (iButtonControl != null)
            {
                OnMouseClick(e);
                iButtonControl.PerformClick(); // Originally in WndProc.
            }
            else
                base.RaiseOnMouseClick(e);
        }

        protected internal virtual void DrawTabDots(PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(uwfTabPen, 2, 2, Width - 4, Height - 4);
        }
        
        protected override void OnKeyUp(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Return)
                OnClick(EventArgs.Empty);

            base.OnKeyUp(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;

            // Image.
            DrawImage(g); 

            // Text.
            var text = Text;
            var textX = Padding.Left;
            var textY = Padding.Top;
            var textW = Width - Padding.Horizontal;
            var textH = Height - Padding.Vertical;
            var textColor = ForeColor;
            var textFont = Font;

            if (!Enabled)
                textColor = uwfForeDisabledColor;
            
            g.uwfDrawString(text, textFont, textColor, textX, textY, textW, textH, TextAlign);

            // Border.
            var borderColorToDraw = Color.Transparent;

            // Get colors from style.
            switch (FlatStyle)
            {
                case FlatStyle.Flat:
                    borderColorToDraw = Color.Black;
                    break;
                case FlatStyle.Popup:
                    borderColorToDraw = SystemColors.ControlDark;
                    break;
                case FlatStyle.Standard:
                case FlatStyle.System:

                    // Border.
                    if (!Enabled)
                        borderColorToDraw = uwfBorderDisableColor;
                    else if (uwfHovered)
                        borderColorToDraw = uwfBorderHoverColor;
                    else if (Focused)
                        borderColorToDraw = uwfBorderSelectColor;
                    else
                        borderColorToDraw = uwfBorderColor;
                    break;
            }

            borderPen.Color = borderColorToDraw;

            g.DrawRectangle(borderPen, 0, 0, Width, Height);
            
            if (uwfCanDrawTabDots && uwfDrawTabDots && Focused)
                DrawTabDots(e);
        }
        protected override void OnPaintBackground(PaintEventArgs args)
        {
            var backColor = BackColor;
            
            if (!Enabled)
                backColor = uwfDisabledColor;
            else if (hovered)
                backColor = uwfHoverColor;

            PaintBackground(args, ClientRectangle, backColor, Point.Empty);
        }

        private void DrawImage(Graphics g)
        {
            // Image.
            var imageToPaint = Image;
            if (imageFromList != null)
                imageToPaint = imageFromList;

            if (imageToPaint == null) return;

            var imageWidth = imageToPaint.Width;
            var imageHeight = imageToPaint.Height;
            var imageColorToPaint = uwfImageColor;
            if (Enabled == false)
                imageColorToPaint = uwfImageDisabledColor;
            else if (uwfHovered)
            {
                if (uwfImageHover != null)
                    imageToPaint = uwfImageHover;
                imageColorToPaint = uwfImageHoverColor;
            }

            float ix = 0, iy = 0;

            // Adjust Y.
            switch (ImageAlign)
            {
                case ContentAlignment.BottomCenter:
                case ContentAlignment.BottomLeft:
                case ContentAlignment.BottomRight:
                    iy = Height - imageHeight - IMAGE_BORDER_OFFSET;
                    break;
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.MiddleLeft:
                case ContentAlignment.MiddleRight:
                    iy = Height / 2f - imageHeight / 2f;
                    break;
                case ContentAlignment.TopCenter:
                case ContentAlignment.TopLeft:
                case ContentAlignment.TopRight:
                    iy = IMAGE_BORDER_OFFSET;
                    break;
            }

            // Adjust X.
            switch (ImageAlign)
            {
                case ContentAlignment.BottomCenter:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.TopCenter:
                    ix = Width / 2f - imageWidth / 2f;
                    break;
                case ContentAlignment.BottomLeft:
                case ContentAlignment.MiddleLeft:
                case ContentAlignment.TopLeft:
                    ix = IMAGE_BORDER_OFFSET;
                    break;
                case ContentAlignment.BottomRight:
                case ContentAlignment.MiddleRight:
                case ContentAlignment.TopRight:
                    ix = Width - imageWidth - IMAGE_BORDER_OFFSET;
                    break;
            }

            g.uwfDrawImage(imageToPaint, imageColorToPaint, ix, iy, imageWidth, imageHeight);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/RadioButton.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class RadioButton : ButtonBase
    {
        private readonly AppGdiImages resources;
        private bool autoCheck = true;
        private bool firstfocus = true;
        private bool isChecked;
        private bool  measureText;
        private SizeF textSize;

        public RadioButton()
        {
            BackColor = Color.Transparent;
            Padding = new Padding(18, 0, 4, 0);
            TextAlign = ContentAlignment.MiddleLeft;

            resources = uwfAppOwner.Resources;
            uwfBorderColor = Color.Transparent;
            uwfBorderHoverColor = Color.Transparent;
            uwfBorderSelectColor = Color.Transparent;
            uwfHoverColor = Color.Transparent;
        }

        public event EventHandler CheckedChanged;

        public bool AutoCheck
        {
            get { return autoCheck; }
            set
            {
                if (autoCheck == value)
                    return;

                autoCheck = value;
                PerformAutoUpdates(false);
            }
        }
        public bool Checked
        {
            get { return isChecked; }
            set
            {
                if (isChecked == value)
                    return;

                isChecked = value;
                PerformAutoUpdates(false);
                OnCheckedChanged(EventArgs.Empty);
            }
        }

        protected override Size DefaultSize
        {
            get { return new Size(104, 24); }
        }

        protected internal override void DrawTabDots(PaintEventArgs e)
        {
            if (measureText)
                textSize = e.Graphics.MeasureString(Text, Font);

            e.Graphics.DrawRectangle(uwfTabPen, Padding.Left - 2, (Height - textSize.Height) / 2 + 2, textSize.Width + 4, textSize.Height - 4);
        }

        protected virtual void OnCheckedChanged(EventArgs e)
        {
            var handler = CheckedChanged;
            if (handler != null)
                handler(this, e);
        }
        protected override void OnClick(EventArgs e)
        {
            if (autoCheck)
                Checked = true;

            base.OnClick(e);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            
            if (e.KeyCode == Keys.Down)
                NextButton();
            
            if (e.KeyCode == Keys.Up)
                PreviousButton();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var radioImage = resources.RadioButton_Unchecked;
            if (hovered)
                radioImage = resources.RadioButton_Hovered;

            e.Graphics.DrawImage(radioImage, 0, 4, 16, 16);
            if (isChecked)
                e.Graphics.DrawImage(resources.RadioButton_Checked, 0, 4, 16, 16);
        }
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            measureText = true;
        }

        private void NextButton()
        {
            var parent = Parent;
            if (parent == null)
                return;

            var buttons = parent.Controls.FindAll(b => b is RadioButton);
            if (buttons.Count == 0)
                return;

            var index = buttons.FindIndex(b => b == this) + 1;
            if (index >= buttons.Count)
                index = 0;

            ((RadioButton) buttons[index]).Checked = true;
            buttons[index].Focus();
        }
        private void PerformAutoUpdates(bool tabbedInto)
        {
            if (!autoCheck)
                return;

            if (firstfocus)
                WipeTabStops(tabbedInto);

            TabStop = isChecked;

            if (!isChecked)
                return;

            var parent = Parent;
            if (parent == null)
                return;

            var parentControls = parent.Controls;
            for (int i = 0; i < parentControls.Count; i++)
            {
                var childRadioButton = parentControls[i] as RadioButton;
                if (childRadioButton == null || childRadioButton == this)
                    continue;

                childRadioButton.Checked = false;
            }
        }
        private void PreviousButton()
        {
            var parent = Parent;
            if (parent == null)
                return;

            var buttons = parent.Controls.FindAll(b => b is RadioButton);
            if (buttons.Count == 0)
                return;

            var index = buttons.FindIndex(b => b == this) - 1;
            if (index < 0)
                index = buttons.Count - 1;

            ((RadioButton) buttons[index]).Checked = true;
            buttons[index].Focus();
        }
        private void WipeTabStops(bool tabbedInto)
        {
            var parent = Parent;
            if (parent == null)
                return;

            var parentControls = parent.Controls;
            for (int i = 0; i < parentControls.Count; i++)
            {
                var childRadioButton = parentControls[i] as RadioButton;
                if (childRadioButton == null)
                    continue;

                if (!tabbedInto)
                    childRadioButton.firstfocus = false;
                
                if (childRadioButton.autoCheck)
                    childRadioButton.TabStop = false;
            }
        }
    }
}


<|start_filename|>Assets/Examples/FormExamples.cs<|end_filename|>
﻿namespace UnityWinForms.Examples
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    using Examples.Panels;

    public sealed class FormExamples : Form
    {
        private readonly TreeView treeView;

        private BaseExamplePanel currentPanel;

        public FormExamples()
        {
            // NOTE: most properties and methods that starts with 'uwf' are
            // internal and not supported by original Windows Forms.

            BackColor = Color.FromArgb(239, 235, 233);
            MinimumSize = new Size(320, 240);
            Text = "Unity-WinForms";
            Size = new Size(640, 480);
            SizeGripStyle = SizeGripStyle.Show;

            treeView = new TreeView();
            treeView.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
            treeView.Location = new Point(0, uwfHeaderHeight - 1); // All controls should be placed with Form header offset.
            treeView.Height = Height - uwfHeaderHeight + 1;
            treeView.TabStop = false;
            treeView.Width = 220;
            treeView.NodeMouseClick += TreeViewOnNodeMouseClick;

            Controls.Add(treeView);

            var labelNote = new Label();
            labelNote.Font = new Font("Arial", 14, FontStyle.Bold);
            labelNote.Location = new Point(treeView.Location.X + treeView.Width + 16, treeView.Location.Y);
            labelNote.Text = 
                "This is not completed overview of the UWF controls.\r\n" + 
                "Work in progress.\r\n\r\n" +
                "Do not forget that you can still modify controls\r\n" + 
                "with 'SWF Inspector' which is located in drop down\r\n" + 
                "menu 'Window' -> 'UnityWinForms'.";
            
            Controls.Add(labelNote);

            var nodeControls = new TreeNode("Controls");
            AddNode(nodeControls, "Button", typeof(PanelButton));
            AddNode(nodeControls, "CheckBox", typeof(PanelCheckBox));
            AddNode(nodeControls, "ComboBox", typeof(PanelComboBox));
            AddNode(nodeControls, "DateTimePicker", typeof(PanelDateTimePicker));
            AddNode(nodeControls, "FileDialog", typeof(PanelFileDialog));
            AddNode(nodeControls, "FontDialog", typeof(PanelFontDialog));
            AddNode(nodeControls, "Form", typeof(PanelForm));
            AddNode(nodeControls, "GroupBox", typeof(PanelGroupBox));
            AddNode(nodeControls, "Label", typeof(PanelLabel));
            AddNode(nodeControls, "LinkLabel", typeof(PanelLinkLabel));
            AddNode(nodeControls, "MenuStrip", typeof(PanelMenuStrip));
            AddNode(nodeControls, "MonthCalendar", typeof(PanelMonthCalendar));
            AddNode(nodeControls, "NumericUpDown", typeof(PanelNumericUpDown));
            AddNode(nodeControls, "Panel", typeof(PanelPanel));
            AddNode(nodeControls, "PictureBox", typeof(PanelPictureBox));
            AddNode(nodeControls, "ProgressBar", typeof(PanelProgressBar));
            AddNode(nodeControls, "RadioButton", typeof(PanelRadioButton));
            AddNode(nodeControls, "ScrollBar", typeof(PanelScrollBar));
            AddNode(nodeControls, "SplitContainer", typeof(PanelSplitContainer));
            AddNode(nodeControls, "TabControl", typeof(PanelTabControl));
            AddNode(nodeControls, "TrackBar", typeof(PanelTrackBar));
            AddNode(nodeControls, "TreeView", typeof(PanelTreeView));
            
            treeView.Nodes.Add(nodeControls);

            var nodeOtherControls = new TreeNode("Other");
            AddNode(nodeOtherControls, "Chart", typeof(PanelChart));
            AddNode(nodeOtherControls, "ColorPicker", typeof(PanelColorPicker));
            AddNode(nodeOtherControls, "TableView", typeof(PanelTableView));
            AddNode(nodeOtherControls, "TableViewLazy", typeof(PanelTableViewLazy));
            
            treeView.Nodes.Add(nodeOtherControls);

            // Refresh method or ExpandAll will update view list. 
            // NOTE: most controls don't need to be refreshed. Make sure to take a look 
            // at Refresh implementation in Control that you think is not working.
            treeView.ExpandAll();

            // Grip renderer is normal control. Bring it to front if you use it over other controls that can technically hide it.
            // uwfSizeGripRenderer.BringToFront();
        }

        public void SetPanel(BaseExamplePanel panel)
        {
            if (currentPanel != null && !currentPanel.IsDisposed)
                currentPanel.Dispose();

            currentPanel = panel;
            currentPanel.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
            currentPanel.Location = new Point(treeView.Location.X + treeView.Width, uwfHeaderHeight);
            currentPanel.Height = Height - uwfHeaderHeight - 16; // We don't want to hide SizeGripRenderer with scrollbars.
            currentPanel.Width = Width - treeView.Width;

            Controls.Add(currentPanel);

            currentPanel.Initialize();
        }
        
        private static void AddNode(TreeNode parent, string text, object tag)
        {
            var node = new TreeNode(text);
            node.Tag = tag;
            
            parent.Nodes.Add(node);
        }
        private void TreeViewOnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button != MouseButtons.Left || e.Node == null || e.Node.Tag == null)
                return;

            var panelType = e.Node.Tag as Type;
            if (panelType == null)
                return;

            var panel = Activator.CreateInstance(panelType) as BaseExamplePanel;
            if (panel == null)
                return;

            SetPanel(panel);
        }
    }
}


<|start_filename|>Assets/Controls/ColorPicker.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class ColorPicker : Button
    {
        private readonly Pen cpBorderPen = new Pen(Color.FromArgb(172, 172, 172));
        private readonly SolidBrush cpColorBrush = new SolidBrush(Color.White);
        private readonly SolidBrush cpAlphaBackBrush = new SolidBrush(Color.Black);
        private readonly SolidBrush cpAlphaFrontBrush = new SolidBrush(Color.White);

        private Color borderColor;
        private Color color;

        public ColorPicker()
        {
            BorderColor = Color.FromArgb(172, 172, 172);
            BorderHoverColor = Color.FromArgb(126, 180, 234);
            Color = Color.White;
            Size = new Size(128, 20);
        }

        public event EventHandler ColorChanged = delegate { };

        public Color BorderColor
        {
            get { return borderColor; }
            set
            {
                borderColor = value;
                cpBorderPen.Color = value;
            }
        }
        public Color BorderHoverColor { get; set; }
        public Color Color
        {
            get { return color; }
            set
            {
                color = value;
                cpColorBrush.Color = Color.FromArgb(255, value);
            }
        }

        protected virtual void OnColorChanged(object sender, EventArgs e)
        {
            ColorChanged(this, EventArgs.Empty);
        }
        protected override void OnMouseClick(MouseEventArgs e)
        {
            var formStartPosition = FormStartPosition.CenterParent;
            var parentForm = FindFormInternal();
            if (parentForm == null)
                formStartPosition = FormStartPosition.WindowsDefaultLocation;

            var colorPickerForm = new ColorPickerForm();
            colorPickerForm.Color = Color;
            colorPickerForm.StartPosition = formStartPosition;
            colorPickerForm.ColorChanged += (sender, args) =>
            {
                Color = ((ColorPickerForm)sender).Color;
                OnColorChanged(this, args);
            };
            colorPickerForm.ShowDialog(parentForm);
        }
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            cpBorderPen.Color = BorderHoverColor;
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            cpBorderPen.Color = BorderColor;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            float alphaWidth = Width * ((float)Color.A / 255);

            e.Graphics.FillRectangle(cpColorBrush, 0, 0, Width, Height - 3);
            e.Graphics.FillRectangle(cpAlphaBackBrush, 0, Height - 3, Width, 3);
            e.Graphics.FillRectangle(cpAlphaFrontBrush, 0, Height - 3, alphaWidth, 3);
            e.Graphics.DrawRectangle(cpBorderPen, 0, 0, Width, Height);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/Panel.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class Panel : ScrollableControl
    {
        public Panel()
        {
            SetStyle(ControlStyles.Selectable | ControlStyles.AllPaintingInWmPaint, false);
        }

        public virtual BorderStyle BorderStyle { get; set; }

        protected override Size DefaultSize
        {
            get { return new Size(200, 100); }
        }

        protected internal override void uwfOnLatePaint(PaintEventArgs e)
        {
            base.uwfOnLatePaint(e);

            ControlPaint.PrintBorder(e.Graphics, ClientRectangle, BorderStyle, Border3DStyle.Sunken);
        }
    }
}


<|start_filename|>Assets/System/Drawing/Graphics.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Drawing.API;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;

    using Unity.API; // TODO: remove

    public sealed class Graphics : IDeviceContext, IDisposable
    {
        internal static IApiGraphics ApiGraphics
        {
            get { return ApiHolder.Graphics; }
        }

        public void Clear(Color color)
        {
            ApiGraphics.Clear(color);
        }
        public void Dispose()
        {
        }
        public void DrawCurve(Pen pen, PointF[] points, int segments = 32) // very slow.
        {
            if (points == null || points.Length <= 1) return;
            if (points.Length == 2)
            {
                DrawLine(pen, points[0].X, points[0].Y, points[1].X, points[1].Y);
                return;
            }

            var bPoints = GetBezierApproximation(points, segments); // decrease segments for better fps.
            for (int i = 0; i + 1 < bPoints.Length; i++)
            {
                var p1 = bPoints[i];
                var p2 = bPoints[i + 1];
                DrawLine(pen, p1.X, p1.Y, p2.X, p2.Y);
            }
        }
        public void DrawImage(Image image, Rectangle rect)
        {
            DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
        }
        public void DrawImage(Image image, RectangleF rect)
        {
            DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
        }
        public void DrawImage(Image image, int x, int y, int width, int height)
        {
            DrawImage(image, (float)x, (float)y, (float)width, (float)height);
        }
        public void DrawImage(Image image, float x, float y, float width, float height)
        {
            ApiGraphics.DrawImage(image, x, y, width, height, 0);
        }
        public void DrawLine(Pen pen, Point pt1, Point pt2)
        {
            DrawLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y);
        }
        public void DrawLine(Pen pen, PointF pt1, PointF pt2)
        {
            DrawLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y);
        }
        public void DrawLine(Pen pen, int x1, int y1, int x2, int y2)
        {
            DrawLine(pen, (float)x1, (float)y1, (float)x2, (float)y2);
        }
        public void DrawLine(Pen pen, float x1, float y1, float x2, float y2)
        {
            ApiGraphics.DrawLine(pen, x1, y1, x2, y2);
        }
        public void DrawLines(Pen pen, PointF[] points)
        {
            for (int i = 0; i < points.Length - 1; i++)
                DrawLine(pen, points[i], points[i + 1]);
        }
        public void DrawLines(Pen pen, Point[] points)
        {
            for (int i = 0; i < points.Length - 1; i++)
                DrawLine(pen, points[i], points[i + 1]);
        }
        public void DrawPolygon(Pen pen, Point[] points)
        {
            ApiGraphics.DrawPolygon(pen, points);
        }
        public void DrawRectangle(Pen pen, Rectangle rect)
        {
            DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
        }
        public void DrawRectangle(Pen pen, int x, int y, int width, int height)
        {
            DrawRectangle(pen, (float)x, (float)y, (float)width, (float)height);
        }
        public void DrawRectangle(Pen pen, float x, float y, float width, float height)
        {
            ApiGraphics.DrawRectangle(pen, x, y, width, height);
        }
        public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle)
        {
            uwfDrawString(s, font, brush, layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height);
        }
        public void DrawString(string s, Font font, Brush brush, PointF point)
        {
            DrawString(s, font, brush, point.X, point.Y);
        }
        public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
        {
            uwfDrawString(s, font, brush, layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height, format);
        }
        public void DrawString(string s, Font font, Brush brush, PointF point, StringFormat format)
        {
            DrawString(s, font, brush, point.X, point.Y, format);
        }
        public void DrawString(string s, Font font, Brush brush, float x, float y)
        {
            uwfDrawString(s, font, brush, x, y, 512, 64);
        }
        public void DrawString(string s, Font font, Brush brush, float x, float y, StringFormat format)
        {
            uwfDrawString(s, font, brush, x, y, 512, 64, format);
        }
        public void FillEllipse(SolidBrush brush, float x, float y, float width, float height)
        {
            uwfDrawImage(ApplicationResources.Images.Circle, brush.Color, x, y, width, height);
        }
        public void FillRectangle(Brush brush, Rectangle rect)
        {
            FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
        }
        public void FillRectangle(Brush brush, RectangleF rect)
        {
            FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
        }
        public void FillRectangle(Brush brush, int x, int y, int width, int height)
        {
            ApiGraphics.FillRectangle(brush, x, y, width, height);
        }
        public void FillRectangle(Brush brush, float x, float y, float width, float height)
        {
            ApiGraphics.FillRectangle(brush, x, y, width, height);
        }
        public void FillRectangles(Brush brush, RectangleF[] rects)
        {
            for (int i = 0; i < rects.Length; i++)
            {
                var r = rects[i];
                FillRectangle(brush, r);
            }
        }
        public void FillRectangles(Brush brush, Rectangle[] rects)
        {
            for (int i = 0; i < rects.Length; i++)
            {
                var r = rects[i];
                FillRectangle(brush, r);
            }
        }
        public SizeF MeasureString(string text, Font font)
        {
            return ApiGraphics.MeasureString(text, font);
        }

        internal static PointF[] GetBezierApproximation(PointF[] controlPoints, int outputSegmentCount)
        {
            if (outputSegmentCount <= 0) 
                return new PointF[] {};
            
            var points = new PointF[outputSegmentCount + 1];
            for (int i = 0; i <= outputSegmentCount; i++)
            {
                float t = (float) i / outputSegmentCount;
                points[i] = GetBezierPoint(t, controlPoints, 0, controlPoints.Length);
            }
            
            return points;
        }
        internal void GroupBegin(Control control)
        {
            var co = control.uwfOffset;
            var x = control.Location.X + co.X;
            var y = control.Location.Y + co.Y;
            var w = control.ClientSize.Width;
            var h = control.ClientSize.Height;

            ApiGraphics.BeginGroup(x, y, w, h);
        }
        internal void GroupEnd()
        {
            ApiGraphics.EndGroup();
        }

        #region Not original methods.
        internal void uwfDrawImage(Image image, Color color, float x, float y, float width, float height)
        {
            image.Color = color;
            ApiGraphics.DrawImage(image, x, y, width, height, 0);
        }
        internal void uwfDrawLine(Color color, int width, DashStyle style, float x1, float y1, float x2, float y2)
        {
            ApiGraphics.DrawLine(color, width, style, x1, y1, x2, y2);
        }
        internal string uwfDrawPasswordField(string s, Font font, Color color, float x, float y, float width, float height, HorizontalAlignment alignment)
        {
            // TODO: textBox.UseSystemPasswordChar.
            var unityApi = ApiGraphics as UnityGdi;
            if (unityApi != null)
                return unityApi.uwfDrawPasswordField(s, font, color, x, y, width, height, alignment);
            
            throw new NotImplementedException("uwfDrawPasswordField");
        }
        internal void uwfDrawString(string s, Font font, Brush brush, float x, float y, float width, float height, ContentAlignment alignment)
        {
            var solidBrush = brush as SolidBrush;
            if (solidBrush == null) return;

            uwfDrawString(s, font, solidBrush.Color, x, y, width, height, alignment);
        }
        internal void uwfDrawString(string s, Font font, Color color, float x, float y, float width, float height, ContentAlignment alignment)
        {
            if (color.A <= 0) return;
            if (string.IsNullOrEmpty(s)) return;

            ApiGraphics.DrawString(s, font, color, x, y, width, height, alignment);
        }
        internal void uwfDrawString(string s, Font font, Color color, float x, float y)
        {
            uwfDrawString(s, font, color, x, y, 512, 64);
        }
        internal void uwfDrawString(string s, Font font, Brush brush, float x, float y, float width, float height)
        {
            uwfDrawString(s, font, brush, x, y, width, height, new StringFormat());
        }
        internal void uwfDrawString(string s, Font font, Color color, float x, float y, float width, float height)
        {
            uwfDrawString(s, font, color, x, y, width, height, ContentAlignment.BottomLeft);
        }
        internal void uwfDrawString(string s, Font font, Color color, float x, float y, float width, float height, HorizontalAlignment alignment)
        {
            ContentAlignment ca = ContentAlignment.MiddleLeft;
            if (alignment == HorizontalAlignment.Center)
                ca = ContentAlignment.MiddleCenter;
            else if (alignment == HorizontalAlignment.Right)
                ca = ContentAlignment.MiddleRight;
            uwfDrawString(s, font, color, x, y, width, height, ca);
        }
        internal void uwfDrawString(string s, Font font, Brush brush, float x, float y, float width, float height, HorizontalAlignment horizontalAlignment)
        {
            ContentAlignment alignment;
            switch (horizontalAlignment)
            {
                default:
                    alignment = ContentAlignment.MiddleLeft;
                    break;
                case HorizontalAlignment.Center:
                    alignment = ContentAlignment.MiddleCenter;
                    break;
                case HorizontalAlignment.Right:
                    alignment = ContentAlignment.MiddleRight;
                    break;
            }
            uwfDrawString(s, font, brush, x, y, width, height, alignment);
        }
        internal void uwfDrawString(string s, Font font, Brush brush, float x, float y, float width, float height, StringFormat format)
        {
            uwfDrawString(s, font, brush, x, y, width, height, format.ToContentAlignment());
        }
        internal string uwfDrawTextArea(string s, Font font, Color color, float x, float y, float width, float height)
        {
            // TODO: TextBoxBase
            var unityApi = ApiGraphics as UnityGdi;
            if (unityApi != null)
                return unityApi.uwfDrawTextArea(s, font, color, x, y, width, height);

            throw new NotImplementedException("uwfDrawTextArea");
        }
        internal string uwfDrawTextField(string s, Font font, Color color, float x, float y, float width, float height, HorizontalAlignment alignment)
        {
            // TODO: TextBoxBase
            var unityApi = ApiGraphics as UnityGdi;
            if (unityApi != null)
                return unityApi.uwfDrawTextField(s, font, color, x, y, width, height, alignment);
            
            throw new NotImplementedException("uwfDrawTextField");
        }
        internal string uwfDrawTextField(string s, Font font, SolidBrush brush, float x, float y, float width, float height, HorizontalAlignment alignment)
        {
            return uwfDrawTextField(s, font, brush.Color, x, y, width, height, alignment);
        }
        internal void uwfFillRectangle(Color color, Rectangle rect)
        {
            uwfFillRectangle(color, rect.X, rect.Y, rect.Width, rect.Height);
        }
        internal void uwfFillRectangle(Color color, float x, float y, float width, float height)
        {
            uwfFillRectangle(color, x, y, width, height, null);
        }
        internal void uwfFillRectangle(Color color, float x, float y, float width, float height, object material)
        {
            if (color.A <= 0) return;

            ApiGraphics.FillRectangle(color, x, y, width, height, material);
        }
        internal void uwfFocus()
        {
            ApiGraphics.Focus();
        }
        internal void uwfFocusNext()
        {
            ApiGraphics.FocusNext();
        }
        #endregion

        private static PointF GetBezierPoint(float t, PointF[] controlPoints, int index, int count)
        {
            if (count == 1)
                return controlPoints[index];
            var P0 = GetBezierPoint(t, controlPoints, index, count - 1);
            var P1 = GetBezierPoint(t, controlPoints, index + 1, count - 1);
            return new PointF((1 - t) * P0.X + t * P1.X, (1 - t) * P0.Y + t * P1.Y);
        }
    }
}


<|start_filename|>Assets/Unity/API/UnityInput.cs<|end_filename|>
﻿namespace Unity.API
{
    using System.Drawing.API;

    public class UnityInput : IApiInput
    {
        public bool CursorVisible
        {
            get { return UnityEngine.Cursor.visible; }
            set { UnityEngine.Cursor.visible = value; }
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/TreeViewEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class TreeViewEventArgs : EventArgs
    {
        public TreeViewEventArgs(TreeNode node)
        {
            Action = TreeViewAction.Unknown;
            Node = node;
        }
        public TreeViewEventArgs(TreeNode node, TreeViewAction action)
        {
            Action = action;
            Node = node;
        }

        public TreeViewAction Action { get; private set; }
        public TreeNode Node { get; private set; }
    }
}


<|start_filename|>Assets/Utility/ColorTranslatorEx.cs<|end_filename|>
﻿namespace System.Drawing
{
    public static class ColorTranslatorEx
    {
        public static Color Clamp(Color value, Color min, Color max)
        {
            value = Min(value, min);
            value = Max(value, max);

            return value;
        }
        
        public static Color FromHsb(byte hue, byte saturation, byte brightness)
        {
            double dh = (double)hue / 255;
            double ds = (double)saturation / 255;
            double db = (double)brightness / 255;
            return FromHsb(dh, ds, db);
        }
        
        public static Color FromHsb(double hue, double saturation, double brightness)
        {
            double r = 0, g = 0, b = 0;
            
            if (brightness != 0)
            {
                if (saturation == 0)
                {
                    r = g = b = brightness;
                }
                else
                {
                    double temp2 = GetTemp2(saturation, brightness);
                    double temp1 = 2.0f * brightness - temp2;

                    r = GetColorComponent(temp1, temp2, hue + 1.0f / 3.0f);
                    g = GetColorComponent(temp1, temp2, hue);
                    b = GetColorComponent(temp1, temp2, hue - 1.0f / 3.0f);
                }
            }

            return Color.FromArgb((int) (255 * r), (int) (255 * g), (int) (255 * b));
        }
        
        public static Color FromHSV(double hue, double saturation, double value)
        {
            int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
            double f = hue / 60 - Math.Floor(hue / 60);

            value = value * 255;
            int v = Convert.ToInt32(value);
            int p = Convert.ToInt32(value * (1 - saturation));
            int q = Convert.ToInt32(value * (1 - f * saturation));
            int t = Convert.ToInt32(value * (1 - (1 - f) * saturation));

            if (hi == 0)
                return Color.FromArgb(255, v, t, p);
            if (hi == 1)
                return Color.FromArgb(255, q, v, p);
            if (hi == 2)
                return Color.FromArgb(255, p, v, t);
            if (hi == 3)
                return Color.FromArgb(255, p, q, v);
            if (hi == 4)
                return Color.FromArgb(255, t, p, v);

            return Color.FromArgb(255, v, p, q);
        }
        
        public static Color Max(this Color value, Color maxValue)
        {
            var a = value.A;
            var r = value.R;
            var g = value.G;
            var b = value.B;

            var ma = maxValue.A;
            var mr = maxValue.R;
            var mg = maxValue.G;
            var mb = maxValue.B;

            if (a > ma) a = ma;
            if (r > mr) r = mr;
            if (g > mg) g = mg;
            if (b > mb) b = mb;

            return Color.FromArgb(a, r, g, b);
        }
        
        public static Color Min(this Color value, Color minValue)
        {
            var a = value.A;
            var r = value.R;
            var g = value.G;
            var b = value.B;

            var ma = minValue.A;
            var mr = minValue.R;
            var mg = minValue.G;
            var mb = minValue.B;

            if (a < ma) a = ma;
            if (r < mr) r = mr;
            if (g < mg) g = mg;
            if (b < mb) b = mb;

            return Color.FromArgb(a, r, g, b);
        }
        
        public static string ToHexString(this Color c)
        {
            return c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2") + c.A.ToString("X2");
        }
        
        public static void ToHSV(Color color, out double hue, out double saturation, out double value)
        {
            int max = Math.Max(color.R, Math.Max(color.G, color.B));
            int min = Math.Min(color.R, Math.Min(color.G, color.B));

            hue = color.GetHue();
            saturation = max == 0 ? 0 : 1d - (1d * min / max);
            value = max / 255d;
        }

        private static double GetColorComponent(double temp1, double temp2, double temp3)
        {
            temp3 = MoveIntoRange(temp3);
            
            if (temp3 < 1.0f / 6.0f)
                return temp1 + (temp2 - temp1) * 6.0f * temp3;
            
            if (temp3 < 0.5f)
                return temp2;
            
            if (temp3 < 2.0f / 3.0f)
                return temp1 + (temp2 - temp1) * (2.0f / 3.0f - temp3) * 6.0f;
            
            return temp1;
        }
        
        private static double GetTemp2(double s, double l)
        {
            double temp2;
            if (l < 0.5f)
                temp2 = l * (1.0f + s);
            else
                temp2 = l + s - l * s;
            return temp2;
        }
        
        private static double MoveIntoRange(double temp3)
        {
            if (temp3 < 0.0f)
                temp3 += 1.0f;
            else if (temp3 > 1.0f)
                temp3 -= 1.0f;
            
            return temp3;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/HScrollProperties.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class HScrollProperties : ScrollProperties
    {
        public HScrollProperties(ScrollableControl container) : base(container)
        {
        }

        internal override int PageSize
        {
            get { return ParentControl.ClientRectangle.Width; }
        }
        internal override int Orientation
        {
            get { return NativeMethods.SB_HORZ; }
        }
        internal override int HorizontalDisplayPosition
        {
            get { return -value; }
        }
        internal override int VerticalDisplayPosition
        {
            get { return ParentControl.DisplayRectangle.Y; }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/DateRangeEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class DateRangeEventArgs : EventArgs
    {
        public DateRangeEventArgs(DateTime start, DateTime end)
        {
            Start = start;
            End = end;
        }

        public DateTime End { get; private set; }
        public DateTime Start { get; private set; }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelDateTimePicker.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelDateTimePicker : BaseExamplePanel
    {
        public override void Initialize()
        {
            this.Create<DateTimePicker>();
        }
    }
}


<|start_filename|>Assets/Examples/Panels/BaseExamplePanel.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public abstract class BaseExamplePanel : Panel
    {
        protected int lineOffset = 36;

        protected BaseExamplePanel()
        {
            AutoScroll = true;
            BackColor = Color.FromArgb(239, 235, 233);
        }
        
        public abstract void Initialize();
    }
}


<|start_filename|>Assets/System/Windows/Forms/MdiClient.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections;
    using System.Drawing;

    public sealed class MdiClient : Control
    {
        private readonly ArrayList items = new ArrayList();

        public MdiClient()
        {
            Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            BackColor = SystemColors.AppWorkspace;
            SetStyle(ControlStyles.Selectable, false);
        }

        public Form[] MdiChildren
        {
            get
            {
                var temp = new Form[items.Count];
                items.CopyTo(temp, 0);
                return temp;
            }
        }

        protected override Control.ControlCollection CreateControlsInstance()
        {
            return new ControlCollection(this);
        }

        public new class ControlCollection : Control.ControlCollection
        {
            private readonly MdiClient owner;

            public ControlCollection(MdiClient owner) : base(owner)
            {
                this.owner = owner;
            }

            public override void Add(Control value)
            {
                if (value == null)
                    return;

                var form = value as Form;
                if (form == null || !form.IsMdiChild)
                    throw new ArgumentException("form");

                owner.items.Add(form);

                base.Add(value);
            }
            public override void Remove(Control item)
            {
                owner.items.Remove(item);

                base.Remove(item);
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripMenuItem.cs<|end_filename|>
namespace System.Windows.Forms
{
    using System.Collections.Generic;
    using System.Drawing;

    public class ToolStripMenuItem : ToolStripDropDownItem
    {
        internal int shortcutMarginLeft  = 14; // Space between item text and shortcut text.
        internal int shortcutMarginRight = 32;
        
        private static Dictionary<int, string> cachedKeysValues;
        private ContentAlignment shortcutKeysFormat = ContentAlignment.MiddleRight;

        private Keys shortcutKeys;
        private string shortcutKeysString;
        
        public ToolStripMenuItem()
        {
        }
        public ToolStripMenuItem(string text)
        {
            Text = text;
            TextAlign = ContentAlignment.MiddleCenter;
        }

        public bool Checked { get; set; }
        public Keys ShortcutKeys
        {
            get { return shortcutKeys; }
            set
            {
                if (shortcutKeys == value)
                    return;

                shortcutKeys = value;
                shortcutKeysString = ToShortcutString(value);
            }
        }

        protected override Size DefaultSize
        {
            get { return new Size(32, 19); }
        }
        protected override Padding DefaultPadding
        {
            get
            {
                if (IsOnDropDown)
                    return new Padding(0, 1, 0, 1);
                return new Padding(4, 0, 4, 0);
            }
        }

        protected internal override int GetEstimatedWidth(Graphics graphics)
        {
            var baseWidth = base.GetEstimatedWidth(graphics);
            if (Owner != null && Owner.IsDropDown)
                baseWidth += OwnerShortcutKeysWidth(graphics) + shortcutMarginLeft + shortcutMarginRight; // not efficient.
            return baseWidth;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var rect = Bounds;

            if (Checked)
            {
                var checkedRect = new Rectangle(rect.X + 1, rect.Y + rect.Height / 2 - 10, 20, 20);
                var graphics = e.Graphics;
                
                graphics.uwfFillRectangle(hoverColor, checkedRect);
                graphics.DrawRectangle(selectPen, checkedRect);

                var checkedImage = ApplicationResources.Images.Checked;
                if (checkedImage != null)
                {
                    var checkedImageRect = new Rectangle( // Draw without streching (override this if u need).
                        checkedRect.X + checkedRect.Width / 2 - checkedImage.Width / 2,
                        checkedRect.Y + checkedRect.Height / 2 - checkedImage.Height / 2,
                        checkedImage.Width,
                        checkedImage.Height);
                    graphics.uwfDrawImage(
                        checkedImage,
                        Color.FromArgb(64, 64,64),
                        checkedImageRect.X,
                        checkedImageRect.Y,
                        checkedImageRect.Width,
                        checkedImageRect.Height);
                }
            }

            if (!string.IsNullOrEmpty(shortcutKeysString))
            {
                if (Owner.Orientation == Orientation.Vertical)
                    e.Graphics.uwfDrawString(
                        shortcutKeysString,
                        Font,
                        Enabled ? ForeColor : SystemColors.InactiveCaption,
                        rect.X,
                        rect.Y,
                        rect.Width - shortcutMarginRight,
                        rect.Height,
                        shortcutKeysFormat);
            }
        }

        private static string GetCachedString(Keys key)
        {
            switch (key)
            {
                case Keys.Control: return "Ctrl";
                case Keys.Delete: return "Del";
                case Keys.Return: return "Enter";
                
                case Keys.Oemcomma: return ",";
            }
            
            if (cachedKeysValues == null)
            {
                // Fill cache.
                cachedKeysValues = new Dictionary<int, string>();
                string[] names;
                object[] values;

                GetEnumData(typeof(Keys), out names, out values);

                for (int i = 0; i < names.Length; i++)
                {
                    var val = (int)values[i];
                    if (cachedKeysValues.ContainsKey(val) == false)
                        cachedKeysValues.Add(val, names[i]);
                }
            }

            return cachedKeysValues[(int)key];
        }
        private static void GetEnumData(Type type, out string[] names, out object[] values)
        {
            // More efficient than Enum.GetNames(...).
            var fields = type.GetFields(
                Reflection.BindingFlags.Public |
                Reflection.BindingFlags.NonPublic |
                Reflection.BindingFlags.Static);

            var fieldsLength = fields.Length;

            names = new string[fieldsLength];
            values = new object[fieldsLength];

            for (int i = 0; i < fieldsLength; i++)
            {
                var field = fields[i];

                names[i] = field.Name;
                values[i] = field.GetRawConstantValue();
            }
        }
        private static Keys GetKeyCode(Keys keyData)
        {
            var keys = keyData & Keys.KeyCode;

            if (KeyEventArgs.IsKeyDefined(keys))
                return keys;

            return Keys.None;
        }
        private static string ToShortcutString(Keys key)
        {
            // TODO: move to KeysConverter.ConvertTo(object).
            var keyCode = GetKeyCode(key);
            var keyMods = key & Keys.Modifiers;
            var result = "";
            if (keyMods != Keys.None)
            {
                if ((keyMods & Keys.Control) != 0)
                    result += GetCachedString(Keys.Control) + "+";

                if ((keyMods & Keys.Alt) != 0)
                    result += GetCachedString(Keys.Alt) + "+";

                if ((keyMods & Keys.Shift) != 0)
                    result += GetCachedString(Keys.Shift) + "+";
            }

            return result + GetCachedString(keyCode);
        }

        private int OwnerShortcutKeysWidth(Graphics graphics)
        {
            var owner = Owner;
            if (owner == null)
                return 0;

            int keysWidth = 0;
            for (int i = 0; i < owner.Items.Count; i++)
            {
                var item = owner.Items[i];
                var menuItem = item as ToolStripMenuItem;
                if (menuItem == null)
                    continue;

                if (menuItem.shortcutKeys != Keys.None)
                    keysWidth = Math.Max((int)graphics.MeasureString(shortcutKeysString, Font).Width, keysWidth);
            }

            return keysWidth;
        }
    }
}

<|start_filename|>Assets/Controls/Highcharts/Legend.cs<|end_filename|>
﻿namespace Highcharts
{
    using System.Drawing;

    public enum LegendLayouts
    {
        horizontal,
        vertical
    }

    public class Legend
    {
        public Legend()
        {
            enabled = true;
            floating = false;
            itemDistance = 20;
            itemHiddenStyle = new LegendItemStyle(Color.FromArgb(0xCC, 0xCC, 0xCC));
            itemHoverStyle = new LegendItemStyle(Color.FromArgb(0x00, 0x00, 0x00));
            itemStyle = new LegendItemStyle(Color.FromArgb(0x33, 0x33, 0x33));
            layout = LegendLayouts.horizontal;
            margin = 12;
        }

        /// <summary>
        /// Enable or disable the legend.
        /// </summary>
        public bool enabled { get; set; }
        /// <summary>
        /// When the legend is floating, the plot area ignores it and is allowed to be placed below it. Defaults to false.
        /// </summary>
        public bool floating { get; set; }
        /// <summary>
        /// In a legend with horizontal layout, the itemDistance defines the pixel distance between each item. Defaults to 20.
        /// </summary>
        public int itemDistance { get; set; }
        public LegendItemStyle itemHiddenStyle { get; set; }
        public LegendItemStyle itemHoverStyle { get; set; }
        public LegendItemStyle itemStyle { get; set; }
        public LegendLayouts layout { get; set; }
        /// <summary>
        /// If the plot area sized is calculated automatically and the legend is not floating, the legend margin 
        /// is the space between the legend and the axis labels or plot area. Defaults to 12.
        /// </summary>
        public int margin { get; set; }
    }
}


<|start_filename|>Assets/System/Windows/Forms/TreeNodeMouseClickEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void TreeNodeMouseClickEventHandler(object sender, TreeNodeMouseClickEventArgs e);
}


<|start_filename|>Assets/Core/API/IApiTiming.cs<|end_filename|>
﻿namespace System.Drawing.API
{
    public interface IApiTiming
    {
        float DeltaTime { get; }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelTableView.cs<|end_filename|>
﻿using System.Drawing;

namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;
    
    public class PanelTableView : BaseExamplePanel
    {
        public override void Initialize()
        {
            // Empty table.
            this.Create<TableView>();
            
            var table = this.Create<TableView>(8, 158);
            table.Size = new Size(360, 240);
            table.Columns.Add("column1", "column1");
            table.Columns.Add("column2", "column2");
            table.Columns.Add("column3", "column3");
            table.Columns.Add("column4", "column4");
            table.Columns.Add("column5", "column5");

            for (int i = 0; i < 20; i++)
                table.Rows.Add();

            var combo = new ComboBox();
            combo.DropDownStyle = ComboBoxStyle.DropDownList;
            combo.Items.AddRange(new object[] { "1", "2", "3" });
            
            var label = new Label();
            label.Text = "label1";
            
            var buttonHideRowsButtons = new Button();
            buttonHideRowsButtons.Text = "Hide rows buttons";
            buttonHideRowsButtons.Click += (sender, args) =>
            {
                // TODO: don't know why, but columns headers becomes hidden aswell.
                table.HideRowHeaders();
                table.Refresh();
            };
            
            // Set a new control for table cell.
            table.Rows[1].ItemsControls[0] = combo;
            table.Rows[1].ItemsControls[1] = label;
            table.Rows[2].ItemsControls[0] = buttonHideRowsButtons;

            table.Columns[0].Width = 128;
            table.Refresh();
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/GroupBox.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class GroupBox : Control
    {
        private readonly Pen borderPen = new Pen(Color.LightGray);
        private int borderMarginTop;
        private int textLeftOffset = 8;
        private int textHeight;
        private int textWidth;
        private bool textUpdateSize;
        
        public GroupBox()
        {
            TabIndex = -1;

            SetStyle(ControlStyles.Selectable, false);
        }

        internal Color uwfBorderColor
        {
            get { return borderPen.Color; }
            set { borderPen.Color = value; }
        }

        protected override Size DefaultSize
        {
            get { return new Size(200, 100); }
        }

        protected internal override void uwfOnLatePaint(PaintEventArgs e)
        {
            base.uwfOnLatePaint(e);

            var g = e.Graphics;

            var text = Text;
            if (textUpdateSize)
            {
                var size = g.MeasureString(text, Font);
                textHeight = (int)size.Height;
                textWidth = (int)size.Width + 2;
                textUpdateSize = false;
                borderMarginTop = textHeight / 2 - 2;
            }
            
            if (!string.IsNullOrEmpty(text))
            {
                // We can draw 5 lines or fill rect with back color (batches vs fillrate).
                g.DrawLine(borderPen, 0, borderMarginTop, 0, Height - 1); // Left.
                g.DrawLine(borderPen, Width - 1, borderMarginTop, Width - 1, Height - 1); // Right.
                g.DrawLine(borderPen, 0, Height - 1, Width - 1, Height - 1); // Bottom.
                g.DrawLine(borderPen, 0, borderMarginTop, textLeftOffset, borderMarginTop); // Top left.
                g.DrawLine(borderPen, textLeftOffset + textWidth, borderMarginTop, Width - 1, borderMarginTop); // Top right.
                g.uwfDrawString(text, Font, ForeColor, textLeftOffset, -2, Width - textLeftOffset * 2, 22, ContentAlignment.TopLeft);
            }
            else
                g.DrawRectangle(borderPen, 0, borderMarginTop, Width, Height - borderMarginTop);
        }

        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            textUpdateSize = true;
        }
    }
}


<|start_filename|>Assets/Controls/Highcharts/SeriesLineSolid.cs<|end_filename|>
namespace Highcharts
{
    using System.Drawing;
    
    public class SeriesLineSolid : Series
    {
        private readonly Pen iconPen = new Pen(Color.Black, 2);
        
        public SeriesLineSolid() : this("") 
        { }

        public SeriesLineSolid(string name) : base(name)
        { }

        protected override void OnPaint(Graphics g, Rectangle clipRectangle)
        {
            if (data.Count == 1)
            {
                SeriesPaint.PaintPoint(this, g, clipRectangle, 0);
                return;
            }
            
            var valueRange = GetValueRange();
            var xStep = GetXStep();
            
            var prevValue = data[0];
            var prevValueX = GetXFromIndex(0, xStep, clipRectangle);
            var prevValueY = GetYFromValue(prevValue, valueRange, clipRectangle);
            
            for (float dataIterator = pointInterval; dataIterator < data.Count; dataIterator += pointInterval)
            {
                int dataIndex = (int) dataIterator;
                 
                double currentValue = data[dataIndex];

                float currentValueX = GetXFromIndex(dataIndex, xStep, clipRectangle);
                float currentValueY = GetYFromValue(currentValue, valueRange, clipRectangle);

                g.DrawLine(pen, prevValueX, prevValueY, currentValueX + 1, prevValueY);
                g.DrawLine(pen, currentValueX, prevValueY, currentValueX, currentValueY);

                prevValueX = currentValueX;
                prevValueY = currentValueY;
                
                SeriesPaint.PaintHoveredValueRect(this, g, currentValueX, currentValueY, xStep);
            }
        }
        
        protected override void OnPaintIcon(Graphics g, Rectangle clipRectangle)
        {
            iconPen.Color = color;
            
            g.DrawLine(iconPen, clipRectangle.Left, clipRectangle.Top + 11, clipRectangle.Left + 16,  clipRectangle.Top + 11);
        }
    }
}

<|start_filename|>Assets/Unity/API/UnityTiming.cs<|end_filename|>
﻿namespace Unity.API
{
    using System.Drawing.API;

    public class UnityTiming : IApiTiming
    {
        public float DeltaTime { get { return UnityEngine.Time.deltaTime; } }
    }
}


<|start_filename|>Assets/System/Drawing/SolidBrush.cs<|end_filename|>
﻿namespace System.Drawing
{
    public sealed class SolidBrush : Brush
    {
        public SolidBrush(Color color)
        {
            Color = color;
        }

        public Color Color { get; set; }

        public override object Clone()
        {
            return new SolidBrush(Color);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripDropDownMenu.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class ToolStripDropDownMenu : ToolStripDropDown
    {
        ////private static Padding arrowPadding = new Padding(0, 0, 8, 0);
        ////private static Padding checkPadding = new Padding(5, 2, 2, 2);
        ////private static Padding imagePadding = new Padding(2);
        private static Padding textPadding = new Padding(8, 1, 9, 1);

        ////private Rectangle arrowRectangle = Rectangle.Empty;
        ////private Rectangle checkRectangle = Rectangle.Empty;
        private Rectangle imageMarginBounds = Rectangle.Empty;
        ////private Rectangle imageRectangle = Rectangle.Empty;
        ////private Rectangle textRectangle = Rectangle.Empty;

        public ToolStripDropDownMenu()
        {
            ShowImageMargin = true;

            uwfContext = true;
            uwfShadowBox = true;
        }

        public bool ShowCheckMargin { get; set; } // TODO: here.
        public bool ShowImageMargin { get; set; } // TOOD: here.

        internal Rectangle ImageMargin
        {
            get
            {
                imageMarginBounds.Height = this.Height;
                return imageMarginBounds;
            }
        }

        protected override Padding DefaultPadding
        {
            get
            {
                var tLeft = textPadding.Left;
                var padding = ShowCheckMargin || ShowImageMargin ? tLeft + ImageMargin.Width : tLeft;
                return new Padding(padding, 2, 1, 2);
            }
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            CalculateInternalLayoutMetrics();
        }

        private void CalculateInternalLayoutMetrics()
        {
            imageMarginBounds = new Rectangle(0, 0, 25, Height);

            Padding = DefaultPadding;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/BorderStyle.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum BorderStyle
    {
        None,
        FixedSingle,
        Fixed3D,
    }
}


<|start_filename|>Assets/System/Windows/Forms/MouseEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void MouseEventHandler(object sender, MouseEventArgs e);
}


<|start_filename|>Assets/System/Windows/Forms/Button.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    [Serializable]
    public class Button : ButtonBase, IButtonControl
    {
        public Button()
        {
            SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
        }

        public virtual DialogResult DialogResult { get; set; }

        public void NotifyDefault(bool value)
        {
            // ?
        }
        public void PerformClick()
        {
            OnClick(EventArgs.Empty);
        }
        public override string ToString()
        {
            return base.ToString() + ", Text: " + Text;
        }

        protected override void OnClick(EventArgs e)
        {
            var form = FindFormInternal();
            if (form != null)
                form.DialogResult = DialogResult;

            base.OnClick(e);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/TreeNodeMouseClickEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class TreeNodeMouseClickEventArgs : MouseEventArgs
    {
        public TreeNodeMouseClickEventArgs(TreeNode node, MouseButtons button, int clicks, int x, int y) : base(button, clicks, x, y, 0)
        {
            Node = node;
        }

        public TreeNode Node { get; private set; }
    }
}


<|start_filename|>Assets/System/Windows/Forms/KeyPressEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class KeyPressEventArgs : EventArgs
    {
        public char KeyChar { get; set; }
        public bool Handled { get; set; }

        public KeyPressEventArgs(char keyChar)
        {
            KeyChar = keyChar;
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelColorPicker.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Drawing;
    using System.Windows.Forms;
    
    public class PanelColorPicker : BaseExamplePanel
    {
        public override void Initialize()
        {
            var picker = this.Create<ColorPicker>();
            picker.Color = Color.FromArgb(64, Color.LightGreen);
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/TextBoxBase.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;

    [Obsolete("WIP")]
    public class TextBoxBase : Control
    {
        internal readonly TextCursor cursor;

        /*
         * --------------------line start |
         * -----top offset                |
         *   text                         | item height
         * -----bottom offset             |
         * --------------------line end   |
         */
        internal int itemHeight = 16;
        internal int itemTextBottomOffset = 4;
        internal int itemTextTopOffset = 2;
        internal char[] nextWordStopAtChars = { ' ' }; // Characters that will prevent moving cursor with Ctrl + Arrows.

        private readonly Pen cursorPen = new Pen(Color.Black);
        private readonly SolidBrush backBrush = new SolidBrush(Color.Transparent);
        private readonly SolidBrush textBrush = new SolidBrush(Color.Black);

        private ScrollBar vscroll;
        private Color selectionColor = Color.FromArgb(173, 214, 255);
        private int selectionStart;
        private int selectionLength;
        private int selectionLine;
        private int selectionRx1, selectionRx2;
        private List<string> lines = new List<string>();

        public TextBoxBase()
        {
            BackColor = Color.FromArgb(245, 245, 245);

            cursor = new TextCursor(this);
            cursor.ResetCursorPaintMode();

            vscroll = new VScrollBar();
            vscroll.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            vscroll.Location = new Point(Width - vscroll.Width, 0);
            vscroll.Height = Height;

            Controls.Add(vscroll);
        }

        public override Color BackColor
        {
            get { return backBrush.Color; }
            set { backBrush.Color = value; }
        }
        public override Color ForeColor
        {
            get { return textBrush.Color; }
            set { textBrush.Color = value; }
        }
        public override string Text
        {
            get
            {
                var builder = new StringBuilder();
                for (int i = 0; i < lines.Count; i++)
                    builder.Append(lines[i] + Environment.NewLine);
                return builder.ToString();
            }
            set
            {
                lines = new List<string>();
                if (string.IsNullOrEmpty(value))
                {
                    this.lines.Add(string.Empty);
                    return;
                }
                var vlines = value.Replace("\r", "").Split('\n');
                lines.AddRange(vlines);

                PerformLayout();
            }
        }

        protected internal virtual void OnPaintCursor(PaintEventArgs e)
        {
            var itemTextHeight = itemHeight + itemTextTopOffset + itemTextBottomOffset;

            // Paint cursor.
            if (Focused && cursor.renderMode)
            {
                cursorPen.Color = ForeColor;
                var cursorRenderY = GetLineRenderY(cursor.y);
                e.Graphics.DrawLine(cursorPen, cursor.renderX, cursorRenderY, cursor.renderX, cursorRenderY + itemHeight - itemTextTopOffset);
            }
        }

        protected override void OnGotFocus(EventArgs e)
        {
            cursor.ResetCursorPaintMode();

            base.OnGotFocus(e);
        }
        protected override void OnLayout(LayoutEventArgs e)
        {
            base.OnLayout(e);

            UpdateScrolls();
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            var keyCode = e.KeyCode;
            var ctrlMod = e.Control;
            var shiftMod = e.Shift;
            switch (keyCode)
            {
                // Basic navigation.
                case Keys.Down: CursorMoveDown(ctrlMod, shiftMod); return;
                case Keys.Left: CursorMoveLeft(ctrlMod, shiftMod); return;
                case Keys.Right: CursorMoveRight(ctrlMod, shiftMod); return;
                case Keys.Up: CursorMoveUp(ctrlMod, shiftMod); return;

                case Keys.End: cursor.MoveToLineEnd(); return;
                case Keys.Home: cursor.MoveToLineStart(); return;

                case Keys.Back: CursorRemoveTextToLeft(); return;
                case Keys.Delete: CursorRemoveTextToRight(); return;
                case Keys.Enter:
                    lines.Insert(cursor.y + 1, "");
                    cursor.MoveDown();
                    return;
            }

            var lastChar = KeyHelper.GetLastInputChar();

            CursorInsertText(lastChar.ToString());
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            CursorSetAt(e.X, e.Y);
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (e.Button == MouseButtons.Right)
            {
                var itemCut = new ToolStripMenuItem("Cut");
                itemCut.Enabled = false;

                var itemCopy = new ToolStripMenuItem("Copy");
                itemCopy.Enabled = false;

                var itemPaste = new ToolStripMenuItem("Paste");
                itemPaste.Enabled = false;

                var context = new ContextMenuStrip();

                context.Items.Add(itemCut);
                context.Items.Add(itemCopy);
                context.Items.Add(itemPaste);

                context.Show(this, e.Location);
            }
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            vscroll.Value -= e.Delta * 2;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;
            var height = Height;
            var width = Width;
            var itemTextHeight = itemHeight + itemTextTopOffset + itemTextBottomOffset;

            g.FillRectangle(backBrush, 0, 0, width, height);

            // Selection.
            if (selectionLength != 0)
            {
                selectionRx1 = (int)g.MeasureString(SubstringSafe(lines[selectionLine], 0, selectionStart), Font).Width;
                selectionRx2 = (int)g.MeasureString(SubstringSafe(lines[selectionLine], 0, selectionStart + selectionLength), Font).Width;
                g.uwfFillRectangle(selectionColor, selectionRx1, GetLineRenderY(selectionLine), selectionRx2 - selectionRx1, itemTextHeight - itemTextBottomOffset);
            }

            // Cursor.
            cursor.UpdateCursorPaintMode();
            cursor.UpdateRenderLocation(g);

            OnPaintCursor(e);

            // Text.
            var scrollIndex = vscroll.Value;
            var startLineIndex = scrollIndex / itemHeight - 1;
            var endLineIndex = (scrollIndex + vscroll.LargeChange) / itemHeight + 1;

            if (startLineIndex < 0) startLineIndex = 0;

            for (int i = startLineIndex; i < lines.Count && i <= endLineIndex; i++)
                g.uwfDrawString(lines[i], Font, textBrush, 0, GetLineRenderY(i), Width, itemTextHeight);
        }

        private static string SubstringSafe(string s, int start, int length)
        {
            if (start + length > s.Length)
                length = s.Length - start;

            return s.Substring(start, length);
        }

        private int GetLineRenderY(int line)
        {
            return line * itemHeight - itemTextBottomOffset - vscroll.Value;// * vscroll.SmallChange;
        }
        private void CursorEnsureVisible()
        {
            var cursorRx = cursor.y * itemHeight;
            if (cursorRx < vscroll.Value) // To top.
            {
                vscroll.Value = cursorRx;
                return;
            }

            if (cursorRx + vscroll.SmallChange > vscroll.Value + vscroll.LargeChange) // To bottom.
                vscroll.Value = cursorRx - vscroll.LargeChange + vscroll.SmallChange;
        }
        private void CursorInsertText(string value, bool moveCursor = true)
        {
            lines[cursor.y] = lines[cursor.Y].Insert(cursor.x, value);

            if (moveCursor)
            {
                cursor.x += value.Length;
                cursor.renderXRecalculate = true;
                cursor.ResetCursorPaintMode();
            }
        }
        private void CursorMoveDown(bool ctrlMod, bool shiftMod)
        {
            if (ctrlMod)
            {
                vscroll.Value += vscroll.SmallChange;
                return;
            }

            if (shiftMod)
            {
            }
            else
                ResetSelection();

            cursor.MoveDown();
            CursorEnsureVisible();
        }
        private void CursorMoveLeft(bool ctrlMod, bool shiftMod)
        {
            var amount = 1;
            if (ctrlMod)
            {
                var str = lines[cursor.y].Substring(0, cursor.x).TrimEnd(' ');
                for (int i = str.Length - 1; i >= 0; i--, amount++)
                    if (nextWordStopAtChars.Contains(str[i]))
                        break;
            }

            if (shiftMod)
            {
                if (selectionLength == 0)
                {
                    selectionStart = cursor.x;
                    selectionLine = cursor.y;
                }

                selectionLength -= amount;
            }
            else
                ResetSelection();

            cursor.MoveLeft(amount);
            CursorEnsureVisible();
        }
        private void CursorMoveRight(bool ctrlMod, bool shiftMod)
        {
            var amount = 1;
            if (ctrlMod)
            {
                var str = lines[cursor.y].Substring(cursor.x).TrimStart(' ');
                for (int i = 0; i < str.Length; i++, amount++)
                    if (nextWordStopAtChars.Contains(str[i]))
                        break;
            }

            if (shiftMod) // Add chars to select.
            {
                if (selectionLength == 0)
                {
                    selectionStart = cursor.x;
                    selectionLine = cursor.y;
                }

                selectionLength += amount;
            }
            else
                ResetSelection();

            cursor.MoveRight(amount);
            CursorEnsureVisible();
        }
        private void CursorMoveUp(bool ctrlMod, bool shiftMod)
        {
            if (ctrlMod)
            {
                vscroll.Value -= vscroll.SmallChange;
                return;
            }

            if (shiftMod)
            {
            }
            else
                ResetSelection();

            cursor.MoveUp();
            CursorEnsureVisible();
        }
        private void CursorRemoveTextToLeft(int amount = 1) // default 'Backspace' action.
        {
            if (cursor.x < amount)
                amount = cursor.x;

            if (amount == 0)
            {
                // Remove line.
                if (cursor.y > 0)
                {
                    var str = lines[cursor.y];

                    lines.RemoveAt(cursor.Y);
                    cursor.MoveLeft();
                    CursorInsertText(str, false);
                }
                return;
            }

            lines[cursor.Y] = lines[cursor.y].Remove(cursor.x - amount, amount);

            cursor.x -= amount;
            cursor.renderXRecalculate = true;
            cursor.ResetCursorPaintMode();
        }
        private void CursorRemoveTextToRight(int amount = 1) // default 'Delete' action.
        {
            var line = lines[cursor.y];
            if (cursor.x >= line.Length)
            {
                // Copy next line and concat to current one.
                if (cursor.y + 1 < lines.Count)
                {
                    lines[cursor.y] = line + lines[cursor.y + 1];
                    lines.RemoveAt(cursor.y + 1);
                }

                return;
            }

            lines[cursor.y] = line.Remove(cursor.x, amount);
        }
        private void CursorSetAt(int renderX, int renderY)
        {
            ResetSelection();

            cursor.y = (vscroll.Value + renderY) / itemHeight;

            cursor.renderXRecalculate = true;
            cursor.FixLocation();
            cursor.ResetCursorPaintMode();
            cursor.ResolveRenderLocation(renderX);
        }
        private void ResetSelection()
        {
            selectionLength = 0;
        }
        private void UpdateScrolls()
        {
            vscroll.Maximum = itemHeight * lines.Count;
            vscroll.LargeChange = Height;
            vscroll.SmallChange = itemHeight;
        }

        internal class TextCursor
        {
            public bool renderMode;
            public float renderWaitTime = 1f;
            public float renderWaitTimeCurrent;
            public int renderX;
            public bool renderXRecalculate = true;

            internal int x;
            internal int y;

            private readonly TextBoxBase owner;

            private bool resolveX;
            private int resolveXAt;

            public TextCursor(TextBoxBase owner)
            {
                this.owner = owner;
            }

            public int X
            {
                get { return x; }
                set
                {
                    if (x == value)
                        return;
                    x = value;
                    renderXRecalculate = true;
                }
            }
            public int Y
            {
                get { return y; }
                set { y = value; }
            }

            public void FixLocation()
            {
                var checkBotttom = y < owner.lines.Count;
                if (checkBotttom == false)
                    Y = owner.lines.Count - 1;

                var checkTop = y >= 0;
                if (checkTop == false)
                    Y = 0;

                var line = owner.lines[y];

                var checkRight = x < line.Length + 1;
                if (checkRight == false)
                    X = line.Length;

                var checkLeft = x >= 0;
                if (checkLeft == false)
                    X = 0;
            }
            public void MoveDown(int amount = 1)
            {
                y += amount;

                FixLocation();
                ResetCursorPaintMode();
            }
            public void MoveLeft(int amount = 1)
            {
                x -= amount;
                if (x < 0 && y > 0)
                {
                    // Move up.
                    y--;
                    MoveToLineEnd();
                }

                renderXRecalculate = true;
                FixLocation();
                ResetCursorPaintMode();
            }
            public void MoveRight(int amount = 1)
            {
                var nx = amount + x;
                var line = owner.lines[y];
                if (nx >= line.Length + 1) // Try move to next line.
                {
                    if (y + 1 < owner.lines.Count)
                    {
                        MoveToLineStart();
                        MoveDown();
                    }
                }
                else
                {
                    x = nx;
                    renderXRecalculate = true;
                    FixLocation();
                    ResetCursorPaintMode();
                }
            }
            public void MoveUp(int amount = 1)
            {
                y -= amount;

                FixLocation();
                ResetCursorPaintMode();
            }
            public void MoveToLineEnd()
            {
                var estIndex = owner.lines[y].Length;
                if (x == estIndex)
                    return;

                x = estIndex;
                renderXRecalculate = true;
                ResetCursorPaintMode();
            }
            public void MoveToLineStart()
            {
                if (x == 0)
                    return;

                x = 0;
                renderXRecalculate = true;
                ResetCursorPaintMode();
            }
            public void ResetCursorPaintMode()
            {
                renderWaitTimeCurrent = 0;
                renderMode = false;
            }
            public void ResolveRenderLocation(int rx)
            {
                resolveX = true;
                resolveXAt = rx;
            }
            public void Set(int nx, int ny)
            {
                X = nx;
                Y = ny;
            }
            public void UpdateCursorPaintMode()
            {
                renderWaitTimeCurrent -= swfHelper.GetDeltaTime();
                if (!(renderWaitTimeCurrent <= 0)) return;

                renderMode = !renderMode;
                renderWaitTimeCurrent = renderWaitTime;
            }
            public void UpdateRenderLocation(Graphics g)
            {
                if (resolveX)
                {
                    var line = owner.lines[y];
                    var charAt = line.Length;
                    for (int i = 0; i < line.Length; i++)
                    {
                        var str = line.Substring(0, i);
                        var textSize = g.MeasureString(str, owner.Font);
                        if (resolveXAt > textSize.Width - 1)
                            continue;

                        charAt = i - 1;
                        break;
                    }

                    if (charAt < 0)
                        charAt = 0;

                    x = charAt;
                    renderXRecalculate = true;
                    resolveX = false;
                    FixLocation();
                }

                if (renderXRecalculate == false)
                    return;

                if (x == 0)
                {
                    renderX = 0;
                    renderXRecalculate = false;
                }
                else
                {
                    var line = owner.lines[y];
                    var cursorText = line.Substring(0, x);
                    var textSize = g.MeasureString(cursorText, owner.Font);
                    renderX = (int)textSize.Width;
                    renderXRecalculate = false;
                }
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ListControl.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public abstract class ListControl : Control
    {
        public event EventHandler SelectedValueChanged;

        public abstract int SelectedIndex { get; set; }
        public object SelectedValue { get; set; }

        protected virtual void OnSelectedIndexChanged(EventArgs e)
        {
            OnSelectedValueChanged(EventArgs.Empty);    
        }
        protected virtual void OnSelectedValueChanged(EventArgs e)
        {
            var handler = SelectedValueChanged;
            if (handler != null)
                handler(this, e);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/KeyEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class KeyEventArgs : EventArgs
    {
        private static object[] keyValuesRaw;

        private readonly Keys keyData;
        private Keys keyCode;
        private bool keyCodeCached;
        private bool suppressKeyPress;

        public KeyEventArgs(Keys keyData)
        {
            this.keyData = keyData;
        }
        internal KeyEventArgs()
        {

        }

        public virtual bool Alt
        {
            get { return (keyData & Keys.Alt) == Keys.Alt; }
        }
        public bool Control
        {
            get { return (keyData & Keys.Control) == Keys.Control; }
        }
        public bool Handled { get; set; }
        public Keys KeyCode
        {
            get
            {
                if (!keyCodeCached)
                {
                    var keys = keyData & Keys.KeyCode;
                    keyCode = !IsKeyDefined(keys) ? Keys.None : keys;
                    keyCodeCached = true;
                }

                return keyCode;
            }
        }
        public int KeyValue
        {
            get { return (int)(keyData & Keys.KeyCode); }
        }
        public Keys KeyData
        {
            get { return keyData; }
        }
        public Keys Modifiers
        {
            get { return keyData & Keys.Modifiers; }
        }
        public virtual bool Shift
        {
            get { return (keyData & Keys.Shift) == Keys.Shift; }
        }
        public bool SuppressKeyPress
        {
            get { return suppressKeyPress; }
            set
            {
                suppressKeyPress = value;
                Handled = value;
            }
        }

        // Less allocation, will only work with integer types, like typeof(Keys).
        internal static bool IsKeyDefined(Keys value)
        {
            if (keyValuesRaw == null)
            {
                var fields = typeof(Keys).GetFields(
                    Reflection.BindingFlags.Public |
                    Reflection.BindingFlags.NonPublic |
                    Reflection.BindingFlags.Static);

                keyValuesRaw = new object[fields.Length];
                for (int i = 0; i < fields.Length; i++)
                    keyValuesRaw[i] = fields[i].GetRawConstantValue();
            }

            var keyValuesRawLength = keyValuesRaw.Length;
            for (int i = 0; i < keyValuesRawLength; i++)
                if ((Keys)keyValuesRaw[i] == value)
                    return true;
            
            return false;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/DrawTreeNodeEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class DrawTreeNodeEventArgs : EventArgs
    {
        public DrawTreeNodeEventArgs(Graphics graphics, TreeNode node, Rectangle bounds, TreeNodeStates state)
        {
            Graphics = graphics;
            Node = node;
            Bounds = bounds;
            State = state;
        }

        public Rectangle Bounds { get; internal set; }
        public bool DrawDefault { get; internal set; }
        public Graphics Graphics { get; internal set; }
        public TreeNode Node { get; internal set; }
        public TreeNodeStates State { get; internal set; }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ScrollProperties.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    /*
     * I don't really know how this class supposed to be used with a ScrollableControl,
     * especially when you have 'scrollableControl.AutoScroll = true'. It's like doing nothing.
     * So, most of the logic will be held inside a ScrollableControl.
     */

    public abstract class ScrollProperties
    {
        internal int minimum = 0;
        internal int maximum = 100;
        internal bool maximumSetExternally;
        internal int largeChange = 10;
        internal bool largeChangeSetExternally;
        internal int smallChange = 1;
        internal bool smallChangeSetExternally;
        internal int value = 0;
        internal bool visible = false;

        private readonly ScrollableControl parent;
        private bool enabled = true;

        protected ScrollProperties(ScrollableControl container)
        {
            parent = container;
        }

        public bool Enabled
        {
            get { return enabled; }
            set
            {
                if (parent.AutoScroll)
                    return;

                if (value == enabled) return;

                enabled = value;
                EnableScroll(value);
            }
        }
        public int LargeChange
        {
            get { return Math.Min(largeChange, maximum - minimum + 1); }
            set
            {
                if (largeChange == value)
                    return;

                if (value < 0)
                    throw new ArgumentOutOfRangeException("value");

                largeChange = value;
                largeChangeSetExternally = true;
                UpdateScrollInfo();
            }
        }
        public int Maximum
        {
            get { return maximum; }
            set
            {
                if (parent.AutoScroll)
                    return;

                if (maximum == value)
                    return;

                if (minimum > value)
                    minimum = value;

                if (value < this.value)
                    Value = value;

                maximumSetExternally = true;
                UpdateScrollInfo();
            }
        }
        public int Minimum
        {
            get { return minimum; }
            set
            {
                if (parent.AutoScroll)
                    return;

                if (minimum == value)
                    return;

                if (value < 0)
                    throw new ArgumentOutOfRangeException("value");

                if (maximum < value)
                    maximum = value;

                if (value > this.value)
                    this.value = value;

                minimum = value;
                UpdateScrollInfo();
            }
        }
        public int SmallChange
        {
            get { return Math.Min(smallChange, LargeChange); }
            set
            {
                if (smallChange == value)
                    return;

                if (value < 0)
                    throw new ArgumentOutOfRangeException("value");

                smallChange = value;
                smallChangeSetExternally = true;
                UpdateScrollInfo();
            }
        }
        public int Value
        {
            get { return value; }
            set
            {
                if (this.value == value)
                    return;

                if (value < minimum || value > maximum)
                    throw new ArgumentOutOfRangeException("value");

                this.value = value;
                UpdateScrollInfo();
            }
        }
        public bool Visible
        {
            get { return visible; }
            set
            {
                if (parent.AutoScroll)
                    return;

                if (visible == value)
                    return;

                visible = value;
                UpdateScrollInfo();
            }
        }

        internal abstract int PageSize
        {
            get;
        }
        internal abstract int Orientation
        {
            get;
        }
        internal abstract int HorizontalDisplayPosition
        {
            get;
        }
        internal abstract int VerticalDisplayPosition
        {
            get;
        }

        protected ScrollableControl ParentControl
        {
            get { return parent; }
        }
        
        internal void UpdateScrollInfo()
        {
            var scrollbar = ParentControl.GetScrollBar(Orientation);
            if (scrollbar == null)
                return;

            scrollbar.Minimum = minimum;
            scrollbar.Maximum = maximum;
            scrollbar.SmallChange = smallChange;
            scrollbar.LargeChange = parent.AutoScroll ? PageSize : LargeChange;
        }

        private void EnableScroll(bool enable)
        {
            ParentControl.Native_EnableScrollBar(enable, Orientation);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/WindowsFormsUtils.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    internal sealed class WindowsFormsUtils
    {
        public static bool ContainsMnemonic(string text)
        {
            if (text == null)
                return false;

            int length = text.Length;
            int firstAmpersand = text.IndexOf('&', 0);
            if (firstAmpersand < 0 || firstAmpersand > length - 2)
                return false;

            return text.IndexOf('&', firstAmpersand + 1) == -1;
        }
        public static int RotateLeft(int value, int nBits) {
            nBits = nBits % 32;
            return value << nBits | (value >> (32 - nBits));
        }
        public static bool SafeCompareStrings(string string1, string string2, bool ignoreCase)
        {
            return string1 != null && string2 != null && string1.Length == string2.Length && string.Compare(string1, string2, ignoreCase) == 0;
        }
        
        internal static Rectangle ConstrainToBounds(Rectangle constrainingBounds, Rectangle bounds)
        {
            if (constrainingBounds.Contains(bounds)) return bounds;

            bounds.Size = new Size(
                Math.Min(constrainingBounds.Width - 2, bounds.Width),
                Math.Min(constrainingBounds.Height - 2, bounds.Height));
                
            if (bounds.Right > constrainingBounds.Right)
                bounds.X = constrainingBounds.Right - bounds.Width;
            else if (bounds.Left < constrainingBounds.Left)
                bounds.X = constrainingBounds.Left;

            if (bounds.Bottom > constrainingBounds.Bottom)
                bounds.Y = constrainingBounds.Bottom - 1 - bounds.Height;
            else if (bounds.Top < constrainingBounds.Top)
                bounds.Y = constrainingBounds.Top;
            return bounds;
        }

        internal class ReadOnlyControlCollection : Control.ControlCollection
        {
            private readonly bool _isReadOnly;
            
            public ReadOnlyControlCollection(Control owner, bool isReadOnly) : base(owner)
            {
                _isReadOnly = isReadOnly;
            }

            public override bool IsReadOnly
            {
                get { return _isReadOnly; }
            }

            public override void Add(Control value)
            {
                if (IsReadOnly)
                    throw new NotSupportedException("readonly collection");

                AddInternal(value);
            }
            public override void Clear()
            {
                if (IsReadOnly)
                    throw new NotSupportedException("readonly collection");

                base.Clear();
            }
            public override void RemoveByKey(string key)
            {
                if (IsReadOnly)
                    throw new NotSupportedException("readonly collection");

                base.RemoveByKey(key);
            }

            internal virtual void AddInternal(Control value)
            {
                base.Add(value);
            }
            internal virtual void RemoveInternal(Control value)
            {
                Remove(value);
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/FontDialog.cs<|end_filename|>
﻿using System.Globalization;

namespace System.Windows.Forms
{
    using System.Drawing;
    
    public class FontDialog : Form
    {
        // Localization text.
        internal static string   locFormText            = "Font";
        internal static string   locFontName            = "Font:";
        internal static string   locFontStyle           = "Font style:";
        internal static string[] locFontStyles          = {"Regular", "Italic", "Bold", "Bold Italic"};
        internal static string   locFontSize            = "Size:";
        internal static string   locFontEffectStrikeout = "Strikeout";
        internal static string   locFontEffectUnderline = "Underline";
        internal static string   locFontEffects         = "Effects";
        internal static string   locFontSample          = "Sample";
        internal static string   locFontScript          = "Script:";
        internal static string[] locFontScripts         = {"Western"};
        internal static string   locOk                  = "OK";
        internal static string   locCancel              = "Cancel";
        
        private string    fontName  = "Arial";
        private FontStyle fontStyle = FontStyle.Regular;
        private float     fontSize  = 12;
        private bool      initialized;

        private readonly Button   buttonCancel;
        private readonly Button   buttonOk;
        private readonly CheckBox checkStrikeout;
        private readonly CheckBox checkUnderline;
        private readonly ComboBox comboScript;
        private readonly Label    labelSample;
        private readonly ListBox  listFontName;
        private readonly ListBox  listFontSize;
        private readonly ListBox  listFontStyle;
        private readonly TextBox  textFontName;
        private readonly TextBox  textFontSize;
        private readonly TextBox  textFontStyle;
        
        public FontDialog()
        {
            FormBorderStyle = FormBorderStyle.FixedSingle;
            Size = new Size(432, 344);
            Text = locFormText;
            
            // Font name.
            var labelFontName = new Label();
            labelFontName.Location = new Point(11, 32);
            labelFontName.Text = locFontName;
            
            textFontName = new TextBox();
            textFontName.Location = new Point(11, 50);
            textFontName.Size = new Size(146, 20);
            textFontName.TabIndex = 0;
            
            listFontName = new ListBox();
            listFontName.Location = new Point(textFontName.Location.X, textFontName.Location.Y + textFontName.Height);
            listFontName.IntegralHeight = false;
            listFontName.Height = 99;
            listFontName.Width = textFontName.Width;
            listFontName.TabIndex = 3;
            listFontName.SelectedIndexChanged += ListFontNameOnSelectedIndexChanged;
            
            if (ApplicationResources.Fonts != null)
                for (int i = 0; i < ApplicationResources.Fonts.Count; i++)
                    listFontName.Items.Add(ApplicationResources.Fonts[i]);
            
            // Font style.
            var labelFontStyle = new Label();
            labelFontStyle.Location = new Point(165, 32);
            labelFontStyle.Text = locFontStyle;
            
            textFontStyle = new TextBox();
            textFontStyle.Location = new Point(165, 50);
            textFontStyle.Size = new Size(111, 20);
            textFontStyle.TabIndex = 1;
            
            listFontStyle = new ListBox();
            listFontStyle.Location = new Point(textFontStyle.Location.X, textFontStyle.Location.Y + textFontStyle.Height);
            listFontStyle.IntegralHeight = false;
            listFontStyle.Height = listFontName.Height;
            listFontStyle.Width = textFontStyle.Width;
            listFontStyle.Items.AddRange(locFontStyles);
            listFontStyle.SelectedIndex = 0;
            listFontStyle.TabIndex = 4;
            listFontStyle.SelectedIndexChanged += ListFontStyleOnSelectedIndexChanged;
            
            // Font size.
            var labelFontSize = new Label();
            labelFontSize.Location = new Point(285, 32);
            labelFontSize.Text = locFontSize;
            
            textFontSize = new TextBox();
            textFontSize.Location = new Point(285, 50);
            textFontSize.Size = new Size(54, 20);
            textFontSize.TabIndex = 2;
            
            listFontSize = new ListBox();
            listFontSize.Location = new Point(textFontSize.Location.X, textFontSize.Location.Y + textFontSize.Height);
            listFontSize.IntegralHeight = false;
            listFontSize.Height = 95;
            listFontSize.Width = textFontSize.Width;
            listFontSize.TabIndex = 5;
            listFontSize.Items.AddRange(new object[] { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 });
            listFontSize.SelectedIndexChanged += ListFontSizeOnSelectedIndexChanged;
            
            // Dialog buttons.
            buttonOk = new Button();
            buttonOk.Location = new Point(348, 51);
            buttonOk.Size = new Size(66, 21);
            buttonOk.TabIndex = 9;
            buttonOk.Text = locOk;
            buttonOk.Click += (sender, args) =>
            {
                DialogResult = DialogResult.OK;
                Close();
            };
            
            buttonCancel = new Button();
            buttonCancel.Location = new Point(348, 77);
            buttonCancel.Size = new Size(66, 21);
            buttonCancel.TabIndex = 10;
            buttonCancel.Text = locCancel;
            buttonCancel.Click += (sender, args) =>
            {
                DialogResult = DialogResult.Cancel;
                Close();
            };
            
            // Effects [Not supported].
            var groupEffects = new GroupBox();
            groupEffects.Location = new Point(11, 180);
            groupEffects.Size = new Size(146, 119);
            groupEffects.Text = locFontEffects;
            
            checkStrikeout = new CheckBox();
            checkStrikeout.Enabled = false;
            checkStrikeout.Location = new Point(10, 20);
            checkStrikeout.TabIndex = 6;
            checkStrikeout.Text = locFontEffectStrikeout;
            
            checkUnderline = new CheckBox();
            checkUnderline.Enabled = false;
            checkUnderline.Location = new Point(10, 41);
            checkUnderline.TabIndex = 7;
            checkUnderline.Text = locFontEffectUnderline;
            
            groupEffects.Controls.Add(checkStrikeout);
            groupEffects.Controls.Add(checkUnderline);
            
            // Sample.
            var groupSample = new GroupBox();
            groupSample.Location = new Point(165, 180);
            groupSample.Size = new Size(173, 72);
            groupSample.Text = locFontSample;
            
            labelSample = new Label();
            labelSample.AutoSize = false;
            labelSample.ForeColor = SystemColors.ControlText;
            labelSample.Location = new Point(0, 16);
            labelSample.Height = groupSample.Height - 16;
            labelSample.Width = groupSample.Width;
            labelSample.Text = "AaBbYyZz";
            labelSample.TextAlign = ContentAlignment.MiddleCenter;
            
            groupSample.Controls.Add(labelSample);
            
            // Script.
            var labelScript = new Label();
            labelScript.Location = new Point(165, 261);
            labelScript.Text = locFontScript;
            
            comboScript = new ComboBox();
            comboScript.Location = new Point(165, 279);
            comboScript.DropDownStyle = ComboBoxStyle.DropDownList;
            comboScript.Size = new Size(174, 20);
            comboScript.Items.AddRange(locFontScripts);
            comboScript.SelectedIndex = 0;
            comboScript.TabIndex = 8;
            
            Controls.Add(labelFontName);
            Controls.Add(textFontName);
            Controls.Add(listFontName);
            Controls.Add(labelFontStyle);
            Controls.Add(textFontStyle);
            Controls.Add(listFontStyle);
            Controls.Add(labelFontSize);
            Controls.Add(textFontSize);
            Controls.Add(listFontSize);
            Controls.Add(buttonOk);
            Controls.Add(buttonCancel);
            Controls.Add(groupEffects);
            Controls.Add(groupSample);
            Controls.Add(labelScript);
            Controls.Add(comboScript);

            AcceptButton = buttonOk;
            initialized = true;
            
            UpdateControls();
        }

        public Color Color
        {
            get { return labelSample.ForeColor; }
            set { labelSample.ForeColor = value; }
        }
        public override Font Font
        {
            get { return new Font(fontName, fontSize, fontStyle); }
            set
            {
                fontName = value.Name;
                fontStyle = value.Style;
                fontSize = value.Size;
                
                UpdateControls();
            }
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.KeyCode == Keys.Escape)
            {
                DialogResult = DialogResult.Cancel;
                Close();
            }
        }

        private static int FindIndex(ListBox list, string item)
        {
            for (int i = 0; i < list.Items.Count; i++)
                if (list.Items[i].ToString() == item)
                    return i;
            return 0;
        }
        private void ListFontNameOnSelectedIndexChanged(object sender, EventArgs e)
        {
            fontName = listFontName.SelectedItem.ToString();
            
            UpdateControls();
        }
        private void ListFontSizeOnSelectedIndexChanged(object sender, EventArgs e)
        {
            float.TryParse(listFontSize.SelectedItem.ToString(), out fontSize);
            
            UpdateControls();
        }
        private void ListFontStyleOnSelectedIndexChanged(object sender, EventArgs e)
        {
            switch (listFontStyle.SelectedIndex)
            {
                case 0:
                    fontStyle = FontStyle.Regular;
                    break;
                case 1:
                    fontStyle = FontStyle.Italic;
                    break;
                case 2:
                    fontStyle = FontStyle.Bold;
                    break;
                case 3:
                    fontStyle = FontStyle.Italic | FontStyle.Bold;
                    break;
            }
            
            UpdateControls();
        }
        private void UpdateControls()
        {
            if (!initialized)
                return;
            
            textFontName.Text = fontName;
            textFontSize.Text = fontSize.ToString(Application.CurrentCulture);
            textFontStyle.Text = listFontStyle.SelectedItem.ToString();
            labelSample.Font = Font;
            
            listFontName.SelectedIndexChanged -= ListFontNameOnSelectedIndexChanged;
            listFontName.SelectedIndex = FindIndex(listFontName, textFontName.Text);
            listFontName.SelectedIndexChanged += ListFontNameOnSelectedIndexChanged;
            
            listFontSize.SelectedIndexChanged -= ListFontSizeOnSelectedIndexChanged;
            listFontSize.SelectedIndex = FindIndex(listFontSize, textFontSize.Text);
            listFontSize.SelectedIndexChanged += ListFontSizeOnSelectedIndexChanged;
            
            listFontStyle.SelectedIndexChanged -= ListFontStyleOnSelectedIndexChanged;
            switch (fontStyle)
            {
                case FontStyle.Regular:
                    listFontStyle.SelectedIndex = 0;
                    break;
                case FontStyle.Italic:
                    listFontStyle.SelectedIndex = 1;
                    break;
                case FontStyle.Bold:
                    listFontStyle.SelectedIndex = 2;
                    break;
                case FontStyle.Italic | FontStyle.Bold:
                    listFontStyle.SelectedIndex = 3;
                    break;
            }
            listFontStyle.SelectedIndexChanged += ListFontStyleOnSelectedIndexChanged;
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/AutoCompleteMode.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum AutoCompleteMode
    {
        None = 0,
        Suggest = 1,
        Append = 2,
        SuggestAppend = 3,
    }
}


<|start_filename|>Assets/System/Drawing/Color.cs<|end_filename|>
﻿namespace System.Drawing
{
    [Serializable]
    public struct Color : IEquatable<Color>
    {
        public static readonly Color Empty = new Color();

        public static readonly Color AliceBlue            = new Color(KnownColor.AliceBlue,            0xFFF0F8FF);
        public static readonly Color AntiqueWhite         = new Color(KnownColor.AntiqueWhite,         0xFFFAEBD7);
        public static readonly Color Aqua                 = new Color(KnownColor.Aqua,                 0xFF00FFFF);
        public static readonly Color Aquamarine           = new Color(KnownColor.Aquamarine,           0xFF7FFFD4);
        public static readonly Color Azure                = new Color(KnownColor.Azure,                0xFFF0FFFF);
        public static readonly Color Beige                = new Color(KnownColor.Beige,                0xFFF5F5DC);
        public static readonly Color Bisque               = new Color(KnownColor.Bisque,               0xFFFFE4C4);
        public static readonly Color Black                = new Color(KnownColor.Black,                0xFF000000);
        public static readonly Color BlanchedAlmond       = new Color(KnownColor.BlanchedAlmond,       0xFFFFEBCD);
        public static readonly Color Blue                 = new Color(KnownColor.Blue,                 0xFF0000FF);
        public static readonly Color BlueViolet           = new Color(KnownColor.BlueViolet,           0xFF8A2BE2);
        public static readonly Color Brown                = new Color(KnownColor.Brown,                0xFFA52A2A);
        public static readonly Color BurlyWood            = new Color(KnownColor.BurlyWood,            0xFFDEB887);
        public static readonly Color CadetBlue            = new Color(KnownColor.CadetBlue,            0xFF5F9EA0);
        public static readonly Color Chartreuse           = new Color(KnownColor.Chartreuse,           0xFF7FFF00);
        public static readonly Color Chocolate            = new Color(KnownColor.Chocolate,            0xFFD2691E);
        public static readonly Color Coral                = new Color(KnownColor.Coral,                0xFFFF7F50);
        public static readonly Color CornflowerBlue       = new Color(KnownColor.CornflowerBlue,       0xFF6495ED);
        public static readonly Color Cornsilk             = new Color(KnownColor.Cornsilk,             0xFFFFF8DC);
        public static readonly Color Crimson              = new Color(KnownColor.Crimson,              0xFFDC143C);
        public static readonly Color Cyan                 = new Color(KnownColor.Cyan,                 0xFF00FFFF);
        public static readonly Color DarkBlue             = new Color(KnownColor.DarkBlue,             0xFF00008B);
        public static readonly Color DarkCyan             = new Color(KnownColor.DarkCyan,             0xFF008B8B);
        public static readonly Color DarkGoldenrod        = new Color(KnownColor.DarkGoldenrod,        0xFFB8860B);
        public static readonly Color DarkGray             = new Color(KnownColor.DarkGray,             0xFFA9A9A9);
        public static readonly Color DarkGreen            = new Color(KnownColor.DarkGreen,            0xFF006400);
        public static readonly Color DarkKhaki            = new Color(KnownColor.DarkKhaki,            0xFFBDB76B);
        public static readonly Color DarkMagenta          = new Color(KnownColor.DarkMagenta,          0xFF8B008B);
        public static readonly Color DarkOliveGreen       = new Color(KnownColor.DarkOliveGreen,       0xFF556B2F);
        public static readonly Color DarkOrange           = new Color(KnownColor.DarkOrange,           0xFFFF8C00);
        public static readonly Color DarkOrchid           = new Color(KnownColor.DarkOrchid,           0xFF9932CC);
        public static readonly Color DarkRed              = new Color(KnownColor.DarkRed,              0xFF8B0000);
        public static readonly Color DarkSalmon           = new Color(KnownColor.DarkSalmon,           0xFFE9967A);
        public static readonly Color DarkSeaGreen         = new Color(KnownColor.DarkSeaGreen,         0xFF8FBC8B);
        public static readonly Color DarkSlateBlue        = new Color(KnownColor.DarkSlateBlue,        0xFF483D8B);
        public static readonly Color DarkSlateGray        = new Color(KnownColor.DarkSlateGray,        0xFF2F4F4F);
        public static readonly Color DarkTurquoise        = new Color(KnownColor.DarkTurquoise,        0xFF00CED1);
        public static readonly Color DarkViolet           = new Color(KnownColor.DarkViolet,           0xFF9400D3);
        public static readonly Color DeepPink             = new Color(KnownColor.DeepPink,             0xFFFF1493);
        public static readonly Color DeepSkyBlue          = new Color(KnownColor.DeepSkyBlue,          0xFF00BFFF);
        public static readonly Color DimGray              = new Color(KnownColor.DimGray,              0xFF696969);
        public static readonly Color DodgerBlue           = new Color(KnownColor.DodgerBlue,           0xFF1E90FF);
        public static readonly Color Firebrick            = new Color(KnownColor.Firebrick,            0xFFB22222);
        public static readonly Color FloralWhite          = new Color(KnownColor.FloralWhite,          0xFFFFFAF0);
        public static readonly Color ForestGreen          = new Color(KnownColor.ForestGreen,          0xFF228B22);
        public static readonly Color Fuchsia              = new Color(KnownColor.Fuchsia,              0xFFFF00FF);
        public static readonly Color Gainsboro            = new Color(KnownColor.Gainsboro,            0xFFDCDCDC);
        public static readonly Color GhostWhite           = new Color(KnownColor.GhostWhite,           0xFFF8F8FF);
        public static readonly Color Gold                 = new Color(KnownColor.Gold,                 0xFFFFD700);
        public static readonly Color Goldenrod            = new Color(KnownColor.Goldenrod,            0xFFDAA520);
        public static readonly Color Gray                 = new Color(KnownColor.Gray,                 0xFF808080);
        public static readonly Color Green                = new Color(KnownColor.Green,                0xFF008000);
        public static readonly Color GreenYellow          = new Color(KnownColor.GreenYellow,          0xFFADFF2F);
        public static readonly Color Honeydew             = new Color(KnownColor.Honeydew,             0xFFF0FFF0);
        public static readonly Color HotPink              = new Color(KnownColor.HotPink,              0xFFFF69B4);
        public static readonly Color IndianRed            = new Color(KnownColor.IndianRed,            0xFFCD5C5C);
        public static readonly Color Indigo               = new Color(KnownColor.Indigo,               0xFF4B0082);
        public static readonly Color Ivory                = new Color(KnownColor.Ivory,                0xFFFFFFF0);
        public static readonly Color Khaki                = new Color(KnownColor.Khaki,                0xFFF0E68C);
        public static readonly Color Lavender             = new Color(KnownColor.Lavender,             0xFFE6E6FA);
        public static readonly Color LavenderBlush        = new Color(KnownColor.LavenderBlush,        0xFFFFF0F5);
        public static readonly Color LawnGreen            = new Color(KnownColor.LawnGreen,            0xFF7CFC00);
        public static readonly Color LemonChiffon         = new Color(KnownColor.LemonChiffon,         0xFFFFFACD);
        public static readonly Color LightBlue            = new Color(KnownColor.LightBlue,            0xFFADD8E6);
        public static readonly Color LightCoral           = new Color(KnownColor.LightCoral,           0xFFF08080);
        public static readonly Color LightCyan            = new Color(KnownColor.LightCyan,            0xFFE0FFFF);
        public static readonly Color LightGoldenrodYellow = new Color(KnownColor.LightGoldenrodYellow, 0xFFFAFAD2);
        public static readonly Color LightGray            = new Color(KnownColor.LightGray,            0xFFD3D3D3);
        public static readonly Color LightGreen           = new Color(KnownColor.LightGreen,           0xFF90EE90);
        public static readonly Color LightPink            = new Color(KnownColor.LightPink,            0xFFFFB6C1);
        public static readonly Color LightSalmon          = new Color(KnownColor.LightSalmon,          0xFFFFA07A);
        public static readonly Color LightSeaGreen        = new Color(KnownColor.LightSeaGreen,        0xFF20B2AA);
        public static readonly Color LightSkyBlue         = new Color(KnownColor.SkyBlue,              0xFF87CEFA);
        public static readonly Color LightSlateGray       = new Color(KnownColor.LightSlateGray,       0xFF778899);
        public static readonly Color LightSteelBlue       = new Color(KnownColor.LightSteelBlue,       0xFFB0C4DE);
        public static readonly Color LightYellow          = new Color(KnownColor.LightYellow,          0xFFFFFFE0);
        public static readonly Color Lime                 = new Color(KnownColor.Lime,                 0xFF00FF00);
        public static readonly Color LimeGreen            = new Color(KnownColor.LimeGreen,            0xFF32CD32);
        public static readonly Color Linen                = new Color(KnownColor.Linen,                0xFFFAF0E6);
        public static readonly Color Magenta              = new Color(KnownColor.Magenta,              0xFFFF00FF);
        public static readonly Color Maroon               = new Color(KnownColor.Maroon,               0xFF800000);
        public static readonly Color MediumAquamarine     = new Color(KnownColor.MediumAquamarine,     0xFF66CDAA);
        public static readonly Color MediumBlue           = new Color(KnownColor.MediumBlue,           0xFF0000CD);
        public static readonly Color MediumOrchid         = new Color(KnownColor.MediumOrchid,         0xFFBA55D3);
        public static readonly Color MediumPurple         = new Color(KnownColor.MediumPurple,         0xFF9370DB);
        public static readonly Color MediumSeaGreen       = new Color(KnownColor.MediumSeaGreen,       0xFF3CB371);
        public static readonly Color MediumSlateBlue      = new Color(KnownColor.MediumSlateBlue,      0xFF7B68EE);
        public static readonly Color MediumSpringGreen    = new Color(KnownColor.MediumSpringGreen,    0xFF00FA9A);
        public static readonly Color MediumTurquoise      = new Color(KnownColor.MediumTurquoise,      0xFF48D1CC);
        public static readonly Color MediumVioletRed      = new Color(KnownColor.MediumVioletRed,      0xFFC71585);
        public static readonly Color MidnightBlue         = new Color(KnownColor.MidnightBlue,         0xFF191970);
        public static readonly Color MintCream            = new Color(KnownColor.MintCream,            0xFFF5FFFA);
        public static readonly Color MistyRose            = new Color(KnownColor.MistyRose,            0xFFFFE4E1);
        public static readonly Color Moccasin             = new Color(KnownColor.Moccasin,             0xFFFFE4B5);
        public static readonly Color NavajoWhite          = new Color(KnownColor.NavajoWhite,          0xFFFFDEAD);
        public static readonly Color Navy                 = new Color(KnownColor.Navy,                 0xFF000080);
        public static readonly Color OldLace              = new Color(KnownColor.OldLace,              0xFFFDF5E6);
        public static readonly Color Olive                = new Color(KnownColor.Olive,                0xFF808000);
        public static readonly Color OliveDrab            = new Color(KnownColor.OliveDrab,            0xFF6B8E23);
        public static readonly Color Orange               = new Color(KnownColor.Orange,               0xFFFFA500);
        public static readonly Color OrangeRed            = new Color(KnownColor.OrangeRed,            0xFFFF4500);
        public static readonly Color Orchid               = new Color(KnownColor.Orchid,               0xFFDA70D6);
        public static readonly Color PaleGoldenrod        = new Color(KnownColor.PaleGoldenrod,        0xFFEEE8AA);
        public static readonly Color PaleGreen            = new Color(KnownColor.PaleGreen,            0xFF98FB98);
        public static readonly Color PaleTurquoise        = new Color(KnownColor.PaleTurquoise,        0xFFAFEEEE);
        public static readonly Color PaleVioletRed        = new Color(KnownColor.PaleVioletRed,        0xFFDB7093);
        public static readonly Color PapayaWhip           = new Color(KnownColor.PapayaWhip,           0xFFFFEFD5);
        public static readonly Color PeachPuff            = new Color(KnownColor.PeachPuff,            0xFFFFDAB9);
        public static readonly Color Peru                 = new Color(KnownColor.Peru,                 0xFFCD853F);
        public static readonly Color Pink                 = new Color(KnownColor.Pink,                 0xFFFFC0CB);
        public static readonly Color Plum                 = new Color(KnownColor.Plum,                 0xFFDDA0DD);
        public static readonly Color PowderBlue           = new Color(KnownColor.PowderBlue,           0xFFB0E0E6);
        public static readonly Color Purple               = new Color(KnownColor.Purple,               0xFF800080);
        public static readonly Color Red                  = new Color(KnownColor.Red,                  0xFFFF0000);
        public static readonly Color RosyBrown            = new Color(KnownColor.RosyBrown,            0xFFBC8F8F);
        public static readonly Color RoyalBlue            = new Color(KnownColor.RoyalBlue,            0xFF4169E1);
        public static readonly Color SaddleBrown          = new Color(KnownColor.SaddleBrown,          0xFF8B4513);
        public static readonly Color Salmon               = new Color(KnownColor.Salmon,               0xFFFA8072);
        public static readonly Color SandyBrown           = new Color(KnownColor.SandyBrown,           0xFFF4A460);
        public static readonly Color SeaGreen             = new Color(KnownColor.SeaGreen,             0xFF2E8B57);
        public static readonly Color SeaShell             = new Color(KnownColor.SeaShell,             0xFFFFF5EE);
        public static readonly Color Sienna               = new Color(KnownColor.Sienna,               0xFFA0522D);
        public static readonly Color Silver               = new Color(KnownColor.Silver,               0xFFC0C0C0);
        public static readonly Color SkyBlue              = new Color(KnownColor.SkyBlue,              0xFF87CEEB);
        public static readonly Color SlateBlue            = new Color(KnownColor.SlateBlue,            0xFF6A5ACD);
        public static readonly Color SlateGray            = new Color(KnownColor.SlateGray,            0xFF708090);
        public static readonly Color Snow                 = new Color(KnownColor.Snow,                 0xFFFFFAFA);
        public static readonly Color SpringGreen          = new Color(KnownColor.SpringGreen,          0xFF00FF7F);
        public static readonly Color SteelBlue            = new Color(KnownColor.SteelBlue,            0xFF4682B4);
        public static readonly Color Tan                  = new Color(KnownColor.Tan,                  0xFFD2B48C);
        public static readonly Color Teal                 = new Color(KnownColor.Teal,                 0xFF008080);
        public static readonly Color Thistle              = new Color(KnownColor.Thistle,              0xFFD8BFD8);
        public static readonly Color Tomato               = new Color(KnownColor.Tomato,               0xFFFF6347);
        public static readonly Color Transparent          = new Color(KnownColor.Transparent,          0x00FFFFFF);
        public static readonly Color Turquoise            = new Color(KnownColor.Turquoise,            0xFF40E0D0);
        public static readonly Color Violet               = new Color(KnownColor.Violet,               0xFFEE82EE);
        public static readonly Color Wheat                = new Color(KnownColor.Wheat,                0xFFF5DEB3);
        public static readonly Color White                = new Color(KnownColor.White,                0xFFFFFFFF);
        public static readonly Color WhiteSmoke           = new Color(KnownColor.WhiteSmoke,           0xFFF5F5F5);
        public static readonly Color Yellow               = new Color(KnownColor.Yellow,               0xFFFFFF00);
        public static readonly Color YellowGreen          = new Color(KnownColor.YellowGreen,          0xFF9ACD32);

        private const int ARGBAlphaShift = 24;
        private const int ARGBRedShift   = 16;
        private const int ARGBGreenShift = 8;
        private const int ARGBBlueShift  = 0;
        
        private const short StateKnownColorValid = 0x0001;
        private const short StateARGBValueValid  = 0x0002;
        
        private readonly byte a, r, g, b;
        private readonly short knownColor;
        private readonly short state;

        internal Color(byte a, byte r, byte g, byte b)
        {
            this.a = a;
            this.r = r;
            this.g = g;
            this.b = b;
            this.state = StateARGBValueValid;
            this.knownColor = 0;
        }
        internal Color(KnownColor knownColor, long value)
        {
            this.a = (byte)((value >> ARGBAlphaShift) & 0xFF);
            this.r = (byte)((value >> ARGBRedShift) & 0xFF);
            this.g = (byte)((value >> ARGBGreenShift) & 0xFF);
            this.b = (byte)((value >> ARGBBlueShift) & 0xFF);
            this.state = StateKnownColorValid;
            this.knownColor = (short)knownColor;
        }

        public bool IsEmpty { get { return state == 0; } }
        public bool IsKnownColor { get { return knownColor != 0; } }
        public bool IsSystemColor {
            get 
            {
                return IsKnownColor && ((KnownColor) knownColor <= KnownColor.WindowText || 
                                        (KnownColor) knownColor > KnownColor.YellowGreen);
            }
        }
        public byte A { get { return a; } }
        public byte R { get { return r; } }
        public byte G { get { return g; } }
        public byte B { get { return b; } }
        
        public static bool operator !=(Color left, Color right)
        {
            return !(left == right);
        }
        public static bool operator ==(Color left, Color right)
        {
            if (left.a == right.a && 
                left.r == right.r && 
                left.g == right.g && 
                left.b == right.b && 
                left.state == right.state)
                return true;
            return false;
        }

        public static Color FromArgb(int argb) 
        {
            return new Color(0, argb);
        }
        public static Color FromArgb(int alpha, Color baseColor)
        {
            return FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B);
        }
        public static Color FromArgb(int r, int g, int b)
        {
            return FromArgb(255, r, g, b);
        }
        public static Color FromArgb(int a, int r, int g, int b)
        {
            if (a < 0) a = 0;
            return new Color((byte)a, (byte)r, (byte)g, (byte)b);
        }

        public bool Equals(Color other)
        {
            return state == other.state && a == other.a && r == other.r && g == other.g && b == other.b;
        }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            return obj is Color && Equals((Color)obj);
        }
        public float GetBrightness()
        {
            float fR = R / 255f;
            float fG = G / 255f;
            float fB = B / 255f;
            float max = fR;
            float min = fR;

            if (fG > max) max = fG;
            if (fB > max) max = fB;
            if (fG < min) min = fG;
            if (fB < min) min = fB;
            
            return (max + min) / 2f;
        }
        public override int GetHashCode()
        {
            return r.GetHashCode() ^
                   g.GetHashCode() ^
                   b.GetHashCode() ^
                   a.GetHashCode() ^
                   state.GetHashCode() ^
                   knownColor.GetHashCode();
        }
        public float GetHue()
        {
            if (R == G && G == B)
                return 0f;

            float fR = R / 255f;
            float fG = G / 255f;
            float fB = B / 255f;
            float hue = 0f;
            float max = fR;
            float min = fR;

            if (fG > max) max = fG;
            if (fB > max) max = fB;
            if (fG < min) min = fG;
            if (fB < min) min = fB;
            
            float delta = max - min;
            
            if (fR == max)
            {
                hue = (fG - fB) / delta;
            }
            else if (fG == max)
            {
                hue = 2f + (fB - fR) / delta;
            }
            else
            {
                hue = 4f + (fR - fG) / delta;
            }
            
            hue *= 60f;

            if (hue < 0f)
                hue += 360f;
            
            return hue;
        }
        public float GetSaturation()
        {
            float fR = R / 255f;
            float fG = G / 255f;
            float fB = B / 255f;
            float saturation = 0f;
            float max = fR;
            float min = fR;
            if (fG > max) max = fG;
            if (fB > max) max = fB;
            if (fG < min) min = fG;
            if (fB < min) min = fB;
            
            if (max != min)
            {
                float l = (max + min) / 2f;
                if (l <= 0.5)
                {
                    saturation = (max - min) / (max + min);
                }
                else
                {
                    saturation = (max - min) / (2f - max - min);
                }
            }
            
            return saturation;
        }
        public override string ToString()
        {
            return "{ R: " + R + "; G: " + G + "; B: " + B + "; A: " + A + " }";
        }
    }
}

<|start_filename|>Assets/Controls/Highcharts/SeriesPoint.cs<|end_filename|>
namespace Highcharts
{
    using System.Drawing;
    
    public class SeriesPoint : Series
    {
        private readonly SolidBrush pointBrush = new SolidBrush(Color.Black);
        
        public SeriesPoint() : this("")
        { }

        public SeriesPoint(string name) : base(name)
        { }

        protected override void OnPaint(Graphics g, Rectangle clipRectangle)
        {
            pointBrush.Color = color;

            var pointRadius = collection.chart.circleRadius;
            var valueRange = GetValueRange();
            var xStep = GetXStep();
            
            for (float dataIterator = 0; dataIterator < data.Count; dataIterator += pointInterval)
            {
                int dataIndex = (int) dataIterator;
                 
                double currentValue = data[dataIndex];

                float currentValueX = GetXFromIndex(dataIndex, xStep, clipRectangle) - pointRadius;
                float currentValueY = GetYFromValue(currentValue, valueRange, clipRectangle) - pointRadius;
                
                g.FillEllipse(pointBrush, currentValueX, currentValueY, pointRadius * 2, pointRadius * 2);
                
                SeriesPaint.PaintHoveredValueRect(this, g, currentValueX, currentValueY, xStep);
            }
        }
        
        protected override void OnPaintIcon(Graphics g, Rectangle clipRectangle)
        {
            pointBrush.Color = color;
            
            g.FillEllipse(pointBrush,  clipRectangle.Left + 4, clipRectangle.Top + 8, 8, 8);
        }
    }
}

<|start_filename|>Assets/System/Drawing/SystemBrushes.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Collections.Generic;
    
    public static class SystemBrushes
    {
        private static readonly Dictionary<Color, Brush> items = new Dictionary<Color, Brush>();
        
        public static Brush ActiveBorder
        {
            get { return FromSystemColor(SystemColors.ActiveBorder); }
        }
        public static Brush ActiveCaption
        {
            get { return FromSystemColor(SystemColors.ActiveCaption); }
        }
        public static Brush ActiveCaptionText
        {
            get { return FromSystemColor(SystemColors.ActiveCaptionText); }
        }
        public static Brush AppWorkspace
        {
            get { return FromSystemColor(SystemColors.AppWorkspace); }
        }
        public static Brush ButtonFace
        {
            get { return FromSystemColor(SystemColors.ButtonFace); }
        }
        public static Brush ButtonHighlight
        {
            get { return FromSystemColor(SystemColors.ButtonHighlight); }
        }
        public static Brush ButtonShadow
        {
            get { return FromSystemColor(SystemColors.ButtonShadow); }
        }
        public static Brush Control
        {
            get { return FromSystemColor(SystemColors.Control); }
        }
        public static Brush ControlLightLight
        {
            get { return FromSystemColor(SystemColors.ControlLightLight); }
        }
        public static Brush ControlLight
        {
            get { return FromSystemColor(SystemColors.ControlLight); }
        }
        public static Brush ControlDark
        {
            get { return FromSystemColor(SystemColors.ControlDark); }
        }
        public static Brush ControlDarkDark
        {
            get { return FromSystemColor(SystemColors.ControlDarkDark); }
        }
        public static Brush ControlText
        {
            get { return FromSystemColor(SystemColors.ControlText); }
        }
        public static Brush Desktop
        {
            get { return FromSystemColor(SystemColors.Desktop); }
        }
        public static Brush GradientActiveCaption
        {
            get { return FromSystemColor(SystemColors.GradientActiveCaption); }
        }
        public static Brush GradientInactiveCaption
        {
            get { return FromSystemColor(SystemColors.GradientInactiveCaption); }
        }
        public static Brush GrayText
        {
            get { return FromSystemColor(SystemColors.GrayText); }
        }
        public static Brush Highlight
        {
            get { return FromSystemColor(SystemColors.Highlight); }
        }
        public static Brush HighlightText
        {
            get { return FromSystemColor(SystemColors.HighlightText); }
        }
        public static Brush HotTrack
        {
            get { return FromSystemColor(SystemColors.HotTrack); }
        }
        public static Brush InactiveCaption
        {
            get { return FromSystemColor(SystemColors.InactiveCaption); }
        }
        public static Brush InactiveBorder
        {
            get { return FromSystemColor(SystemColors.InactiveBorder); }
        }
        public static Brush InactiveCaptionText
        {
            get { return FromSystemColor(SystemColors.InactiveCaptionText); }
        }
        public static Brush Info
        {
            get { return FromSystemColor(SystemColors.Info); }
        }
        public static Brush InfoText
        {
            get { return FromSystemColor(SystemColors.InfoText); }
        }
        public static Brush Menu
        {
            get { return FromSystemColor(SystemColors.Menu); }
        }
        public static Brush MenuBar
        {
            get { return FromSystemColor(SystemColors.MenuBar); }
        }
        public static Brush MenuHighlight
        {
            get { return FromSystemColor(SystemColors.MenuHighlight); }
        }
        public static Brush MenuText
        {
            get { return FromSystemColor(SystemColors.MenuText); }
        }
        public static Brush ScrollBar
        {
            get { return FromSystemColor(SystemColors.ScrollBar); }
        }
        public static Brush Window
        {
            get { return FromSystemColor(SystemColors.Window); }
        }
        public static Brush WindowFrame
        {
            get { return FromSystemColor(SystemColors.WindowFrame); }
        }
        public static Brush WindowText
        {
            get { return FromSystemColor(SystemColors.WindowText); }
        }

        public static Brush FromSystemColor(Color c)
        {
            if (!c.IsSystemColor)
                throw new ArgumentException("Color is not system color.");

            if (items.ContainsKey(c))
                return items[c];

            var brush = new SolidBrush(c);
            
            items.Add(c, brush);
            return brush;
        }
    }
}

<|start_filename|>Assets/Controls/Highcharts/Chart.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Drawing;

    public class Chart : IDisposable
    {
        internal Pen borderPen     = new Pen(Color.White);
        internal Pen plotBorderPen = new Pen(Color.Transparent);

        public Chart()
        {
            backgroundColor = Color.FromArgb(0xFF, 0xFF, 0xFF);
            borderColor = Color.FromArgb(0x33, 0x5C, 0xAD);
            borderWidth = 0;
            plotBackgroundColor = Color.Transparent;
            plotBorderColor = Color.FromArgb(0xCC, 0xCC, 0xCC);
            plotBorderWidth = 0;
            spacingBottom = 15;
            spacingLeft = 10;
            spacingRight = 10;
            spacingTop = 10;
        }

        public Color backgroundColor { get; set; }
        public Color borderColor { get; set; }
        public int borderWidth { get; set; }
        public int?[] margin
        {
            get { return new[] {marginTop, marginRight, marginBottom, marginLeft}; }
            set
            {
                if (value == null)
                {
                    marginBottom = null;
                    marginLeft = null;
                    marginRight = null;
                    marginTop = null;
                }
                else if (value.Length != 4)
                {
                    throw new NotSupportedException("margin");
                }
                else
                {
                    marginBottom = value[2];
                    marginLeft = value[3];
                    marginRight = value[1];
                    marginTop = value[0];
                }
            }
        }
        public int? marginBottom { get; set; }
        public int? marginLeft { get; set; }
        public int? marginRight { get; set; }
        public int? marginTop { get; set; }
        public Color plotBackgroundColor { get; set; }
        public Color plotBorderColor
        {
            get { return plotBorderPen.Color; }
            set { plotBorderPen.Color = value; }
        }
        public int plotBorderWidth
        {
            get { return (int)plotBorderPen.Width; }
            set { plotBorderPen.Width = value; }
        }
        public int spacingBottom { get; set; }
        public int spacingLeft { get; set; }
        public int spacingRight { get; set; }
        public int spacingTop { get; set; }
        //public ZoomTypes zoomType { get; set; }

        public void Dispose()
        {
            if (borderPen != null) borderPen.Dispose();
            if (plotBorderPen != null) plotBorderPen.Dispose();
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripButton.cs<|end_filename|>
namespace System.Windows.Forms
{
    using System.Drawing;

    //// Default size is 23, 22.
    public class ToolStripButton : ToolStripItem
    {
        private CheckState checkState = CheckState.Unchecked;
        private bool checkOnClick;
        
        public ToolStripButton()
        {
        }
        public ToolStripButton(string text) : base(text, null, null)
        {
        }
        public ToolStripButton(Image image) : base(null, image, null)
        {
        }
        public ToolStripButton(string text, Image image) : base(text, image, null)
        {
        }
        public ToolStripButton(string text, Image image, EventHandler onClick) : base(text, image, onClick)
        {
        }
        public ToolStripButton(string text, Image image, EventHandler onClick, string name) : base(text, image, onClick, name)
        {
        }

        public event EventHandler CheckedChanged;
        public event EventHandler CheckStateChanged;

        public override bool CanSelect
        {
            get { return true; }
        }
        public bool Checked
        {
            get { return checkState != CheckState.Unchecked; }
            set
            {
                if (value == Checked)
                    return;

                CheckState = value ? CheckState.Checked : CheckState.Unchecked;
            }
        }
        public CheckState CheckState
        {
            get { return checkState; }
            set
            {
                if (value == checkState)
                    return;

                checkState = value;
                OnCheckedChanged(EventArgs.Empty);
                OnCheckStateChanged(EventArgs.Empty);
            }
        }
        public bool CheckOnClick {
            get { return checkOnClick; }
            set { checkOnClick = value; }
        }

        protected internal override void SetBounds(Rectangle nbounds)
        {
            if (AutoSize && nbounds.Width != 23) // Always set width = 23 if autosize?
                nbounds = new Rectangle(nbounds.X, nbounds.Y, 23, nbounds.Height);

            base.SetBounds(nbounds);
        }

        protected override void OnClick(EventArgs e)
        {
            if (checkOnClick)
                Checked = !Checked;
            
            base.OnClick(e);
        }
        protected virtual void OnCheckedChanged(EventArgs e) {
            var handler = CheckedChanged;
            if (handler != null) 
                handler(this,e);
        }
        protected virtual void OnCheckStateChanged(EventArgs e)
        {
            var handler = CheckStateChanged;
            if (handler != null) 
                handler(this,e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            
            if (Checked)
                e.Graphics.DrawRectangle(selectPen, Bounds);
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/LinkBehavior.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum LinkBehavior
    {
        SystemDefault,
        AlwaysUnderline,
        HoverUnderline,
        NeverUnderline,
    }
}

<|start_filename|>Assets/System/Windows/Forms/HScrollBar.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class HScrollBar : ScrollBar
    {
        public HScrollBar()
        {
            scrollOrientation = ScrollOrientation.HorizontalScroll;

            subtractButton.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
            subtractButton.Image = uwfAppOwner.Resources.CurvedArrowLeft;
            subtractButton.Size = new Size(SystemInformation.HorizontalScrollBarArrowWidth, SystemInformation.HorizontalScrollBarHeight);
            subtractButton.Location = new Point(0, 0);

            addButton.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            addButton.Image = uwfAppOwner.Resources.CurvedArrowRight;
            addButton.Size = new Size(SystemInformation.HorizontalScrollBarArrowWidth, SystemInformation.HorizontalScrollBarHeight);
            addButton.Location = new Point(Width - addButton.Width, 0);

            UpdateScrollRect();
        }

        protected override Size DefaultSize
        {
            get { return new Size(80, SystemInformation.HorizontalScrollBarHeight); }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/TreeNodeMouseHoverEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void TreeNodeMouseHoverEventHandler(object sender, TreeNodeMouseHoverEventArgs e);

    public class TreeNodeMouseHoverEventArgs : EventArgs
    {
        public TreeNodeMouseHoverEventArgs(TreeNode node)
        {
            Node = node;
        }

        public TreeNode Node { get; private set; }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolTip.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;

    public class ToolTip : Component
    {
        private const int   SCREEN_MIN_MARGIN = 2;
        private const int   SHADOW_STRENGTH   = 12;
        private const float ALPHA_TIME_SEC    = .5f;
        private const float ALPHA_SPEED       = 255f / ALPHA_TIME_SEC;
        
        internal static ToolTip instance;
        internal int alphaState; // 0: none; 1: 0 to 255; 2 : alphaWait; 3: 255 to 0
        
        private static readonly Queue<ToolTip> items = new Queue<ToolTip>();

        private readonly Pen borderPen = new Pen(Color.Black);
        private float   alphaF;
        private float   alphaWait; // seconds. Wait time before hide. 
        private Control control;
        private int     initialDelay = 1000;
        private Point   location;
        private string  text;
        private float   waitToShow;

        public ToolTip()
        {
            BackColor = SystemColors.Info;
            ForeColor = SystemColors.uwfInfoText;
            
            uwfBorderColor = Color.FromArgb(118, 118, 118);
            uwfFont = new Font("Arial", 12);
            uwfPadding = new Padding(8, 2, 8, 2);
        }

        public Color BackColor { get; set; }
        public Color ForeColor { get; set; }
        public int InitialDelay
        {
            get { return initialDelay; }
            set { initialDelay = MathHelper.Clamp(value, 0, 32767); }
        }

        internal Color uwfBorderColor { get; set; }
        internal Font uwfFont { get; set; }
        internal Padding uwfPadding { get; set; }
        
        public void SetToolTip(Control control, string caption)
        {
            this.control = control;
            control.MouseEnter -= control_MouseEnter;
            control.MouseEnter += control_MouseEnter;
            control.MouseLeave -= control_MouseLeave;
            control.MouseLeave += control_MouseLeave;
            control.Disposed -= control_Disposed;
            control.Disposed += control_Disposed;
            control.VisibleChanged -= control_Disposed;
            control.VisibleChanged += control_Disposed;
            text = caption;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="text"></param>
        /// <param name="point">Useless right now (will use Control.MousePosition)</param>
        public void Show(string text, Point point)
        {
            if (string.IsNullOrEmpty(text))
                return;

            location = Control.MousePosition;
            location = new Point(location.X, location.Y + 24); // Cursor offset.
            this.text = text;
            alphaF = 0;
            alphaWait = 5;
            alphaState = 0;
            waitToShow = initialDelay;

            if (instance != this && items.Contains(this) == false)
                items.Enqueue(this);
        }

        internal static void OnPaint(PaintEventArgs e)
        {
            if (instance == null && items.Count > 0)
                instance = items.Dequeue();

            if (instance != null)
            {
                instance.PaintInternal(e);

                TryHideInstance();
            }
        }

        protected override void Dispose(bool release_all)
        {
            base.Dispose(release_all);

            if (control != null)
            {
                control.MouseEnter -= control_MouseEnter;
                control.MouseLeave -= control_MouseLeave;
                control.Disposed -= control_Disposed;
                control.VisibleChanged -= control_Disposed;
            }
        }

        private static void ForceHideInstance()
        {
            if (instance != null)
                instance.alphaState = 3;
        }
        private static void TryHideInstance()
        {
            if (instance != null && items.Count > 0 && instance.alphaState != 3)
                instance.alphaState = 3;
        }

        private void control_MouseLeave(object sender, EventArgs e)
        {
            ForceHideInstance();
        }
        private void control_MouseEnter(object sender, EventArgs e)
        {
            if (control != null && control.Visible && !control.Disposing)
            {
                var position = Control.MousePosition.Add(new Point(0, 18));

                Show(text, position);
            }
        }
        private void control_Disposed(object sender, EventArgs e)
        {
            ForceHideInstance();
        }
        
        private void PaintInternal(PaintEventArgs e)
        {
            if (waitToShow > 0)
            {
                waitToShow -= 1000 * swfHelper.GetDeltaTime();
                return;
            }
            
            UpdateAlpha();

            var g = e.Graphics;

            var screenSize = Screen.PrimaryScreen.WorkingArea;
            var textSize = g.MeasureString(text, uwfFont);
            
            var renderingW = (int) textSize.Width + uwfPadding.Horizontal;
            var renderingH = (int) textSize.Height + uwfPadding.Vertical;
            var renderingX = MathHelper.Clamp(location.X, 0, screenSize.Width - SCREEN_MIN_MARGIN - renderingW);
            var renderingY = MathHelper.Clamp(location.Y, 0, screenSize.Height - SCREEN_MIN_MARGIN - renderingH);

            var alpha = MathHelper.Clamp((int) alphaF, 1, 255);
            
            // Shadow.
            var shadowAlpha = SHADOW_STRENGTH / (255 / alpha);
            var shadowColor = Color.FromArgb(shadowAlpha, 64, 64, 64);
            
            g.uwfFillRectangle(shadowColor, renderingX + 1, renderingY + 1, renderingW + 3, renderingH + 3);
            g.uwfFillRectangle(shadowColor, renderingX + 2, renderingY + 2, renderingW + 1, renderingH + 1);
            g.uwfFillRectangle(shadowColor, renderingX + 3, renderingY + 3, renderingW - 1, renderingH - 1);

            // Background.
            var backColor = Color.FromArgb(alpha, BackColor);
            
            g.uwfFillRectangle(backColor, renderingX, renderingY, renderingW, renderingH);
            
            // Border.
            borderPen.Color = Color.FromArgb(alpha, uwfBorderColor);
            
            g.DrawRectangle(borderPen, renderingX, renderingY, renderingW, renderingH);
            
            // Text.
            var textColor = Color.FromArgb(alpha, ForeColor);
            var textFont = uwfFont;
            var textX = renderingX + uwfPadding.Left;
            var textY = renderingY + uwfPadding.Top;
            var textWidth = renderingW - uwfPadding.Horizontal;
            var textHeight = renderingH - uwfPadding.Vertical;
            
            g.uwfDrawString(text, textFont, textColor, textX, textY, textWidth, textHeight);
        }
        
        private void UpdateAlpha()
        {
            switch (alphaState)
            {
                case 0:
                    alphaState = 1;
                    break;
                
                case 1:
                    // 0 to 255.
                    if (alphaF < 255)
                        alphaF += swfHelper.GetDeltaTime() * ALPHA_SPEED;
                    else
                    {
                        alphaF = 255;
                        alphaState = 2;
                    }

                    break;
                
                case 2:
                    // Wait.
                    if (alphaWait > 0)
                        alphaWait -= swfHelper.GetDeltaTime();
                    else
                    {
                        alphaWait = 0;
                        alphaState = 3;
                    }

                    break;
                
                case 3:
                    // 255 to 0.
                    if (alphaF > 0)
                        alphaF -= swfHelper.GetDeltaTime() * ALPHA_SPEED;
                    else
                    {
                        alphaF = 0;
                        instance = null;
                    }

                    break;
            }
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/CheckBox.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class CheckBox : ButtonBase
    {
        internal Color uwfBoxBackColor = Color.White;
        internal Color uwfBoxBackHoverColor = Color.FromArgb(243, 249, 255);
        internal Color uwfBoxBackDisableColor = Color.FromArgb(230, 230, 230);
        internal Color uwfMarkColor = Color.FromArgb(15, 15, 15);
        internal Color uwfMarkHoverColor = Color.FromArgb(15, 15, 15);

        private readonly Pen borderPen = new Pen(Color.Transparent);
        private CheckState checkState;
        private bool measureText;
        private SizeF textSize;

        public CheckBox()
        {
            BackColor = Color.Transparent;
            TextAlign = ContentAlignment.MiddleLeft;

            uwfBorderColor = Color.FromArgb(112, 112, 112);
            uwfBorderHoverColor = Color.FromArgb(51, 153, 255);
            uwfBorderDisableColor = Color.FromArgb(188, 188, 188);
            uwfHoverColor = Color.Transparent;

            Click += CheckBox_Click;
        }

        public event EventHandler CheckedChanged = delegate { };

        public bool Checked
        {
            get { return checkState != CheckState.Unchecked; }
            set { CheckState = value ? CheckState.Checked : CheckState.Unchecked; }
        }
        public CheckState CheckState
        {
            get
            {
                return checkState;
            }
            set
            {
                if (checkState != value)
                {
                    checkState = value;
                    OnCheckedChanged(EventArgs.Empty);
                }
            }
        }

        protected override Size DefaultSize
        {
            get { return new Size(104, 24); }
        }

        protected virtual void OnCheckedChanged(EventArgs e)
        {
            CheckedChanged(this, e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;

            var boxBackColor = uwfBoxBackDisableColor;
            var markColor = uwfMarkColor;
            
            borderPen.Color = uwfBorderDisableColor;
            
            if (Enabled)
            {
                if (uwfHovered)
                {
                    boxBackColor = uwfBoxBackHoverColor;
                    borderPen.Color = uwfBorderHoverColor;
                    markColor = uwfMarkHoverColor;
                }
                else
                {
                    boxBackColor = uwfBoxBackColor;
                    borderPen.Color = uwfBorderColor;
                }
            }

            var checkRectX = Padding.Left;
            var checkRectY = Padding.Top + Height / 2 - 6;
            var checkRectWH = 12;

            g.uwfFillRectangle(boxBackColor, checkRectX, checkRectY, checkRectWH, checkRectWH);
            g.DrawRectangle(borderPen, checkRectX, checkRectY, checkRectWH, checkRectWH);
            if (Checked)
                g.uwfDrawImage(uwfAppOwner.Resources.Checked, markColor, checkRectX, checkRectY, checkRectWH, checkRectWH);

            g.uwfDrawString(Text, Font, ForeColor, checkRectX + checkRectWH + 4, Padding.Top + 0, Width - 20, Height, TextAlign);

            if (uwfCanDrawTabDots && uwfDrawTabDots && Focused && !string.IsNullOrEmpty(Text))
            {
                if (measureText)
                    textSize = g.MeasureString(Text, Font);
                    
                g.DrawRectangle( uwfTabPen, checkRectX + checkRectWH + 2, (Height - textSize.Height) / 2 + 2, textSize.Width + 4, textSize.Height - 4);
            }
        }
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            measureText = true;
        }

        private void CheckBox_Click(object sender, EventArgs e)
        {
            Checked = !Checked;
            CheckedChanged(this, new EventArgs());
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelMonthCalendar.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelMonthCalendar : BaseExamplePanel
    {
        public override void Initialize()
        {
            this.Create<MonthCalendar>();
        }
    }
}


<|start_filename|>Assets/Core/MouseHook.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    /// <summary>
    /// implement your windows hook here.
    /// </summary>
    internal static class MouseHook
    {
        public static event MouseEventHandler MouseDown;
        [Obsolete("not supported yet")]
        public static event MouseEventHandler MouseMove;
        public static event MouseEventHandler MouseUp;
        [Obsolete("not supported yet")]
        public static event MouseEventHandler MouseWheel;
        
        public static void RaiseMouseDown(object sender, MouseEventArgs args)
        {
            var handler = MouseDown;
            if (handler != null)
                handler(sender, args);
        }
        public static void RaiseMouseMove(object sender, MouseEventArgs args)
        {
#pragma warning disable 618
            var handler = MouseMove;
#pragma warning restore 618
            if (handler != null)
                handler(sender, args);
        }
        public static void RaiseMouseWheel(object sender, MouseEventArgs args)
        {
#pragma warning disable 618
            var handler = MouseWheel;
#pragma warning restore 618
            if (handler != null)
                handler(sender, args);
        }
        public static void RaiseMouseUp(object sender, MouseEventArgs args)
        {
            var handler = MouseUp;
            if (handler != null)
                handler(sender, args);
        }
    }
}


<|start_filename|>Assets/Core/KeyboardHook.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    internal static class KeyboardHook
    {
        public static event KeyEventHandler KeyDown;
        public static event KeyEventHandler KeyUp;

        public static void RaiseKeyDown(object sender, KeyEventArgs e)
        {
            var handler = KeyDown;
            if (handler != null)
                handler(sender, e);
        }
        public static void RaiseKeyUp(object sender, KeyEventArgs e)
        {
            var handler = KeyUp;
            if (handler != null)
                handler(sender, e);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/IButtonControl.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public interface IButtonControl
    {
        DialogResult DialogResult { get; set; }

        void NotifyDefault(bool value);
        void PerformClick();
    }
}


<|start_filename|>Assets/System/Windows/Forms/TextBox.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class TextBox : Control
    {
        private bool customBackColor;
        private bool customForeColor;
        
        private Color backColor;
        private Color foreColor;
        private Color borderSingleColor = Color.FromArgb(100, 100, 100);
        
        private readonly Pen borderPen = new Pen(Color.White);
        private readonly bool styleInitialized;
        
        private char passwordChar = (char)0;
        private string passwordText;
        private string text;
        
        public TextBox()
        {
            text = string.Empty;
            
            BackColor = SystemColors.Window;
            BorderStyle = BorderStyle.Fixed3D;
            Padding = new Padding(2, 0, 2, 0);
            TextAlign = HorizontalAlignment.Left;
            
            uwfBorderColor = SystemColors.ActiveBorder;
            uwfBorderFocusedColor = Color.FromArgb(86, 157, 229);
            uwfBorderHoverColor = Color.FromArgb(126, 180, 234);

            styleInitialized = true;
        }

        public BorderStyle BorderStyle { get; set; }
        public bool Multiline { get; set; }
        public char PasswordChar
        {
            get { return passwordChar; }
            set
            {
                passwordChar = value;
                UpdatePasswordText();
            }
        }
        public bool ReadOnly { get; set; }
        public override string Text
        {
            get { return text; }
            set
            {
                if (text == value)
                    return;
                
                text = value;
                if (text == null)
                    text = string.Empty;
                
                UpdatePasswordText();
                OnTextChanged(EventArgs.Empty);
            }
        }
        public HorizontalAlignment TextAlign { get; set; }
        
        internal Color uwfBorderColor { get; set; }
        internal Color uwfBorderFocusedColor { get; set; }
        internal Color uwfBorderHoverColor { get; set; }

        protected override Size DefaultSize
        {
            get { return new Size(100, 24); }
        }

        public override string ToString()
        {
            // In future: move to TextBoxBase.
            var bs = base.ToString();
            var txt = Text;

            if (txt == null)
                txt = "";

            if (txt.Length > 40)
                txt = txt.Substring(0, 40) + "...";

            return bs + ", Text: " + txt;
        }

        protected override void OnBackColorChanged(EventArgs e)
        {
            base.OnBackColorChanged(e);

            if (styleInitialized)
                customBackColor = true;
            
            backColor = BackColor;
        }
        protected override void OnEnabledChanged(EventArgs e)
        {
            base.OnEnabledChanged(e);

            backColor = !customBackColor && !Enabled ? SystemColors.Control : BackColor;
            foreColor = !customForeColor && !Enabled ? SystemColors.GrayText : ForeColor;
        }
        protected override void OnForeColorChanged(EventArgs e)
        {
            base.OnForeColorChanged(e);

            if (styleInitialized)
                customForeColor = true;

            foreColor = ForeColor;
        }
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            if (Enabled && !ReadOnly)
                Cursor.Current = Cursors.IBeam;
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            Cursor.Current = Cursors.Default;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            
            var g = e.Graphics;
            var textX = Padding.Left;
            var textY = Padding.Top;
            var textW = Width - Padding.Horizontal;
            var textH = Height - Padding.Vertical;

            if (Enabled && Focused)
            {
                string tempText;

                if (shouldFocus)
                    g.uwfFocusNext();

                if (passwordChar == 0)
                {
                    if (!Multiline)
                        tempText = g.uwfDrawTextField(Text, Font, foreColor, textX, textY, textW, textH, TextAlign);
                    else
                        tempText = g.uwfDrawTextArea(Text, Font, foreColor, textX, textY, textW, textH);
                }
                else
                    tempText = g.uwfDrawPasswordField(Text, Font, foreColor, textX, textY, textW, textH, TextAlign);

                if (shouldFocus)
                {
                    shouldFocus = false;
                    g.uwfFocus();
                }

                if (!ReadOnly)
                    Text = tempText;
            }
            else
            {
                var paintText = Text;

                if (passwordChar != 0)
                    paintText = passwordText;

                if (Multiline)
                    g.uwfDrawString(paintText, Font, foreColor, textX, textY, textW, textH, ContentAlignment.TopLeft);
                else
                    g.uwfDrawString(paintText, Font, foreColor, textX, textY, textW, textH, TextAlign);
            }

            switch (BorderStyle)
            {
                case BorderStyle.None:
                    break;
                
                case BorderStyle.FixedSingle:
                    borderPen.Color = borderSingleColor;
                    g.DrawRectangle(borderPen, 0, 0, Width, Height);
                    break;
                
                case BorderStyle.Fixed3D:
                    borderPen.Color = Color.White;
                    g.DrawRectangle(borderPen, 1, 1, Width - 2, Height - 2);
                    
                    borderPen.Color = Focused ? uwfBorderFocusedColor : uwfHovered ? uwfBorderHoverColor : uwfBorderColor;
                    g.DrawRectangle(borderPen, 0, 0, Width, Height);
                    break;
                
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            e.Graphics.uwfFillRectangle(backColor, 0, 0, Width, Height);
        }

        private static string GetPasswordString(string from)
        {
            return string.IsNullOrEmpty(from) ? string.Empty : new string('*', from.Length);
        }
        private void UpdatePasswordText()
        {
            if (passwordChar != 0)
                passwordText = GetPasswordString(Text);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ListSortDirection.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum ListSortDirection
    {
        Ascending = 0,
        Descending = 1,
    }
}


<|start_filename|>Assets/System/Windows/Forms/ResizeButton.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    internal sealed class ResizeButton : Button, IResizableControl
    {
        private readonly Form owner;
        private bool pressed;

        public ResizeButton(Form form, Bitmap img)
        {
            owner = form;

            Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            Image = img;
            uwfImageColor = Color.White;
            uwfImageHoverColor = Color.FromArgb(0, 122, 204);
            Text = "";
            Height = img.Height;
            Width = img.Width;

            SetStyle(ControlStyles.Selectable, false);

            BackColor = Color.Transparent;
            uwfBorderColor = Color.Transparent;
            uwfHoverColor = Color.Transparent;
            uwfBorderHoverColor = Color.Transparent;
            uwfBorderSelectColor = Color.Transparent;

            MouseHook.MouseUp += Owner_UpClick;
        }

        public ControlResizeTypes GetResizeAt(Point mclient)
        {
            return ControlResizeTypes.RightDown;
        }

        protected override void Dispose(bool release_all)
        {
            base.Dispose(release_all);

            MouseHook.MouseUp -= Owner_UpClick;
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            pressed = true;

            owner.SetResize(ControlResizeTypes.RightDown);
        }
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            Cursor.CurrentSystem = Cursors.SizeNWSE;
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            if (pressed == false)
                Cursor.CurrentSystem = Cursors.Default;
        }

        private void Owner_UpClick(object sender, MouseEventArgs e)
        {
            if (pressed)
                Cursor.CurrentSystem = Cursors.Default;
            pressed = false;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/SizeGripStyle.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum SizeGripStyle
    {
        Auto,
        Show,
        Hide,
    }
}


<|start_filename|>Assets/System/Windows/Forms/TreeNodeStates.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum TreeNodeStates
    {
        Selected = 1,
        Grayed = 2,
        Checked = 8,
        Focused = 16,
        Default = 32,
        Hot = 64,
        Marked = 128,
        Indeterminate = 256,
        ShowKeyboardCues = 512,
    }
}


<|start_filename|>Assets/Unity/Views/Editor.cs<|end_filename|>
﻿namespace Unity.Views
{
    using System;
    using System.Globalization;
    using System.Windows.Forms;

    using Unity.API;

    using UnityEngine;

    public static class Editor
    {
        private static readonly string[] boolOnOff = { "On", "Off" };

        public static bool WinFormsCompatible { get; set; }

        private static float _width { get; set; }
        private static float _nameWidth { get; set; }
        private static float _contentWidth { get; set; }

        public static void BeginGroup(float width, string style = "Box")
        {
            _width = width;
            _nameWidth = 160;
            _contentWidth = width - _nameWidth;

            if (string.IsNullOrEmpty(style))
                GUILayout.BeginVertical();
            else
                GUILayout.BeginVertical(style);
        }
        public static void BeginHorizontal()
        {
            if (_width > 0)
                GUILayout.BeginHorizontal(GUILayout.Width(_width));
            else
                GUILayout.BeginHorizontal();
        }
        public static void BeginVertical()
        {
            GUILayout.BeginVertical();
        }
        public static void BeginVertical(string style)
        {
            if (string.IsNullOrEmpty(style))
                GUILayout.BeginVertical();
            else
                GUILayout.BeginVertical(style);
        }
        public static void BeginVertical(GUIStyle style)
        {
            GUILayout.BeginVertical(style);
        }
        public static void EndGroup()
        {
            GUILayout.EndVertical();
        }
        public static void EndHorizontal()
        {
            GUILayout.EndHorizontal();
        }
        public static void EndVertical()
        {
            GUILayout.EndVertical();
        }
        public static EditorValue<bool> BooleanField(string name, bool value)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            var boolBuffer = GUILayout.Toolbar(value ? 0 : 1, boolOnOff, GUILayout.Width(_contentWidth)) != 1;
            GUILayout.EndHorizontal();

            return new EditorValue<bool>(boolBuffer, boolBuffer != value);
        }
        public static bool Button(string name, string text)
        {
            if (name == null)
                name = "null";

            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            var boolResult = GUILayout.Button(text, GUILayout.Width(_contentWidth));
            GUILayout.EndHorizontal();

            return boolResult;
        }
        public static bool Button(string text)
        {
            return GUILayout.Button(text);
        }
        public static bool Button(string text, int width)
        {
            return GUILayout.Button(text, GUILayout.Width(width));
        }
        public static void ColorField(string name, System.Drawing.Color value, Action<System.Drawing.Color> setColor)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            if (WinFormsCompatible)
            {
                if (Button(value.ToString()))
                {
                    var colorForm = new ColorPickerForm();
                    colorForm.Color = value;
                    colorForm.Show();
                    colorForm.ColorChanged += (s, a) =>
                    {
                        if (setColor != null)
                            setColor.Invoke(colorForm.Color);
                    };
                }
            }

#if UNITY_EDITOR
            else
            {
                var colorBuffer = UnityEditor.EditorGUILayout.ColorField(value.ToUnityColor(), GUILayout.Width(_contentWidth)).ToColor();
                if (colorBuffer != value && setColor != null)
                    setColor.Invoke(colorBuffer);
            }

#endif
            GUILayout.EndHorizontal();
        }
        public static EditorValue<Enum> EnumField(string name, Enum value)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            var enumBuffer = value;
            if (WinFormsCompatible)
            {
            }

#if UNITY_EDITOR
            else
                enumBuffer = UnityEditor.EditorGUILayout.EnumPopup(value, GUILayout.Width(_contentWidth));
#endif
            GUILayout.EndHorizontal();

            return new EditorValue<Enum>(enumBuffer, !Equals(enumBuffer, value));
        }
        public static bool Foldout(string name, bool value)
        {
            if (WinFormsCompatible)
            {
                return Toggle(name, value);
            }

#if UNITY_EDITOR
            else
                return UnityEditor.EditorGUILayout.Foldout(value, name);
#else
            return false;
#endif
        }
        public static void Header(string text)
        {
            GUI.skin.label.fontStyle = UnityEngine.FontStyle.Bold;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUI.Label(new Rect(0, 0, _width, 36), text);

            GUI.skin.label.fontStyle = UnityEngine.FontStyle.Normal;
            GUI.skin.label.alignment = TextAnchor.UpperLeft;
        }
        public static void Label(object value)
        {
            if (value != null)
                GUILayout.Label(value.ToString());
        }
        public static void Label(string name, object value)
        {
            string valueString = "null";
            if (value != null) valueString = value.ToString();
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            GUILayout.Label(valueString, GUILayout.Width(_contentWidth));
            GUILayout.EndHorizontal();
        }
        public static EditorValue<int[]> IntField(string name, params int[] value)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));

            bool changed = false;
            int[] intBuffer = new int[value.Length];
            for (int i = 0; i < value.Length; i++)
            {
                if (WinFormsCompatible)
                {
                    var valueBuffer = GUILayout.TextField(value[i].ToString(), GUILayout.Width(_contentWidth / value.Length));
                    int.TryParse(valueBuffer, out intBuffer[i]);
                }

#if UNITY_EDITOR
                else
                    intBuffer[i] = UnityEditor.EditorGUILayout.IntField(value[i], GUILayout.Width(_contentWidth / value.Length - value.Length));
#endif
                if (intBuffer[i] != value[i])
                    changed = true;
            }

            GUILayout.EndHorizontal();

            return new EditorValue<int[]>(intBuffer, changed);
        }
        public static EditorValue<int> MaskField(string name, int value, string[] options)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            var buffer = value;
            if (WinFormsCompatible)
            {
            }

#if UNITY_EDITOR
            else
                buffer = UnityEditor.EditorGUILayout.MaskField(value, options);
#endif
            GUILayout.EndHorizontal();

            return new EditorValue<int>(buffer, buffer != value);
        }
        public static void NewLine(int cnt)
        {
            for (int i = 0; i < cnt; i++)
                GUILayout.Label(string.Empty);
        }
        public static EditorValue<UnityEngine.Object> ObjectField(string name, UnityEngine.Object value, Type type)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            var objectBuffer = value;
            if (WinFormsCompatible)
            {
            }

#if UNITY_EDITOR
            else
                objectBuffer = UnityEditor.EditorGUILayout.ObjectField(value, type, true, GUILayout.Width(_contentWidth));
#endif
            GUILayout.EndHorizontal();

            return new EditorValue<UnityEngine.Object>(objectBuffer, objectBuffer != value);
        }
        public static EditorValue<int> Popup(string name, int index, string[] values)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            int intBuffer = 0;
            if (WinFormsCompatible)
            {
            }

#if UNITY_EDITOR
            else
                intBuffer = UnityEditor.EditorGUILayout.Popup(index, values, GUILayout.Width(_contentWidth - 8));
#endif
            GUILayout.EndHorizontal();

            return new EditorValue<int>(intBuffer, intBuffer != index);
        }
        public static EditorValue<float> Slider(string name, float value, float min, float max)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            float floatBuffer = value;
            if (WinFormsCompatible)
            {
                floatBuffer = GUILayout.HorizontalSlider(value, min, max, GUILayout.Width(_contentWidth - 96));
                GUILayout.TextField(floatBuffer.ToString(CultureInfo.InvariantCulture), GUILayout.Width(32));
            }

#if UNITY_EDITOR
            else
                floatBuffer = UnityEditor.EditorGUILayout.Slider(value, min, max, GUILayout.Width(_contentWidth));
#endif
            GUILayout.EndHorizontal();

            return new EditorValue<float>(floatBuffer, floatBuffer != value);
        }
        public static EditorValue<string> TextField(string name, string value)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            if (value != null && value.Length > 1024)
            {
                GUILayout.TextField(value.Substring(0, 1024) + "...", GUILayout.Width(_contentWidth));
                GUILayout.EndHorizontal();
                return new EditorValue<string>(value, false);
            }
            var textBuffer = GUILayout.TextField(value, GUILayout.Width(_contentWidth));
            GUILayout.EndHorizontal();

            return new EditorValue<string>(textBuffer, textBuffer != value);
        }
        public static bool Toggle(string name, bool value)
        {
            return GUILayout.Toggle(value, name, GUILayout.Width(_width));
        }
        public static void SetBackColor(System.Drawing.Color color)
        {
            GUI.backgroundColor = color.ToUnityColor();
        }
    }
}


<|start_filename|>Assets/System/Drawing/Pen.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Drawing.Drawing2D;

    public sealed class Pen : IDisposable, ICloneable
    {
        public Pen(Color color)
        {
            Color = color;
            Width = 1;
        }
        
        public Pen(Color color, float width)
        {
            Color = color;
            Width = width;
        }

        ~Pen() 
        {
            Dispose(false);
        }
        
        public Color Color { get; set; }
        public DashStyle DashStyle { get; set; }
        public float Width { get; set; }

        public object Clone()
        {
            var pen = new Pen(Color);
            pen.DashStyle = DashStyle;
            pen.Width = Width;
            return pen;
        }
        
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            // Nothing to dispose.
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/PaintEventHandler.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public delegate void PaintEventHandler(object sender, PaintEventArgs e);
}


<|start_filename|>Assets/System/Drawing/SystemColors.cs<|end_filename|>
﻿namespace System.Drawing
{
    public static class SystemColors
    {
        public static readonly Color ActiveBorder = new Color(KnownColor.ActiveBorder, 0xFFB4B4B4);
        public static readonly Color ActiveCaption = new Color(KnownColor.ActiveCaption, 0xFF99B4D1);
        public static readonly Color ActiveCaptionText = new Color(KnownColor.ActiveCaptionText, 0xFF000000);
        public static readonly Color AppWorkspace = new Color(KnownColor.AppWorkspace, 0xFFABABAB);
        public static readonly Color ButtonFace = new Color(KnownColor.ButtonFace, 0xFFF0F0F0);
        public static readonly Color ButtonHighlight = new Color(KnownColor.ButtonHighlight, 0xFFFFFFFF);
        public static readonly Color ButtonShadow = new Color(KnownColor.ButtonShadow, 0xFFA0A0A0);
        public static readonly Color Control = new Color(KnownColor.Control, 0xFFF0F0F0);
        public static readonly Color ControlDark = new Color(KnownColor.ControlDark, 0xFFA0A0A0);
        public static readonly Color ControlDarkDark = new Color(KnownColor.ControlDarkDark, 0xFF696969);
        public static readonly Color ControlLight = new Color(KnownColor.ControlLight, 0xFFE3E3E3);
        public static readonly Color ControlLightLight = new Color(KnownColor.ControlLightLight, 0xFFFFFFFF);
        public static readonly Color ControlText = new Color(KnownColor.ControlText, 0xFF000000);
        public static readonly Color Desktop = new Color(KnownColor.Desktop, 0xFF000000);
        public static readonly Color GradientActiveCaption = new Color(KnownColor.GradientActiveCaption, 0xFFB9D1EA);
        public static readonly Color GradientInactiveCaption = new Color(KnownColor.GradientInactiveCaption, 0xFFD7E4F2);
        public static readonly Color GrayText = new Color(KnownColor.GrayText, 0xFF6D6D6D);
        public static readonly Color Highlight = new Color(KnownColor.Highlight, 0xFF3399FF);
        public static readonly Color HighlightText = new Color(KnownColor.HighlightText, 0xFFFFFFFF);
        public static readonly Color HotTrack = new Color(KnownColor.HotTrack, 0xFF0066CC);
        public static readonly Color InactiveBorder = new Color(KnownColor.InactiveBorder, 0xFFF4F7FC);
        public static readonly Color InactiveCaption = new Color(KnownColor.InactiveCaption, 0xFFBFCDDB);
        public static readonly Color InactiveCaptionText = new Color(KnownColor.InactiveCaptionText, 0xFF000000);
        public static readonly Color Info = new Color(KnownColor.Info, 0xFFFFFFFF);
        public static readonly Color InfoText = new Color(KnownColor.InfoText, 0xFF000000);
        public static readonly Color Menu = new Color(KnownColor.Menu, 0xFFF0F0F0);
        public static readonly Color MenuBar = new Color(KnownColor.MenuBar, 0xFFF0F0F0);
        public static readonly Color MenuHighlight = new Color(KnownColor.MenuHighlight, 0xFF3399FF);
        public static readonly Color MenuText = new Color(KnownColor.MenuText, 0xFF000000);
        public static readonly Color ScrollBar = new Color(KnownColor.ScrollBar, 0xFFC8C8C8);
        public static readonly Color Window = new Color(KnownColor.Window, 0xFFFFFFFF);
        public static readonly Color WindowFrame = new Color(KnownColor.WindowFrame, 0xFF646464);
        public static readonly Color WindowText = new Color(KnownColor.WindowText, 0xFF000000);
        
        internal static readonly Color uwfControlText = new Color(KnownColor.ControlText, 0xFF404040);
        internal static readonly Color uwfInfoText = new Color(KnownColor.InfoText, 0xFF404040);
    }
}


<|start_filename|>Assets/System/Windows/Forms/Label.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class Label : Control
    {
        private bool adjustSize;

        public Label()
        {
            base.AutoSize = true;
            BackColor = Color.Transparent;
            TabStop = false;
            TextAlign = ContentAlignment.TopLeft;

            SetStyle(ControlStyles.FixedHeight | ControlStyles.Selectable, false);
            SetStyle(ControlStyles.ResizeRedraw, true);
        }

        public override bool AutoSize
        {
            get
            {
                return base.AutoSize;
            }
            set
            {
                if (AutoSize == value)
                    return;

                base.AutoSize = value;
                AdjustSize();
            }
        }
        public virtual BorderStyle BorderStyle { get; set; }
        public ContentAlignment TextAlign { get; set; }

        protected override Padding DefaultPadding
        {
            get { return new Padding(4, 0, 4, 0); }
        }
        protected override Size DefaultSize
        {
            get { return new Size(100, 23); } // Autosize ? Preferred height.
        }

        internal void AdjustSize()
        {
            adjustSize = AutoSize;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;
            var p = Padding;
            var w = Width;
            var h = Height;

            if (adjustSize)
            {
                var size = g.MeasureString(Text, Font);
                Size = new Size((int)size.Width + p.Horizontal, (int)size.Height + p.Vertical);
                adjustSize = false;
            }

            g.uwfFillRectangle(BackColor, 0, 0, w, h);
            g.uwfDrawString(Text, Font, ForeColor, p.Left, p.Top, w - p.Horizontal, h - p.Vertical, TextAlign);

            ControlPaint.PrintBorder(g, ClientRectangle, BorderStyle, Border3DStyle.SunkenOuter);
        }
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            AdjustSize();
        }
    }
}


<|start_filename|>Assets/Controls/BitmapLabel.cs<|end_filename|>
﻿namespace Unity.Controls
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    /// <summary>
    /// Less allocation, slower baking.
    /// Multiline not supported yet.
    /// </summary>
    public class BitmapLabel : Control
    {
        internal readonly BitmapText bmText;
        
        public float Scale
        {
            get { return bmText.Scale; }
            set { bmText.Scale = value; }
        }
        public bool ShowRects { get; set; }
        public override string Text
        {
            get { return bmText.Text; }
            set
            {
                bmText.Text = value;
                Refresh();
            }
        }

        public BitmapLabel(BitmapFont font)
        {
            if (font == null || font.Loaded == false)
                throw new ArgumentNullException("font");

            bmText = new BitmapText(font);

            AutoSize = true;
            Size = new Size(120, 20);
        }
        
        public override void Refresh()
        {
            base.Refresh();

            bmText.Apply();
            if (AutoSize)
                Size = new Size(bmText.Width, bmText.Height);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.uwfFillRectangle(BackColor, 0, 0, Width, Height);
            e.Graphics.uwfDrawImage(bmText, ForeColor, 0, 0, bmText.Width, bmText.Height);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/TreeNode.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class TreeNode
    {
        public static readonly Color DEFAULT_FORE_COLOR = Color.Empty;

        internal int index;
        internal int indexY;
        internal TreeNode parent;
        internal TreeView treeView;
        internal TreeNodeCollection nodes;
        internal int textWidth;
        internal string tagString;

        private bool expanded;
        private Color foreColor = DEFAULT_FORE_COLOR;
        private int imageIndex = -1;
        private string text;
        private bool visible = true;

        public TreeNode() : this(string.Empty, null)
        { }
        
        public TreeNode(string text) : this(text, null)
        {
            this.text = text;
        }
        
        public TreeNode(string text, TreeNode[] children)
        {
            ImageColor = Color.White;
            Enabled = true;
            BackColor = Color.Transparent;
            ImageIndex_Expanded = -1;
            ImageIndex_Collapsed = -1;
            this.text = text;

            if (children != null)
                Nodes.AddRange(children);
        }
        
        internal TreeNode(TreeView treeView) : this(string.Empty)
        {
            this.treeView = treeView;
        }

        public Color BackColor { get; set; }
        public Rectangle Bounds { get; internal set; }
        public bool Enabled { get; set; }
        public TreeNode FirstNode
        {
            get
            {
                if (Nodes.Count == 0) return null;

                return nodes[0];
            }
        }
        public Color ForeColor
        {
            get { return foreColor; }
            set { foreColor = value; }
        }
        public Color ImageColor { get; set; }
        public int ImageIndex
        {
            get
            {
                var value = imageIndex;
                if (expanded)
                {
                    if (ImageIndex_Expanded >= 0)
                        value = ImageIndex_Expanded;
                }
                else if (ImageIndex_Collapsed >= 0)
                    value = ImageIndex_Collapsed;

                return value;
            }
            set { imageIndex = value; }
        }
        public int ImageIndex_Collapsed { get; set; }
        public int ImageIndex_Expanded { get; set; }
        public int Index { get { return index; } }
        public bool IsExpanded { get { return expanded; } internal set { expanded = value; } }
        public bool IsSelected { get { return TreeView.SelectedNode == this; } }
        public bool IsVisible { get { return visible; } }
        public TreeNode LastNode
        {
            get
            {
                if (Nodes.Count == 0) return null;

                return nodes[nodes.Count - 1];
            }
        }
        public string Name { get; set; }
        public TreeNode NextNode
        {
            get
            {
                if (index + 1 < parent.Nodes.Count)
                    return parent.Nodes[index + 1];

                return null;
            }
        }
        public Font NodeFont { get; set; }
        public TreeNodeCollection Nodes
        {
            get
            {
                if (nodes == null)
                    nodes = new TreeNodeCollection(this);
                return nodes;
            }
        }
        public TreeNode Parent { get { return parent; } }
        public TreeNode PrevNode
        {
            get
            {
                if (index - 1 >= 0)
                    return parent.Nodes[index - 1];

                return null;
            }
        }
        public object Tag { get; set; }
        public string Text
        {
            get { return text; }
            set
            {
                text = value;
                textWidth = 0;
            }
        }
        public string ToolTipText { get; set; }
        public TreeView TreeView
        {
            get
            {
                if (treeView == null && parent != null)
                    treeView = parent.TreeView;
                return treeView;
            }
        }

        internal Color ForeColorInternal
        {
            get { return ForeColor.IsEmpty ? TreeView.ForeColor : ForeColor; }
        }
        internal Font NodeFontInternal
        {
            get
            {
                if (NodeFont != null)
                    return NodeFont;

                return TreeView.Font;
            }
        }
        internal Color SelectColorInternal
        {
            get
            {
                if (!IsSelected) return TreeView.uwfItemHoveredColor;
                
                if (!TreeView.Focused)
                    return TreeView.uwfItemSelectedUnfocusedColor;

                return TreeView.uwfItemSelectedColor;

            }
        }

        public void Collapse()
        {
            expanded = false;
            TreeView.Refresh();
        }
        public void EnsureVisible()
        {
            treeView.EnsureVisible(this);
        }
        public void Expand()
        {
            expanded = true;
            TreeView.Refresh();
        }
        public void ExpandAll()
        {
            ExpandAllInternal();
            TreeView.Refresh();
        }
        public void Remove()
        {
            Remove(true);
        }
        public void Toggle()
        {
            if (expanded) Collapse();
            else Expand();
        }

        public override string ToString()
        {
            return "TreeNode: " + (Text == null ? string.Empty : Text);
        }

        internal void CollapseInternal()
        {
            expanded = false;
        }
        internal void ExpandAllInternal()
        {
            expanded = true;
            var nodesCount = Nodes.Count;
            for (int i = 0; i < nodesCount; i++)
            {
                var node = Nodes[i];
                if (node.IsExpanded) continue;

                node.expanded = true;
                node.ExpandAllInternal();
            }
        }
        internal int GetXIndex()
        {
            return GetXIndex(this, 0);
        }
        internal int GetYIndex()
        {
            return GetYIndex(this, 0);
        }
        internal void Remove(bool notify)
        {
            if (parent != null)
            {
                parent.Nodes.RemoveAt(index);
                parent = null;
            }

            treeView = null;
        }

        private static int GetVisibleNodesAmount(TreeNode node, int currentAmount)
        {
            if (node.IsVisible) currentAmount++;
            else return currentAmount;

            if (node.IsExpanded)
                for (int i = 0; i < node.Nodes.Count; i++)
                    currentAmount = GetVisibleNodesAmount(node.Nodes[i], currentAmount);

            return currentAmount;
        }
        private int GetXIndex(TreeNode currentNode, int currentX)
        {
            if (currentNode.parent == null) return currentX;

            return GetXIndex(currentNode.parent, currentX) + 1;
        }
        private int GetYIndex(TreeNode currentNode, int currentY)
        {
            if (currentNode.parent == null) return currentY;

            if (currentNode == TreeView.root) return --currentY; // was currentY--, should check it.

            if (currentNode.parent != TreeView.root && currentNode.parent.IsVisible) currentY++;

            for (int i = 0; i < currentNode.index; i++)
                currentY += GetVisibleNodesAmount(currentNode.parent.Nodes[i], 0);

            return GetYIndex(currentNode.parent, currentY);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/SafeNativeMethods.cs<|end_filename|>
#if UNITY_STANDALONE_WIN
#define KEYBOARD_LAYOUT_SUPPORTED
#endif

namespace System.Windows.Forms
{
    internal static class SafeNativeMethods
    {
#if KEYBOARD_LAYOUT_SUPPORTED
        
        [System.Runtime.InteropServices.DllImport("user32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
        [System.Runtime.Versioning.ResourceExposure(System.Runtime.Versioning.ResourceScope.None)]
        public static extern IntPtr GetKeyboardLayout(int dwLayout);
        
#endif
    }
}

<|start_filename|>Assets/Controls/Highcharts/SeriesAreaSolid.cs<|end_filename|>
namespace Highcharts
{
    using System.Drawing;
    
    public class SeriesAreaSolid : Series
    {
        public SeriesAreaSolid() : this("")
        { }

        public SeriesAreaSolid(string name) : base(name)
        { }

        protected override void OnPaint(Graphics g, Rectangle clipRectangle)
        {
            if (data.Count == 1)
            {
                SeriesPaint.PaintPoint(this, g, clipRectangle, 0);
                return;
            }
            
            var valueRange = GetValueRange();
            var xStep = GetXStep();
            var areaColorAlpha = collection.GetColorAlpha();
            var areaColor = Color.FromArgb(areaColorAlpha, color);
            
            var prevValue = data[0];
            var prevValueX = GetXFromIndex(0, xStep, clipRectangle);
            var prevValueY = GetYFromValue(prevValue, valueRange, clipRectangle);
           
            for (float dataIterator = pointInterval; dataIterator < data.Count; dataIterator += pointInterval)
            {
                double currentValue = data[(int) dataIterator];

                float currentValueX = GetXFromIndex(dataIterator, xStep, clipRectangle);
                float currentValueY = GetYFromValue(currentValue, valueRange, clipRectangle);

                float width = currentValueX - prevValueX;

                g.uwfFillRectangle(areaColor, prevValueX, prevValueY, width, clipRectangle.Bottom - prevValueY);
                
                if (dataIterator + pointInterval >= data.Count)
                    g.uwfFillRectangle(areaColor, currentValueX, currentValueY, xStep, clipRectangle.Bottom - currentValueY);

                prevValueX = currentValueX;
                prevValueY = currentValueY;
                
                SeriesPaint.PaintHoveredValueRect(this, g, currentValueX, currentValueY, xStep);
            }
        }

        protected override void OnPaintIcon(Graphics g, Rectangle clipRectangle)
        {
            g.uwfFillRectangle(color, clipRectangle.Left + 4, clipRectangle.Top + 8, 8, 8);
        }
    }
}

<|start_filename|>Assets/Examples/Panels/PanelTreeView.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Drawing;
    using System.Windows.Forms;
    
    public class PanelTreeView : BaseExamplePanel
    {
        public override void Initialize()
        {
            // Only affects the speed of refreshing the tree.
            // It's also possible to fill the tree smoothly every frame.
            var nodesCount = 500000; 

            var label = this.Create<Label>();
            var tree = this.Create<TreeView>(); 
            tree.Size = new Size(320, 400);

            var watch = System.Diagnostics.Stopwatch.StartNew();
            
            for (int i = 0; i < nodesCount; i++)
                tree.Nodes.Add("node " + i);
            
            watch.Stop();

            label.Text = nodesCount + " nodes created in " + (int) watch.ElapsedMilliseconds + " ms.";
            
            tree.Refresh();
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/ContainerControl.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections.Generic;

    [Serializable]
    public class ContainerControl : ScrollableControl, IContainerControl
    {
        private Control selectedControl;

        public Control ActiveControl { get; set; }

        public bool ActivateControl(Control active)
        {
            throw new NotImplementedException();
        }
        
        internal void RaiseProcessTabKey(bool forward, Control selectedControl)
        {
            this.selectedControl = selectedControl;
            ProcessTabKey(forward);
        }

        protected virtual bool ProcessTabKey(bool forward)
        {
            if (forward)
                NextTabControl(selectedControl);
            else
                PrevTabControl(selectedControl);

            return true;
        }

        // TODO: far from perfect. Need to remember current focused control and it's tab index.
        internal static void FillListWithPossibleControls(Control control, List<Control> list)
        {
            for (int i = 0; i < control.Controls.Count; i++)
            {
                var c = control.Controls[i];
                if (!c.Visible || !c.Enabled || !c.TabStop || c.IsDisposed) 
                    continue;
                
                list.Add(c);
                FillListWithPossibleControls(c, list);
            }
        }
        
        private static int TabComparison(Control c1, Control c2)
        {
            if (c1.TabIndex >= 0 || c2.TabIndex >= 0)
                return c1.TabIndex.CompareTo(c2.TabIndex);

            var c1Location = c1.Location;
            var c2Location = c2.Location;

            if (c1Location.Y != c2Location.Y)
                return c1Location.Y.CompareTo(c2Location.Y);
            if (c1Location.X == c2Location.X)
                return 0;

            return c1Location.X.CompareTo(c2Location.X);
        }
        private void NextTabControl(Control control)
        {
            var controlForm = Application.GetRootControl(control) as Form;
            if (controlForm == null || controlForm.Controls.Count <= 0) return;

            var formControls = new List<Control>();
            
            FillListWithPossibleControls(controlForm, formControls);

            var possibleControls = formControls.FindAll(x => x.CanSelect);
            if (possibleControls.Count == 0) return;

            for (int i = 0; i < possibleControls.Count; i++)
                possibleControls[i].uwfDrawTabDots = true;

            possibleControls.Sort(TabComparison);

            int controlIndex = possibleControls.FindIndex(x => x == control);

            var nextControlIndex = controlIndex + 1;
            if (nextControlIndex >= possibleControls.Count)
                nextControlIndex = 0;

            var nextControl = possibleControls[nextControlIndex];
            nextControl.Focus();
            
            EnsureVisible(nextControl);
        }
        private void PrevTabControl(Control control)
        {
            var controlForm = Application.GetRootControl(control) as Form;
            if (controlForm == null || controlForm.Controls.Count <= 0) return;

            var formControls = new List<Control>();
            
            FillListWithPossibleControls(controlForm, formControls);

            var possibleControls = formControls.FindAll(x => x.CanSelect);
            if (possibleControls.Count == 0) return;
            
            for (int i = 0; i < possibleControls.Count; i++)
                possibleControls[i].uwfDrawTabDots = true;

            possibleControls.Sort(TabComparison);

            int controlIndex = possibleControls.FindIndex(x => x == control);

            var nextControlIndex = controlIndex - 1;
            if (nextControlIndex < 0)
                nextControlIndex = possibleControls.Count - 1;

            var nextControl = possibleControls[nextControlIndex];
            nextControl.Focus();
            
            EnsureVisible(nextControl);
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelChart.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    using Highcharts;
    
    public class PanelChart : BaseExamplePanel
    {
        private double x;
        private double xStep = .02d;
        
        private Timer timer;
        
        public override void Initialize()
        {
            this.Create<Label>("Press LMB on the legend button to enable/disable series, press RMB to show the context menu.");
            
            var seriesSin = new SeriesAreaSolidOutline("Sin");
            var seriesCos = new SeriesAreaSolidOutline("Cos");
            var seriesX = new SeriesAreaSolidOutline("Rounded X");
            
            var chart = this.Create<Highchart>();
            chart.fixedMin = -2; // Set plot min value.
            chart.Size = new Size(480, 320);
            chart.title.text = "Test chart";
            chart.subtitle.text = "(updating every frame)";
            chart.legend.itemHoverStyle = new LegendItemStyle(Color.FromArgb(0, 122, 204));
            //chart.plotOptions.linearGradient = true;
            //chart.plotOptions.linearGradientMaterial = UnitWinFormsExamples.s_chartGradient; // Can't make clipping working for this shader.
            chart.series.Add(seriesSin);
            chart.series.Add(seriesCos);
            chart.series.Add(seriesX);
            chart.Refresh(); // To update plot.

            // Set custom series colors. Colors are updating when new series is added to the chart.
            seriesSin.color = Color.FromArgb(205, 196, 67);
            seriesCos.color = Color.FromArgb(235, 101, 79);
            seriesX.color = Color.Gray;
            
            timer = new Timer();
            timer.Interval = 16; // Update every frame (1000 msec / 60 fps = 16.(6) frames needs to be updated per 1 second).
            timer.Tick += (sender, args) =>
            {
                var sin = Math.Truncate((Math.Sin(x) + 1) * 100) / 100;
                var cos = Math.Truncate((Math.Cos(x) / 2) * 100) / 100;
                var sx = Math.Truncate((Math.Floor(x * 2) / 6) * 100) / 100;
                
                seriesSin.data.Add(sin);
                seriesCos.data.Add(cos);
                seriesX.data.Add(sx);
                
                // Limit data.
                if (seriesSin.data.Count > 100)
                {
                    seriesSin.data.RemoveAt(0);
                    seriesCos.data.RemoveAt(0);
                    seriesX.data.RemoveAt(0);
                }
                
                chart.RecalcCategories();
                chart.UpdatePlot();

                // Update X.
                x += xStep;
                if (x > Math.PI)
                    x = -Math.PI;
            };
            timer.Start();
        }

        protected override void Dispose(bool release_all)
        {
            base.Dispose(release_all);
            
            timer.Dispose();
            x = 0;
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/FileDialog.cs<|end_filename|>
﻿#if UNITY_STANDALONE || UNITY_ANDROID
#define IO_SUPPORTED
#endif

namespace System.Windows.Forms
{
    using System.Collections.Generic;
    using System.Drawing;
    using System.Globalization;
    using System.Linq;

    public abstract class FileDialog : Form
    {
        internal static Size savedFormSize = new Size(720, 400);

        internal FileRenderer fileRenderer;
        internal Button       buttonOk;
        internal Button       buttonCancel;
        internal Button       buttonBack;
        internal Button       buttonUp;
        internal Button       buttonRefresh;
        internal ComboBox     comboFilter;
        internal Label        labelFilename;
        internal TextBox      textBoxPath;
        internal TextBox      textBoxFilename;           
        
        private readonly bool handleFormSize;
        private readonly Pen splitterPen = new Pen(Color.FromArgb(232, 232, 232));
        private string initialDir;
        private string filename;
        
        internal FileDialog()
        {
#if !IO_SUPPORTED
            throw new NotSupportedException();
#endif

            BackColor = Color.White;
            Filter = "All files|*.*";
            MinimumSize = new Drawing.Size(240, 240);
            KeyPreview = true;
            Padding = new Padding(12, 12, 12, 12);
            SizeGripStyle = SizeGripStyle.Show;
            Text = "File Dialog";

            handleFormSize = false;
            Size = savedFormSize;
            handleFormSize = true;

            // Button Back.
            buttonBack = new Button();
            buttonBack.BackgroundImageLayout = ImageLayout.Center;
            buttonBack.Enabled = false;
            buttonBack.Font = new Drawing.Font("Arial", 16, FontStyle.Bold);
            buttonBack.Image = ApplicationResources.Images.FileDialogBack;
            buttonBack.Location = new Point(Padding.Left, uwfHeaderHeight + Padding.Top);
            buttonBack.BackColor = Color.Transparent;
            buttonBack.uwfBorderColor = Color.Transparent;
            buttonBack.uwfBorderDisableColor = Color.Transparent;
            buttonBack.uwfImageColor = Color.Gray;
            buttonBack.uwfImageHoverColor = buttonBack.uwfImageColor;
            buttonBack.uwfImageDisabledColor = Color.FromArgb(207, 207, 207);
            buttonBack.Size = new Size(22, 22);
            if (buttonBack.Image == null) buttonBack.Text = "◀";
            buttonBack.Click += (sender, args) => ButtonBack();
            Controls.Add(buttonBack);

            var buttonBackTooltip = new ToolTip();
            buttonBackTooltip.SetToolTip(buttonBack, "Back (ALT + Left Arrow)");
            
            // Button Up.
            buttonUp = new Button();
            buttonUp.BackgroundImageLayout = ImageLayout.Center;
            buttonUp.Font = new Drawing.Font("Arial", 16, FontStyle.Bold);
            buttonUp.Image = ApplicationResources.Images.FileDialogUp;
            buttonUp.Location = new Point(buttonBack.Location.X + buttonBack.Width + 8, buttonBack.Location.Y);
            buttonUp.BackColor = Color.Transparent;
            buttonUp.uwfBorderColor = Color.Transparent;
            buttonUp.Size = new Drawing.Size(22, 22);
            if (buttonUp.Image == null) buttonUp.Text = "▲";
            buttonUp.Click += (sender, args) => ButtonUp();
            Controls.Add(buttonUp);

            var buttonUpTooltip = new ToolTip();
            buttonUpTooltip.SetToolTip(buttonUp, "Up (ALT + Up Arrow)");
            
            // Button Refresh.
            buttonRefresh = new Button();
            buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right;
            buttonRefresh.BackColor = Color.Transparent;
            buttonRefresh.Image = ApplicationResources.Images.FileDialogRefresh;
            buttonRefresh.Size = new Size(22, 22);
            buttonRefresh.Location = new Point(Width - Padding.Right - buttonRefresh.Width, buttonUp.Location.Y);
            //buttonRefresh.uwfImageColor = Color.FromArgb(64, 64, 64);
            //buttonRefresh.uwfImageHoverColor = buttonRefresh.uwfImageColor;
            //buttonRefresh.uwfBorderColor = Color.Transparent;
            
            buttonRefresh.Click += (sender, args) => ButtonRefresh();
            if (buttonRefresh.Image == null) buttonRefresh.Text = "R";
            Controls.Add(buttonRefresh);

            var buttonRefreshTooltip = new ToolTip();
            buttonRefreshTooltip.SetToolTip(buttonRefresh, "Refresh (F5)");
            
            // Textbox Path.
            textBoxPath = new PathTextBox(this);
            textBoxPath.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            textBoxPath.Font = new Drawing.Font("Arial", 12);
            textBoxPath.Location = new Point(buttonUp.Location.X + buttonUp.Width + 8, buttonUp.Location.Y);
            textBoxPath.Size = new Drawing.Size(Width - textBoxPath.Location.X - Padding.Right - buttonRefresh.Width + 1, buttonBack.Height);
            Controls.Add(textBoxPath);
            
            // Button Cancel.
            buttonCancel = new Button();
            buttonCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            buttonCancel.Location = new Point(Width - Padding.Right - buttonCancel.Width, Height - Padding.Bottom - buttonCancel.Height);
            buttonCancel.Text = "Cancel";
            buttonCancel.Click += (sender, args) =>
            {
                DialogResult = Forms.DialogResult.Cancel;
                Close();
            };
            Controls.Add(buttonCancel);
            
            // Button Ok.
            buttonOk = new Button();
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonOk.Location = new Point(buttonCancel.Location.X - buttonOk.Width - 8, buttonCancel.Location.Y);
            buttonOk.Text = "Ok";
            buttonOk.Click += (sender, args) => { OpenFile(); };
            Controls.Add(buttonOk);
            
            // Label Filename.
            labelFilename = new Label();
            labelFilename.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
            labelFilename.Location = new Point(8, buttonOk.Location.Y - 30);
            labelFilename.Size = new Drawing.Size(64, 22);
            labelFilename.Text = "File: ";
            labelFilename.TextAlign = ContentAlignment.MiddleRight;
            Controls.Add(labelFilename);
            
            // Textbox Filename.
            textBoxFilename = new TextBox();
            textBoxFilename.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
            textBoxFilename.Location = new Point(labelFilename.Location.X + labelFilename.Width, labelFilename.Location.Y);
            textBoxFilename.Size = new Drawing.Size(Width - 32 - (buttonOk.Width + 8 + buttonCancel.Width) - labelFilename.Width, 22);
            Controls.Add(textBoxFilename);
            
            // Combobox Filter.
            comboFilter = new ComboBox();
            comboFilter.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            comboFilter.DropDownStyle = ComboBoxStyle.DropDownList;
            comboFilter.Size = new Drawing.Size(buttonOk.Width + 8 + buttonCancel.Width, 22);
            comboFilter.Location = new Point(Width - Padding.Right - comboFilter.Width, textBoxFilename.Location.Y);
            Controls.Add(comboFilter);
            
            // File Render.
            fileRenderer = new FileRenderer(this);
            fileRenderer.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
            fileRenderer.Location = new Point(Padding.Left, buttonBack.Location.Y + buttonBack.Height + 8);
            fileRenderer.Name = "fileRenderer";
            fileRenderer.Size = new Drawing.Size(Width - Padding.Left - Padding.Right, textBoxFilename.Location.Y - buttonBack.Location.Y - buttonBack.Height - 16);
            fileRenderer.DirectoryChanged += () =>
            {
                if (fileRenderer.prevPathes.Count > 0)
                    buttonBack.Enabled = true;
                textBoxPath.Text = fileRenderer.currentPath;
                textBoxPath.Refresh();
            };
            fileRenderer.SelectedFileChanged += (file) => textBoxFilename.Text = file.ToString();
            fileRenderer.FileOpened += (file) => OpenFile();
            Controls.Add(fileRenderer);
            
            textBoxPath.Text = fileRenderer.currentPath;
            textBoxPath.Refresh();
            textBoxPath.KeyDown += (sender, args) =>
            {
                if (args.KeyCode == Keys.Enter)
                    fileRenderer.SetDirectory(textBoxPath.Text);
            };

            fileRenderer.filesTree.NodeMouseClick += filesTree_NodeMouseClick;

            //AcceptButton = buttonOk;
            InitialDirectory = UnityEngine.Application.dataPath;
            Shown += FileDialog_Shown;
        }

        public string FileName
        {
            get { return filename; }
            set
            {
                filename = value;
                textBoxFilename.Text = value;
            }
        }
        public string Filter { get; set; }
        public string InitialDirectory
        {
            get { return initialDir; }
            set { initialDir = value; }
        }

        internal string currentFilter
        {
            get
            {
                if (comboFilter.SelectedIndex < 0 || string.IsNullOrEmpty(Filter)) return "*.*";
                
                var fs = Filter.Split('|');
                return fs[comboFilter.SelectedIndex * 2 + 1];
            }
        }
        protected internal virtual void ButtonBack()
        {
            buttonBack.Enabled = fileRenderer.Back() && fileRenderer.prevPathes.Count > 0;
            textBoxPath.Text = fileRenderer.currentPath;
        }
        protected internal virtual void ButtonUp()
        {
            fileRenderer.Up();
        }
        protected internal virtual void ButtonRefresh()
        {
            fileRenderer.SetDirectory(fileRenderer.currentPath);
        }
        protected internal virtual void filesTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                var contextMenu = new ContextMenuStrip();

                ToolStripMenuItem itemOpen = new ToolStripMenuItem("Select");
                itemOpen.Click += (sender2, args) => { OpenFile(); };
                contextMenu.Items.Add(itemOpen);

                ToolStripSeparator itemSep = new ToolStripSeparator();
                contextMenu.Items.Add(itemSep);

                ToolStripMenuItem itemProperties = new ToolStripMenuItem("Properties");
                itemProperties.Click += (sender2, args) => { new FormFileInfo(fileRenderer.currentPath + "/" + textBoxFilename.Text).ShowDialog(); };
                contextMenu.Items.Add(itemProperties);

                contextMenu.Show(null, MousePosition);
            }
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            
            if (e.KeyCode == Keys.Escape)
            {
                if (textBoxPath.Focused)
                {
                    Focus();
                    return;
                }
                
                DialogResult = DialogResult.Cancel;
                Close();
            }

            // Next folder.
            if (e.KeyCode == Keys.Return && textBoxPath.Focused == false)
                fileRenderer.Next();

            // Refresh directory.
            if (e.KeyCode == Keys.F5)
                ButtonRefresh();

            if (e.Alt)
            {
                switch (e.KeyCode)
                {
                    case Keys.Left: ButtonBack(); break;
                    case Keys.Up: ButtonUp(); break;
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (fileRenderer != null)
            {
                var grayFillY = fileRenderer.Location.Y;
                e.Graphics.DrawLine(splitterPen, 0, grayFillY - 1, Width, grayFillY - 1);
                e.Graphics.uwfFillRectangle(SystemColors.Control, 0, grayFillY, Width, Height - grayFillY);
            }
        }
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            if (handleFormSize)
                savedFormSize = Size;
        }
        protected internal void OpenFile()
        {
            filename = fileRenderer.currentPath + "/" + textBoxFilename.Text;
            
#if IO_SUPPORTED

            // Check if file is not a directory.
            if (!System.IO.Directory.Exists(filename))
            {
                // Add extension to the end of file if needed.
                var hasExtension = System.IO.Path.HasExtension(filename);
                if (!hasExtension)
                {
                    var extension = currentFilter;
                    if (extension.Contains('.'))
                        filename += extension.Substring(extension.IndexOf('.'));
                }
            }

#endif
            
            DialogResult = DialogResult.OK;
            Close();
        }

        private void FileDialog_Shown(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Filter))
            {
                comboFilter.Visible = false;
                textBoxFilename.Width = Width - textBoxFilename.Location.X - (Width - comboFilter.Location.X - comboFilter.Width);
            }
            else
            {
                var fs = Filter.Split('|');
                if (fs.Length % 2 != 0)
                {
                    Close();
                    throw new ArgumentException("filter");
                }

                for (int i = 0; i < fs.Length; i += 2)
                    comboFilter.Items.Add(fs[i] + " (" + fs[i + 1] + ")");

                if (comboFilter.Items.Count > 0)
                {
                    comboFilter.SelectedIndex = 0;
                    comboFilter.SelectedIndexChanged += (s, a) => { fileRenderer.SetDirectory(fileRenderer.currentPath); };
                }
            }

            fileRenderer.SetDirectory(InitialDirectory);
            fileRenderer.filesTree.Focus();
        }

        #region classes

        internal class FileRenderer : Control
        {
            public string currentPath;
            public List<string> prevPathes;

            internal TreeView filesTree;

            private readonly FileDialog owner;
            private string fromFolder;
            private FileInfo[] currentFiles;

            public FileRenderer(FileDialog owner)
            {
                this.owner = owner;

                prevPathes = new List<string>();

                filesTree = new FileTreeView();
                filesTree.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
                filesTree.BorderStyle = BorderStyle.None;
                filesTree.Size = new Drawing.Size(Width, Height);
                filesTree.AfterSelect += filesTree_SelectedNodeChanged;
                filesTree.NodeMouseDoubleClick += filesTree_NodeMouseDoubleClick;
                Controls.Add(filesTree);

                filesTree.ImageList = new ImageList();
                filesTree.ImageList.Images.Add(ApplicationResources.Images.FileDialogFolder);
                filesTree.ImageList.Images.Add(ApplicationResources.Images.FileDialogFile);
            }

            public delegate void DirectoryChangedHandler();
            public delegate void FileHandler(FileInfo file);

            public event DirectoryChangedHandler DirectoryChanged;
            public event FileHandler FileOpened;
            public event FileHandler SelectedFileChanged;

            public bool Back()
            {
                if (prevPathes.Count == 0) return false;

                currentPath = prevPathes.Last();
                prevPathes.RemoveAt(prevPathes.Count - 1);
                SetDirectory(currentPath);
                return true;
            }
            public void Next()
            {
                if (filesTree.SelectedNode == null) return;

                var fInfo = (FileInfo)filesTree.SelectedNode.Tag;
                if (fInfo.IsDirectory)
                {
                    prevPathes.Add(currentPath);
                    currentPath += fInfo.Name;
                    SetDirectory(currentPath);
                    
                    if (DirectoryChanged != null)
                        DirectoryChanged();
                }
                else
                {
                    if (FileOpened != null)
                        FileOpened(fInfo);
                }
            }
            public void SetDirectory(string path, bool addPrevPath = false)
            {
#if IO_SUPPORTED
                if (path.Length <= 2) return;
                if (System.IO.Directory.Exists(path) == false) return;

                if (addPrevPath)
                    prevPathes.Add(currentPath);
                
                currentPath = path.Replace("\\", "/");
                var filter = owner.currentFilter;
                
                string[] files;
                try
                {
                    if (filter == "*" || filter == "*.*")
                        files = System.IO.Directory.GetFiles(currentPath, "*.*")
                            .Select(f => f.Substring(currentPath.Length))
                            .ToArray();
                    else
                        files = System.IO.Directory.GetFiles(currentPath, "*.*")
                            .Where(f => filter.Contains(System.IO.Path.GetExtension(f).ToLower()))
                            .Select(f => f.Substring(currentPath.Length))
                            .ToArray();
                }
                catch (UnauthorizedAccessException ex)
                {
                    // Restore previous path.
                    if (prevPathes.Count > 0)
                    {
                        var prevPath = prevPathes[prevPathes.Count - 1];
                        prevPathes.RemoveAt(prevPathes.Count - 1);
                        
                        if (prevPath != currentPath) // Or we can get stack overflow.
                            SetDirectory(prevPath);
                    }
                    
                    MessageBox.Show(ex.Message, "Error");
                    return;
                }

                var dirs = System.IO.Directory.GetDirectories(currentPath)
                    .Select(f => f.Substring(currentPath.Length))
                    .ToArray();

                currentFiles = new FileInfo[dirs.Length + files.Length];
                
                for (int i = 0; i < dirs.Length; i++)
                {
                    currentFiles[i] = new FileInfo();
                    currentFiles[i].IsDirectory = true;
                    currentFiles[i].Name = dirs[i];
                }
                
                for (int i = dirs.Length; i < dirs.Length + files.Length; i++)
                {
                    currentFiles[i] = new FileInfo();
                    currentFiles[i].Name = files[i - dirs.Length];
                }

                filesTree.Nodes.Clear();
                
                for (int i = 0; i < currentFiles.Length; i++)
                {
                    var file = currentFiles[i];
                    file.CurrentPath = currentPath;
                    
                    var fileNode = new TreeNode(file.ToString());
                    fileNode.Tag = file;
                    fileNode.ImageIndex = file.IsDirectory ? 0 : 1;

                    filesTree.Nodes.Add(fileNode);
                    if (fileNode.Text == fromFolder)
                        filesTree.SelectedNode = fileNode;
                }
                filesTree.ExpandAll();

                if (DirectoryChanged != null)
                    DirectoryChanged();

                fromFolder = null;

                owner.textBoxFilename.Text = "";
#endif
            }
            public void Up()
            {
#if IO_SUPPORTED
                System.IO.DirectoryInfo parent;
                try
                {
                    // Can throw NullReferenceExepcetion for path like 'C:\'.
                    parent = System.IO.Directory.GetParent(currentPath);
                }
                catch (Exception e) { return; }
                
                if (parent == null || parent.Exists == false) return;
                
                prevPathes.Add(currentPath);
                fromFolder = System.IO.Path.GetFileName(currentPath);
                SetDirectory(parent.FullName);
#endif
            }

            private void filesTree_SelectedNodeChanged(object sender, TreeViewEventArgs e)
            {
                if (e.Node != null && SelectedFileChanged != null)
                    SelectedFileChanged((FileInfo)e.Node.Tag);
            }
            private void filesTree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
            {
                Next();
            }

            private class FileTreeView : TreeView
            {
                public Pen selectionPen = new Pen(Color.White);

                public FileTreeView()
                {
                    uwfItemSelectedColor = Color.Transparent;
                    uwfItemHoveredColor = Color.Transparent;
                    uwfItemSelectedUnfocusedColor = Color.Transparent;
                }
                
                protected override void OnDrawNode(DrawTreeNodeEventArgs e)
                {
                    var selectionBounds = new Rectangle(e.Node.Bounds.X, e.Node.Bounds.Y, 660, e.Node.Bounds.Height);
                    
                    if (e.Node.IsSelected || e.Node == hoveredNode)
                    {
                        var backColor = Color.FromArgb(209, 232, 255);
                        
                        if (e.Node.IsSelected)
                        {
                            if (Focused)
                                selectionPen.Color = Color.FromArgb(60, 162, 223);
                            else
                            {
                                backColor = Color.FromArgb(247, 247, 247);
                                selectionPen.Color = Color.FromArgb(222, 222, 222);
                            }
                        }
                        else
                        {
                            // Hovered.
                            backColor = Color.FromArgb(229, 243, 251);
                            selectionPen.Color = Color.FromArgb(112, 192, 231);
                        }
                        
                        e.Graphics.uwfFillRectangle(backColor, selectionBounds);
                        e.Graphics.DrawRectangle(selectionPen, selectionBounds);
                    }
                    
                    base.OnDrawNode(e);

#if IO_SUPPORTED
                    var info = e.Node.Tag as FileInfo;
                    if (info == null)
                        return;

                    var fInfo = info.Info;
                    if (fInfo == null)
                        return;

                    var foreColor = e.Node.ForeColor;
                    if (foreColor.IsEmpty)
                        foreColor = ForeColor;
                    
                    e.Graphics.uwfDrawString(
                        fInfo.LastWriteTime.ToString("dd.MM.yyyy HH:mm"), 
                        Font, 
                        foreColor, 
                        selectionBounds.X + 440,
                        selectionBounds.Y,
                        200,
                        selectionBounds.Height);
                    
                    e.Graphics.uwfDrawString(
                        info.sizeStr, 
                        Font, 
                        foreColor, 
                        selectionBounds.X + 400,
                        selectionBounds.Y,
                        selectionBounds.Width - 412,
                        selectionBounds.Height,
                        ContentAlignment.MiddleRight);
#endif
                }
                
                
            }
        }

        internal class FileInfo
        {
#if IO_SUPPORTED
            private System.IO.FileInfo info;
            public System.IO.FileInfo Info
            {
                get
                {
                    if (IsDirectory)
                        return null;

                    if (info == null && System.IO.File.Exists(CurrentPath + Name))
                    {
                        info = new System.IO.FileInfo(CurrentPath + Name);
                        sizeStr = HumanizeBytes(info.Length);
                    }
                    
                    return info;
                }
            }

            public string sizeStr;
#endif

            public string CurrentPath;
            public bool IsDirectory;
            public string Name;

            private static readonly NumberFormatInfo numberFormatInfo = new NumberFormatInfo()
            {
                NumberGroupSeparator = " "
            };
            
            public override string ToString()
            {
                //if (IsDirectory) return "/ " + Name;
                return Name.Replace("\\", "");
            }
            
            private static string HumanizeBytes(long bytes)
            {
                if (bytes < 1024) return " 1 KB";

                return (bytes / 1024).ToString("N0", numberFormatInfo) + " KB";
            }
        }

        internal class FormFileInfo : Form
        {
            public FormFileInfo(string path)
            {
#if IO_SUPPORTED
                Size = new Drawing.Size(320, 120);
                Location = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2 - Height / 2);
                FormBorderStyle = FormBorderStyle.FixedSingle;
                Text = "Properties: ";

                if (System.IO.File.Exists(path) == false) return;

                var info = new System.IO.FileInfo(path);
                var bytes = info.Length;
                string sbytes = bytes.ToString() + " bytes";
                if (bytes >= 1000000000)
                    sbytes = (bytes / 1000000000) + " gb";
                if (bytes >= 1000000)
                    sbytes = (bytes / 1000000) + " mb";
                else if (bytes >= 1000)
                    sbytes = (bytes / 1000) + " kb";

                Label labelSize = new Label();
                labelSize.Location = new Point(16, 32);
                labelSize.Text = "Size: " + sbytes;
                Controls.Add(labelSize);

                Label labelCreationDate = new Label();
                labelCreationDate.Location = new Point(16, 64);
                labelCreationDate.Text = "Date creation: " + info.CreationTime.ToString("dd.MM.yyyy");
                Controls.Add(labelCreationDate);

                Label labelModDate = new Label();
                labelModDate.Location = new Point(16, 86);
                labelModDate.Text = "Date modified: " + info.LastWriteTime.ToString();
                Controls.Add(labelModDate);

                string fileName = System.IO.Path.GetFileName(path);
                Text += fileName;
#endif
            }
        }

        internal class PathTextBox : TextBox
        {
            private readonly FileDialog fileDialog;
            private string text;
            private bool updateButtons;

            public PathTextBox(FileDialog owner)
            {
                fileDialog = owner;
                Padding = new Padding(8, 0, 8, 0);
            }

            public override string Text
            {
                get { return text; }
                set
                {
                    if (text == value)
                        return;
                    
                    // TODO: reset text when directory not found or Escape button was pressed.
                    text = value;
                    if (text == null)
                        text = "";

                    OnTextChanged(EventArgs.Empty);
                }
            }

            protected override void OnGotFocus(EventArgs e)
            {
                base.OnGotFocus(e);
                DisposeButtons();
            }
            protected override void OnLostFocus(EventArgs e)
            {
                base.OnLostFocus(e);
                
                Refresh();
            }
            protected override void OnKeyDown(KeyEventArgs e)
            {
                base.OnKeyDown(e);

                if (e.KeyCode == Keys.Enter)
                    Parent.Focus();
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                if (updateButtons)
                {
                    for (int i = Controls.Count - 1, x = 0; i >= 0; i--)
                    {
                        var b = Controls[i] as pathButton;
                        if (b == null) continue;

                        b.Width = (int) e.Graphics.MeasureString(b.Text, b.Font).Width + 23; // padding + arrowButton.
                        b.Location = new Point(x, 1);

                        x += b.Width;
                    }
                    updateButtons = false;
                }

                // Write text to buffer.
                var temp = text;
                if (Focused == false)
                    text = string.Empty;

                base.OnPaint(e);

                if (Focused == false)
                    text = temp; // Restore buffered text if needed.
            }
            public override void Refresh()
            {
                base.Refresh();
                
                UpdateButtons();
            }

            private void CreateButtons()
            {
#if IO_SUPPORTED
                var currentPath = text;
                if (string.IsNullOrEmpty(currentPath))
                    return;
                
                var directories = new List<IO.DirectoryInfo>();
                var cdir = new IO.DirectoryInfo(currentPath);
                directories.Add(cdir);

                var count = 0;
                while (count < 30)
                {
                    try
                    {
                        var dir = System.IO.Directory.GetParent(currentPath);
                        if (dir == null) break;

                        directories.Add(dir);
                        currentPath = dir.FullName;
                    }
                    catch (Exception)
                    {
                        // Fix: nullreference?? (Directory.GetParent("C:\\")). 
                    }

                    count++;
                }

                var allowedWidth = Width;
                float currentWidth = 0;
                int currentIndex;
                
                for (currentIndex = 0; currentIndex < directories.Count; currentIndex++)
                {
                    var dir = directories[currentIndex];
                    var estimatedWidth = Font.MeasureStringSimple(dir.Name).Width + 15;

                    currentWidth += estimatedWidth;
                    if (currentWidth >= allowedWidth)
                        break;

                    var button = new pathButton(dir.FullName);
                    button.Font = Font;
                    button.Height = Height - 2;
                    button.Width = (int)estimatedWidth;
                    button.Text = dir.Name;
                    button.Click += (sender, args) => fileDialog.fileRenderer.SetDirectory(button.Path, true);

                    Controls.Add(button);
                }

                updateButtons = true;
#endif
            }
            private void DisposeButtons()
            {
                for (int i = 0; i < Controls.Count; i++)
                {
                    var pb = Controls[i] as pathButton;
                    if (pb == null) continue;

                    pb.Dispose(); // TODO: cache + visible.
                    i--;
                }
            }
            private void UpdateButtons()
            {
                DisposeButtons();
                CreateButtons();
            }

            private class pathButton : Button
            {
                public pathButton(string path)
                {
                    Path = path;

                    BackColor = Color.Transparent;
                    uwfBorderColor = Color.Transparent;
                    ForeColor = Color.FromArgb(47, 47, 47);
                    uwfHoverColor = Color.FromArgb(229, 243, 251);
                    Padding = new Padding(4, 0, 4, 0);
                    TextAlign = ContentAlignment.MiddleLeft;

                    var arrowButton = new Button();
                    arrowButton.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                    arrowButton.BackColor = BackColor;
                    arrowButton.uwfBorderColor = uwfBorderColor;
                    arrowButton.uwfHoverColor = uwfHoverColor;
                    arrowButton.Width = 15;
                    arrowButton.Height = Height;
                    arrowButton.Location = new Point(Width - arrowButton.Width, 0);
                    arrowButton.Text = "";
                    arrowButton.Image = ApplicationResources.Images.ArrowRight;
                    arrowButton.uwfImageColor = Color.Gray;
                    arrowButton.uwfImageHoverColor = Color.Gray;

                    Controls.Add(arrowButton);
                }

                public string Path { get; private set; }
            }
        }

        #endregion
    }
}


<|start_filename|>Assets/System/Windows/Forms/OpenFileDialog.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public sealed class OpenFileDialog : FileDialog
    {
        public OpenFileDialog()
        {
            Text = "Open";

            buttonOk.Text = "Open";
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/SplitContainer.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;
    
    public class SplitContainer : ContainerControl
    {
        private bool cursorWasSet;
        private BorderStyle borderStyle = BorderStyle.None;
        private Orientation orientation = Orientation.Vertical;
        private int panel1MinSize = 25;
        private int panel2MinSize = 25;
        private bool panel1WasEnabled;
        private bool panel2WasEnabled;
        private int splitterDistance = 50;
        private bool splitterMoving;
        private int splitterMovingOffset;
        private int splitterWidth = 4;

        public SplitContainer()
        {
            Panel1 = new SplitterPanel(this);
            Panel2 = new SplitterPanel(this);
            
            Controls.Add(Panel1);
            Controls.Add(Panel2);
            
            UpdateSplitter();
            
            Application.UpdateEvent += ApplicationOnUpdateEvent;
            MouseHook.MouseUp += MouseHookOnMouseUp;
        }
        
        public BorderStyle BorderStyle
        {
            get { return borderStyle; }
            set
            {
                if (borderStyle == value)
                    return;

                borderStyle = value;
                
                Panel1.BorderStyle = borderStyle;
                Panel2.BorderStyle = borderStyle;
            }
        }
        public Orientation Orientation
        {
            get { return orientation; }
            set
            {
                if (orientation == value)
                    return;

                orientation = value;
                
                UpdateSplitter();
            }
        }
        public bool IsSplitterFixed { get; set; }
        public SplitterPanel Panel1 { get; private set; }
        public bool Panel1Collapsed {
            get { return Panel1.collapsed; }
            set {
                if (Panel1.collapsed == value) 
                    return;
                
                if (Panel2.collapsed && value)
                    CollapsePanel(Panel2, false);
                    
                CollapsePanel(Panel1, value);
            }
        }
        public int Panel1MinSize {
            get {  return panel1MinSize; }
            set 
            { 
                if (panel1MinSize == value)
                    return;
                
                if (value < 0) 
                    throw new ArgumentOutOfRangeException("value");
                
                panel1MinSize = value;
            }
        }
        public SplitterPanel Panel2 { get; private set; }
        public bool Panel2Collapsed {
            get { return Panel2.collapsed; }
            set {
                if (Panel2.collapsed == value) 
                    return;

                if (Panel1.collapsed && value)
                    CollapsePanel(Panel1, false);
                
                CollapsePanel(Panel2, value);
            }
        }
        public int Panel2MinSize
        {
            get { return panel2MinSize; }
            set
            {
                if (panel2MinSize == value)
                    return;
                
                if (value < 0) 
                    throw new ArgumentOutOfRangeException("value");

                panel2MinSize = value;
            }
        }
        public int SplitterDistance
        {
            get { return splitterDistance; }
            set
            {
                if (splitterDistance == value)
                    return;

                splitterDistance = value;
                UpdateSplitter();
            }
        }
        public int SplitterWidth
        {
            get { return splitterWidth; }
            set
            {
                if (splitterWidth == value)
                    return;

                splitterWidth = value;
                UpdateSplitter();
            }
        }
        
        protected override Size DefaultSize
        {
            get { return new Size(150, 100); }
        }
        
        protected override void Dispose(bool release_all)
        {
            base.Dispose(release_all);
            
            Application.UpdateEvent -= ApplicationOnUpdateEvent;
            MouseHook.MouseUp -= MouseHookOnMouseUp;
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (!IsSplitterFixed)
            {
                if (Orientation == Orientation.Vertical && e.X >= splitterDistance && e.X <= splitterDistance + splitterWidth ||
                    Orientation == Orientation.Horizontal && e.Y >= splitterDistance && e.Y <= splitterDistance + splitterWidth)
                {
                    splitterMoving = true;
                    panel1WasEnabled = Panel1.Enabled;
                    panel2WasEnabled = Panel2.Enabled;

                    if (Orientation == Orientation.Vertical)
                    {
                        splitterMovingOffset = e.X - splitterDistance;
                        Cursor.Current = Cursors.VSplit;
                        cursorWasSet = true;
                    }
                    else
                    {
                        splitterMovingOffset = e.Y - splitterDistance;
                        Cursor.Current = Cursors.HSplit;
                        cursorWasSet = true;
                    }
                }
            }
        }
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            
            UpdateSplitter();
        }
        
        private void ApplicationOnUpdateEvent()
        {
            var mclient = PointToClient(MousePosition);
            if (splitterMoving)
            {
                if (Orientation == Orientation.Vertical)
                    splitterDistance = mclient.X - splitterMovingOffset;
                else
                    splitterDistance = mclient.Y - splitterMovingOffset;

                UpdateSplitter();
            }
            else if (ClientRectangle.Contains(mclient))
            {
                if (Orientation == Orientation.Vertical)
                {
                    if (mclient.X >= splitterDistance &&
                        mclient.X <= splitterDistance + splitterWidth && hovered)
                    {
                        Cursor.Current = Cursors.VSplit;
                        cursorWasSet = true;
                    }
                    else
                    {
                        Cursor.Current = null;
                        cursorWasSet = false;
                    }
                }
                else
                {
                    if (mclient.Y >= splitterDistance &&
                        mclient.Y <= splitterDistance + splitterWidth && hovered)
                    {
                        Cursor.Current = Cursors.HSplit;
                        cursorWasSet = true;
                    }
                    else
                    {
                        Cursor.Current = null;
                        cursorWasSet = false;
                    }
                }
            }
            else if (cursorWasSet)
            {
                Cursor.Current = null;
                cursorWasSet = false;
            }
        }
        private void CollapsePanel(SplitterPanel p, bool collapsing) 
        {
            p.collapsed = collapsing;
            p.Visible = !collapsing;

            UpdateSplitter();
        }
        private void MouseHookOnMouseUp(object sender, MouseEventArgs e)
        {
            if (splitterMoving)
            {
                Panel1.Enabled = panel1WasEnabled;
                Panel2.Enabled = panel2WasEnabled;
                splitterMoving = false;
                cursorWasSet = false;
                Cursor.Current = null;
            }            
        }
        private void UpdateSplitter()
        {
            if (Orientation == Orientation.Vertical)
                splitterDistance = MathHelper.Clamp(splitterDistance, panel1MinSize, Width - panel2MinSize - splitterWidth);
            else if (Orientation == Orientation.Horizontal)
                splitterDistance = MathHelper.Clamp(splitterDistance, panel1MinSize, Height - panel2MinSize - splitterWidth);
            
            Panel1.SuspendLayout();
            Panel2.SuspendLayout();

            if (Panel1Collapsed == false && Panel2Collapsed == false)
            {
                if (Orientation == Orientation.Vertical)
                {
                    Panel1.Location = new Point();
                    Panel1.Size = new Size(splitterDistance, Height);
                    Panel2.Location = new Point(splitterDistance + splitterWidth, 0);
                    Panel2.Size = new Size(Width - splitterDistance - splitterWidth, Height);
                }
                else
                {
                    Panel1.Location = new Point();
                    Panel1.Size = new Size(Width, splitterDistance);
                    Panel2.Location = new Point(0, splitterDistance + splitterWidth);
                    Panel2.Size = new Size(Width, Height - splitterDistance - splitterWidth);
                }
            }
            else
            {
                if (Panel1Collapsed)
                {
                    Panel2.Location = new Point();
                    Panel2.Size = Size;
                }
                else if (Panel2Collapsed)
                {
                    Panel1.Location = new Point();
                    Panel1.Size = Size;
                }
            }

            Panel1.ResumeLayout();
            Panel2.ResumeLayout();
        }
    }
}

<|start_filename|>Assets/Core/ApiHolder.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;
    using System.Drawing.API;

    /// <summary>
    /// Replace with your own implementation if needed.
    /// </summary>
    public static class ApiHolder
    {
        public static IApiGraphics Graphics { get; set; }
        public static IApiInput Input { get; set; }
        public static IApiSystem System { get; set; }
        public static IApiTiming Timing { get; set; }
    }
}

<|start_filename|>Assets/System/Windows/Forms/ScrollableControl.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;
    using System.Linq;

    public class ScrollableControl : Control
    {
        internal HScrollBar hscroll; // In case you want to scroll manually.
        internal VScrollBar vscroll;

        internal event EventHandler uwfHScrollAdded; // For styling if necessary.
        internal event EventHandler uwfVScrollAdded;

        protected const int ScrollStateAutoScrolling = 0x0001;
        protected const int ScrollStateHScrollVisible = 0x0002;
        protected const int ScrollStateVScrollVisible = 0x0004;
        protected const int ScrollStateUserHasScrolled = 0x0008;
        protected const int ScrollStateFullDrag = 0x0010;

        private Rectangle displayRect = Rectangle.Empty;
        private int scrollState;

        private HScrollProperties horizontalScroll;
        private VScrollProperties verticalScroll;

        public ScrollableControl()
        {
            SetStyle(ControlStyles.ContainerControl, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, false);
            SetScrollState(ScrollStateAutoScrolling, false);
        }

        public virtual bool AutoScroll
        {
            get { return GetScrollState(ScrollStateAutoScrolling); }
            set
            {
                SetScrollState(ScrollStateAutoScrolling, value);
                PerformLayout();
            }
        }
        public override Rectangle DisplayRectangle
        {
            get
            {
                var rect = ClientRectangle;
                if (!displayRect.IsEmpty)
                {
                    rect.X = displayRect.X;
                    rect.Y = displayRect.Y;
                    if (HScroll)
                        rect.Width = displayRect.Width;

                    if (VScroll)
                        rect.Height = displayRect.Height;
                }
                return rect;
            }
        }
        public HScrollProperties HorizontalScroll
        {
            get
            {
                if (horizontalScroll == null)
                    horizontalScroll = new HScrollProperties(this);

                return horizontalScroll;
            }
        }
        public VScrollProperties VerticalScroll
        {
            get
            {
                if (verticalScroll == null)
                    verticalScroll = new VScrollProperties(this);

                return verticalScroll;
            }
        }

        protected bool HScroll
        {
            get { return GetScrollState(ScrollStateHScrollVisible); }
            set { SetScrollState(ScrollStateHScrollVisible, value); }
        }
        protected bool VScroll
        {
            get { return GetScrollState(ScrollStateVScrollVisible); }
            set { SetScrollState(ScrollStateVScrollVisible, value); }
        }

        internal void EnsureVisible(Control control)
        {
            if (control == null || control.Parent == null)
                return;

            var scrollable = control.Parent as ScrollableControl;
            if (scrollable == null)
            {
                EnsureVisible(control.Parent);
                return;
            }

            // Vertical.
            if (scrollable.vscroll != null)
            {
                var controlY = control.Location.Y;
                var hScrollHeight = 0;
                if (scrollable.hscroll != null)
                    hScrollHeight = scrollable.hscroll.Height;
                
                var goDown = controlY + control.Height > scrollable.vscroll.Value + scrollable.vscroll.LargeChange - hScrollHeight;
                var goUp = controlY < scrollable.vscroll.Value;
                
                var newValue = 0;

                if (goDown)
                    newValue = controlY + control.Height + hScrollHeight + 4 - scrollable.vscroll.LargeChange;
                else if (goUp)
                    newValue = controlY - 4;
                
                if (goDown || goUp)
                    scrollable.vscroll.Value = MathHelper.Clamp(newValue, 0, scrollable.vscroll.Maximum);
            }

            // Horizontal.
            if (scrollable.hscroll != null)
            {
                var controlX = control.Location.X;
                var vScrollWidth = 0;
                if (scrollable.vscroll != null)
                    vScrollWidth = scrollable.vscroll.Width;
                
                var goLeft = controlX < scrollable.hscroll.Value;
                var goRight = controlX + control.Width > scrollable.hscroll.Value + scrollable.hscroll.LargeChange - vScrollWidth;
                
                var newValue = 0;

                if (goRight)
                    newValue = controlX + control.Width + vScrollWidth + 4 - scrollable.hscroll.LargeChange;
                else if (goLeft)
                    newValue = controlX - 4;    
                
                if (goRight || goLeft)
                    scrollable.hscroll.Value = MathHelper.Clamp(newValue, 0, scrollable.hscroll.Maximum);
            }
        }
        internal void Native_EnableScrollBar(bool enable, int orientation)
        {
            var oriV = orientation == NativeMethods.SB_VERT;
            var oriH = orientation == NativeMethods.SB_HORZ;

            if (enable)
            {
                if (oriV && vscroll == null)
                {
                    vscroll = new VScrollBar();
                    vscroll.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
                    vscroll.uwfSystem = true;
                    vscroll.ValueChanged += Scroll_ValueChanged;

                    Controls.Add(vscroll);

                    uwfOnVScrollAdded(EventArgs.Empty);
                }

                if (oriH && hscroll == null)
                {
                    hscroll = new HScrollBar();
                    hscroll.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right;
                    hscroll.uwfSystem = true;
                    hscroll.ValueChanged += Scroll_ValueChanged;

                    Controls.Add(hscroll);

                    uwfOnHScrollAdded(EventArgs.Empty);
                }
            }
            else
            {
                if (oriV && vscroll != null)
                {
                    vscroll.Value = 0; // Reset view.
                    vscroll.ValueChanged -= Scroll_ValueChanged;
                    vscroll.Dispose();
                    vscroll = null;
                }

                if (oriH && hscroll != null)
                {
                    hscroll.Value = 0; // Reset view.
                    hscroll.ValueChanged -= Scroll_ValueChanged;
                    hscroll.Dispose();
                    hscroll = null;
                }
            }
        }
        internal ScrollBar GetScrollBar(int orientation)
        {
            var oriV = orientation == NativeMethods.SB_VERT;
            var oriH = orientation == NativeMethods.SB_HORZ;

            if (oriV) return vscroll;
            if (oriH) return hscroll;

            return null;
        }
        internal void UpdateControlsOffsets()
        {
            var hValue = 0;
            var vValue = 0;

            if (hscroll != null)
                hValue = hscroll.Value;

            if (vscroll != null)
                vValue = vscroll.Value;

            for (int i = 0; i < Controls.Count; i++)
            {
                var item = Controls[i];
                if (item.uwfSystem)
                    continue;

                item.uwfOffset = new Point(-hValue, -vValue);
            }
        }
        internal void UpdateScrolls()
        {
            var autoScroll = (scrollState & ScrollStateAutoScrolling) != 0;
            if (autoScroll == false)
            {
                Native_EnableScrollBar(false, NativeMethods.SB_VERT);
                Native_EnableScrollBar(false, NativeMethods.SB_HORZ);
                return;
            }

            var controlRect = GetControlsRect();
            var bottom = controlRect.Height;
            var left = controlRect.X;
            var right = controlRect.Width;
            var top = controlRect.Y;
            
            var enableHScroll = left < 0 || right > Width;
            var enableVScroll = top < 0 || bottom > Height;

            Native_EnableScrollBar(enableHScroll, NativeMethods.SB_HORZ);
            Native_EnableScrollBar(enableVScroll, NativeMethods.SB_VERT);

            var hMaximum = right > Width ? right : Width;
            var vMaximum = bottom > Height ? bottom : Height;

            if (vscroll != null) hMaximum += vscroll.Width + 2;
            if (hscroll != null) vMaximum += hscroll.Height + 2;

            if (vscroll != null)
            {
                vscroll.Maximum = vMaximum;
                vscroll.Minimum = top < 0 ? top : 0;
                vscroll.LargeChange = Height; 
            }

            if (hscroll != null)
            {
                hscroll.Maximum = hMaximum;
                hscroll.Minimum = left < 0 ? left : 0;
                hscroll.LargeChange = Width; 
            }

            UpdateScrollRects();
        }

        protected internal virtual void uwfOnHScrollAdded(EventArgs e)
        {
            var handler = uwfHScrollAdded;
            if (handler != null)
                handler(this, e);
        }
        protected internal virtual void uwfOnVScrollAdded(EventArgs e)
        {
            var handler = uwfVScrollAdded;
            if (handler != null)
                handler(this, e);
        }
        protected internal override void uwfOnLatePaint(PaintEventArgs e)
        {
            if (vscroll == null || hscroll == null)
                return;

            // Fill rect between two scrollbars.
            var rx = hscroll.Location.X + hscroll.Width;
            var ry = vscroll.Location.Y + vscroll.Height;
            var rw = Width - rx;
            var rh = Height - ry;

            e.Graphics.uwfFillRectangle(vscroll.BackColor, rx, ry, rw, rh);
        }

        protected bool GetScrollState(int bit)
        {
            return (bit & scrollState) == bit;
        }
        protected override void OnLayout(LayoutEventArgs e)
        {
            base.OnLayout(e);

            UpdateScrolls();
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            ScrollBar scroll = vscroll;
            if (scroll == null)
                scroll = hscroll;

            if (scroll != null)
                scroll.Value -= e.Delta;
        }
        protected void SetScrollState(int bit, bool value)
        {
            if (value)
                scrollState |= bit;
            else
                scrollState &= ~bit;
        }

        private Rectangle GetControlsRect()
        {
            var bottom = 0;
            var left = 0;
            var right = 0;
            var top = 0;
            
            for (int i = 0; i < Controls.Count; i++)
            {
                var item = Controls[i];
                if (item.uwfSystem)
                    continue;

                var itemBottom = item.Location.Y + item.Height;
                if (itemBottom > bottom)
                    bottom = itemBottom;

                var itemLeft = item.Location.X;
                if (itemLeft < left)
                    left = itemLeft;
                
                var itemRight = item.Location.X + item.Width;
                if (itemRight > right)
                    right = itemRight;

                var itemTop = item.Location.Y;
                if (itemTop < top)
                    top = itemTop;
            }

            return new Rectangle(left, top, right, bottom);
        }
        private void Scroll_ValueChanged(object sender, EventArgs e)
        {
            UpdateControlsOffsets();
        }
        private void UpdateScrollRects()
        {
            var hRightOffset = 0;
            var vBottomOffset = 0;
            var vTopOffset = 0;

            var form = this as Form;
            if (form != null)
            {
                vTopOffset += form.uwfHeaderHeight;

                if (form.uwfSizeGripRenderer != null)
                {
                    form.ResetGripRendererLocation();

                    var gripOriginLocation = form.uwfSizeGripRenderer.Location;
                    if (vscroll != null && hscroll == null)
                        gripOriginLocation.Offset(-vscroll.Width, 0);
                    if (hscroll != null && vscroll == null)
                        gripOriginLocation.Offset(0, -hscroll.Height);
                    
                    form.uwfSizeGripRenderer.Location = gripOriginLocation;
                }
            }

            if (vscroll != null && hscroll != null)
            {
                hRightOffset += 14;
                vBottomOffset += 14;
            }

            if (vscroll != null)
            {
                vscroll.Location = new Point(Width - vscroll.Width - 1, vTopOffset - 1);
                vscroll.Height = Height - vTopOffset - vBottomOffset - 2;
            }

            if (hscroll != null)
            {
                hscroll.Location = new Point(1, Height - hscroll.Height - 1);
                hscroll.Width = Width - hRightOffset - 2;
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/SplitterPanel.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public sealed class SplitterPanel : Panel
    {
        internal bool collapsed;

        private readonly SplitContainer owner;

        public SplitterPanel(SplitContainer owner)
        {
            this.owner = owner;
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/VScrollProperties.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class VScrollProperties : ScrollProperties
    {
        public VScrollProperties(ScrollableControl container) : base(container)
        {
        }
        internal override int PageSize
        {
            get { return ParentControl.ClientRectangle.Height; }
        }
        internal override int Orientation
        {
            get { return NativeMethods.SB_VERT; }
        }
        internal override int HorizontalDisplayPosition
        {
            get { return ParentControl.DisplayRectangle.X; }
        }
        internal override int VerticalDisplayPosition
        {
            get { return -value; }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripLabel.cs<|end_filename|>
namespace System.Windows.Forms
{
    using System.Drawing;

    public class ToolStripLabel : ToolStripItem
    {
        public ToolStripLabel()
        {
        }
        public ToolStripLabel(string text) : base(text, null, null)
        {
        }
        public ToolStripLabel(Image image) : base(null, image, null)
        {
        }
        public ToolStripLabel(string text, Image image) : base(text, image, null)
        {
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/FormWindowState.cs<|end_filename|>
namespace System.Windows.Forms
{
    public enum FormWindowState
    {
        Normal    = 0,
        Minimized = 1,
        Maximized = 2,
    }
}

<|start_filename|>Assets/System/Windows/Forms/UserControl.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class UserControl : ContainerControl
    {
    }
}


<|start_filename|>Assets/System/Windows/Forms/LinkLabel.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections;
    using System.Drawing;
    using System.Globalization;

    /// <summary>
    /// Link collection is not working. And probably won't any time soon.
    /// </summary>
    public class LinkLabel : Label, IButtonControl
    {
        private static readonly LinkComparer linkComparer = new LinkComparer();

        private readonly ArrayList links = new ArrayList(2);
        private readonly Pen underlinePen = new Pen(Color.Blue);
        private Link focusLink;
        private LinkCollection linkCollection;
        private Color linkColor = Color.Blue;
        private Color visitedLinkColor = Color.Purple;

        public LinkLabel()
        {
            Links.Add(new Link(0, -1));
            InvalidateLink(null);
        }

        public event LinkLabelLinkClickedEventHandler LinkClicked;

        public DialogResult DialogResult { get; set; }
        public LinkBehavior LinkBehavior { get; set; }
        public Color LinkColor
        {
            get { return linkColor; }
            set
            {
                if (linkColor == value)
                    return;

                linkColor = value;
                InvalidateLink(null);
            }
        }
        public LinkCollection Links
        {
            get
            {
                if (linkCollection == null)
                    linkCollection = new LinkCollection(this);

                return linkCollection;
            }
        }
        public bool LinkVisited
        {
            get
            {
                if (links.Count == 0)
                    return false;

                return ((Link)links[0]).Visited;
            }
            set
            {
                if (value == LinkVisited)
                    return;

                if (links.Count == 0)
                    Links.Add(new Link(this));

                ((Link)links[0]).Visited = value;
            }
        }
        public Color VisitedLinkColor
        {
            get { return visitedLinkColor; }
            set
            {
                if (visitedLinkColor == value) return;

                visitedLinkColor = value;
                InvalidateLink(null);
            }
        }

        private Link FocusLink
        {
            get { return focusLink; }
            set
            {
                if (focusLink == value) return;
                if (focusLink != null)
                    InvalidateLink(focusLink);

                focusLink = value;

                if (focusLink != null)
                    InvalidateLink(focusLink);
            }
        }

        public void NotifyDefault(bool value)
        { }
        public void PerformClick()
        {
            if (FocusLink == null && Links.Count > 0)
            {
                string text = Text;
                foreach (Link link in Links)
                {
                    int charStart = ConvertToCharIndex(link.Start, text);
                    int charEnd = ConvertToCharIndex(link.Start + link.Length, text);
                    if (link.Enabled && LinkInText(charStart, charEnd - charStart))
                    {
                        FocusLink = link;
                        break;
                    }
                }
            }

            if (FocusLink != null)
                OnLinkClicked(new LinkLabelLinkClickedEventArgs(FocusLink));
        }

        internal override void RaiseOnMouseClick(MouseEventArgs e)
        {
            PerformClick();
        }

        protected virtual void OnLinkClicked(LinkLabelLinkClickedEventArgs e)
        {
            var linkClicked = LinkClicked;
            if (linkClicked != null)
                linkClicked(this, e);
        }
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            Cursor.Current = Cursors.Hand;
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            Cursor.Current = null;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            //// It's too complex...

            base.OnPaint(e);

            // Underline.
            switch (LinkBehavior)
            {
                case LinkBehavior.SystemDefault:
                case LinkBehavior.AlwaysUnderline:
                    e.Graphics.DrawLine(underlinePen, Padding.Left, Height - 4, Width - Padding.Right, Height - 4);
                    break;
                case LinkBehavior.HoverUnderline:
                    if (uwfHovered)
                        e.Graphics.DrawLine(underlinePen, Padding.Left, Height - 4, Width - Padding.Right, Height - 4);
                    break;
            }
        }

        private static int ConvertToCharIndex(int index, string text)
        {
            if (index <= 0)
                return 0;

            if (string.IsNullOrEmpty(text))
                return index;

            var stringInfo = new StringInfo(text);
            int numTextElements = stringInfo.LengthInTextElements;

            if (index > numTextElements)
                return index - numTextElements + text.Length;

            return stringInfo.SubstringByTextElements(0, index).Length;
        }

        private void InvalidateLink(Link link)
        {
            ForeColor = LinkVisited == false ? LinkColor : VisitedLinkColor;
            underlinePen.Color = ForeColor;
        }
        private bool LinkInText(int start, int length)
        {
            return start >= 0 && start < Text.Length && length > 0;
        }

        public class Link
        {
            internal int length;
            internal LinkLabel owner;
            internal LinkState state = LinkState.Normal;

            private bool enabled = true;
            private string description;
            private object linkData;
            private string name;
            private int start;
            private object userData;

            public Link()
            {
            }
            public Link(int start, int length)
            {
                this.start = start;
                this.length = length;
            }
            public Link(int start, int length, object linkData)
            {
                this.start = start;
                this.length = length;
                this.linkData = linkData;
            }

            internal Link(LinkLabel owner)
            {
                this.owner = owner;
            }

            public string Description
            {
                get { return description; }
                set { description = value; }
            }
            public bool Enabled
            {
                get { return enabled; }
                set
                {
                    if (enabled == value) return;

                    enabled = value;

                    if ((state & (LinkState.Hover | LinkState.Active)) != 0)
                        state &= ~(LinkState.Hover | LinkState.Active);

                    if (owner != null)
                        owner.InvalidateLink(this);
                }
            }
            public int Length
            {
                get
                {
                    if (length == -1)
                    {
                        if (owner != null && !string.IsNullOrEmpty(owner.Text))
                        {
                            StringInfo stringInfo = new StringInfo(owner.Text);
                            return stringInfo.LengthInTextElements - Start;
                        }

                        return 0;
                    }
                    return length;
                }
                set
                {
                    if (length == value) return;

                    length = value;
                    if (owner != null)
                        owner.Invalidate();
                }
            }
            public object LinkData
            {
                get { return linkData; }
                set { linkData = value; }
            }
            public string Name
            {
                get { return name == null ? "" : name; }
                set { this.name = value; }
            }
            public int Start
            {
                get
                {
                    return start;
                }
                set
                {
                    if (start == value) return;
                    start = value;

                    if (owner == null) return;
                    owner.links.Sort(linkComparer);
                    owner.Invalidate();
                }
            }
            public object Tag
            {
                get { return userData; }
                set { userData = value; }
            }
            public bool Visited
            {
                get
                {
                    return (state & LinkState.Visited) == LinkState.Visited;
                }
                set
                {
                    bool old = Visited;

                    if (value)
                        state |= LinkState.Visited;
                    else
                        state &= ~LinkState.Visited;

                    if (old != Visited && owner != null)
                        owner.InvalidateLink(this);
                }
            }
        }
        public class LinkCollection : IList
        {
            private readonly LinkLabel owner;
            private int lastAccessedIndex = -1;

            public LinkCollection(LinkLabel owner)
            {
                if (owner == null)
                    throw new ArgumentNullException("owner");
                this.owner = owner;
            }

            public int Count
            {
                get
                {
                    return owner.links.Count;
                }
            }

            object ICollection.SyncRoot
            {
                get
                {
                    return this;
                }
            }
            bool ICollection.IsSynchronized
            {
                get
                {
                    return false;
                }
            }
            bool IList.IsFixedSize
            {
                get
                {
                    return false;
                }
            }
            public bool IsReadOnly
            {
                get
                {
                    return false;
                }
            }

            public virtual Link this[int index]
            {
                get
                {
                    return (Link)owner.links[index];
                }
                set
                {
                    owner.links[index] = value;
                    owner.links.Sort(linkComparer);
                    owner.Invalidate();
                }
            }
            public virtual Link this[string key]
            {
                get
                {
                    if (string.IsNullOrEmpty(key))
                        return null;

                    int index = IndexOfKey(key);
                    if (IsValidIndex(index))
                        return this[index];

                    return null;
                }
            }
            object IList.this[int index]
            {
                get
                {
                    return this[index];
                }
                set
                {
                    var link = value as Link;
                    if (link == null)
                        throw new ArgumentException("value");

                    this[index] = link;
                }
            }

            public int Add(Link value)
            {
                if (value == null)
                    return -1;

                if (owner.links.Count == 1 && this[0].Start == 0 && this[0].length == -1)
                {
                    owner.links.Clear();
                    owner.FocusLink = null;
                }

                value.owner = this.owner;

                owner.links.Add(value);

                if (owner.AutoSize)
                {
                    owner.AdjustSize();
                    owner.Invalidate();
                }

                if (owner.Links.Count > 1)
                    owner.links.Sort(linkComparer);

                owner.Invalidate();

                if (owner.Links.Count > 1)
                    return IndexOf(value);

                return 0;
            }
            public virtual void Clear()
            {
                bool doLayout = owner.links.Count > 0 && owner.AutoSize;
                owner.links.Clear();

                if (doLayout)
                {
                    owner.AdjustSize();
                    owner.Invalidate();
                }

                owner.Invalidate();
            }
            public bool Contains(Link link)
            {
                return owner.links.Contains(link);
            }
            public IEnumerator GetEnumerator()
            {
                if (owner.links != null)
                    return owner.links.GetEnumerator();

                return new Link[0].GetEnumerator();
            }
            public int IndexOf(Link link)
            {
                return owner.links.IndexOf(link);
            }
            public virtual int IndexOfKey(string key)
            {
                if (string.IsNullOrEmpty(key))
                    return -1;

                if (IsValidIndex(lastAccessedIndex))
                    if (WindowsFormsUtils.SafeCompareStrings(this[lastAccessedIndex].Name, key, true))
                        return lastAccessedIndex;

                for (int i = 0; i < this.Count; i++)
                    if (WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, true))
                    {
                        lastAccessedIndex = i;
                        return i;
                    }

                lastAccessedIndex = -1;
                return -1;
            }
            public void Remove(Link value)
            {
                if (value.owner != this.owner)
                    return;

                owner.links.Remove(value);

                if (owner.AutoSize)
                {
                    owner.AdjustSize();
                    owner.Invalidate();
                }

                owner.links.Sort(linkComparer);
                owner.Invalidate();

                if (owner.FocusLink == null && owner.links.Count > 0)
                    owner.FocusLink = (Link)owner.links[0];
            }
            public void RemoveAt(int index)
            {
                Remove(this[index]);
            }
            public virtual void RemoveByKey(string key)
            {
                int index = IndexOfKey(key);
                if (IsValidIndex(index))
                {
                    RemoveAt(index);
                }
            }

            int IList.Add(object value)
            {
                var link = value as Link;
                if (link != null)
                    return Add(link);

                throw new ArgumentException("value");
            }
            bool IList.Contains(object value)
            {
                var l = value as Link;
                if (l != null)
                    return Contains(l);

                return false;
            }
            void ICollection.CopyTo(Array array, int index)
            {
                owner.links.CopyTo(array, index);
            }
            int IList.IndexOf(object value)
            {
                var l = value as Link;
                if (l != null)
                    return IndexOf(l);

                return -1;
            }
            void IList.Insert(int index, object value)
            {
                var link = value as Link;
                if (link != null)
                    Add(link);

                throw new ArgumentException("value");
            }
            void IList.Remove(object value)
            {
                var link = value as Link;
                if (link != null)
                    Remove(link);
            }

            private bool IsValidIndex(int index)
            {
                return index >= 0 && index < Count;
            }
        }
        private class LinkComparer : IComparer
        {
            int IComparer.Compare(object x, object y)
            {
                int pos1 = ((Link)x).Start;
                int pos2 = ((Link)y).Start;

                return pos1 - pos2;
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/Padding.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public struct Padding : IEquatable<Padding>
    {
        public static readonly Padding Empty = new Padding(0);

        public Padding(int all) : this()
        {
            Left = Bottom = Right = Top = 0;

            Left = all;
            Bottom = all;
            Right = all;
            Top = all;
        }
        public Padding(int left, int bottom, int right, int top) : this()
        {
            this.Left = this.Bottom = this.Right = this.Top = 0;

            this.Left = left;
            this.Bottom = bottom;
            this.Right = right;
            this.Top = top;
        }

        public int Bottom { get; set; }
        public int Left { get; set; }
        public int Horizontal { get { return Left + Right; } }
        public int Right { get; set; }
        public Size Size
        {
            get { return new Size(Horizontal, Vertical); }
        }
        public int Top { get; set; }
        public int Vertical { get { return Top + Bottom; } }

        public static Padding operator +(Padding p1, Padding p2)
        {
            return new Padding(p1.Left + p2.Left, p1.Top + p2.Top, p1.Right + p2.Right, p1.Bottom + p2.Bottom);
        }
        public static Padding operator -(Padding p1, Padding p2)
        {
            return new Padding(p1.Left - p2.Left, p1.Top - p2.Top, p1.Right - p2.Right, p1.Bottom - p2.Bottom);
        }
        public static bool operator ==(Padding p1, Padding p2)
        {
            if (p1.Left == p2.Left && p1.Top == p2.Top && p1.Right == p2.Right)
                return p1.Bottom == p2.Bottom;
            return false;
        }
        public static bool operator !=(Padding p1, Padding p2)
        {
            return !(p1 == p2);
        }

        public bool Equals(Padding other)
        {
            return Bottom == other.Bottom && Left == other.Left && Right == other.Right && Top == other.Top;
        }
        public override bool Equals(object obj)
        {
            if (obj is Padding)
                return (Padding) obj == this;
            return false;
        }
        public override int GetHashCode()
        {
            return Left
                   ^ WindowsFormsUtils.RotateLeft(Top, 8)
                   ^ WindowsFormsUtils.RotateLeft(Right, 16)
                   ^ WindowsFormsUtils.RotateLeft(Bottom, 24);
        }
        public override string ToString()
        {
            return "{Left=" + Left + ",Top=" + Top + ",Right=" + Right + ",Bottom=" + Bottom + "}";
        }
    }
}


<|start_filename|>Assets/Core/API/ITexture.cs<|end_filename|>
﻿namespace System.Drawing.API
{
    public interface ITexture
    {
        int Height { get; }
        int Width { get; }

        void    Apply();
        void    Clear(Color color);
        Color   GetPixel(int x, int y);
        Color[] GetPixels();
        Color[] GetPixels(int x, int y, int width, int height);
        void    SetPixel(int x, int y, Color color);
        void    SetPixels(Color[] colors);
        void    SetPixels(int x, int y, int width, int height, Color[] colors);
    }
}

<|start_filename|>Assets/Examples/Panels/PanelTabControl.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Drawing;
    using System.Windows.Forms;

    public class PanelTabControl : BaseExamplePanel
    {
        public override void Initialize()
        {
            this.Create<Label>("Empty");
            this.Create<TabControl>("", true);

            var button1 = new Button();
            button1.Location = new Point(8, 8);
            button1.Text = "button1";
            
            var button2 = new Button();
            button2.Location = new Point(480, 360);
            button2.Text = "button2";
            
            var page1 = new TabPage("First");
            page1.AutoScroll = true;
            page1.Controls.Add(button1);
            page1.Controls.Add(button2);
            
            var label = new Label();
            label.Location = new Point(8, 8);
            label.Text = "label1";
            
            var page2 = new TabPage("Second");
            page2.Controls.Add(label);
            
            var tabControl = this.Create<TabControl>(8, 116);
            tabControl.BackColor = Color.Transparent;
            tabControl.Padding = new Padding(0);
            tabControl.TabPages.Add(page1);
            tabControl.TabPages.Add(page2);
            tabControl.TabPages.Add("Third");
            tabControl.TabPages.Add("Forth");
            tabControl.TabPages.Add("Fifth");
            
            // Autosize is not working for page headers.
            tabControl.SetPageButtonWidth(0, 48);
        }
    }
}

<|start_filename|>Assets/Unity/Views/AppControlList.cs<|end_filename|>
﻿#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using SWF = System.Windows.Forms;

namespace Unity.Views
{
    public class AppControlList : EditorWindow
    {
        private string filter = "";
        private float _repaintWait;
        private Vector2 scrollPosition;

        void Update()
        {
            if (_repaintWait < 1)
                _repaintWait += Time.deltaTime;
            else
            {
                Repaint();
                _repaintWait = 0;
            }
        }
        void OnGUI()
        {
            if (!Application.isPlaying) return;
            if (SWF.Control.uwfDefaultController == null)
            {
                GUILayout.Label("SWF.Control.DefaultController is null");
                return;
            }
            
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            GUILayout.BeginVertical();
            filter = GUILayout.TextField(filter).ToLower();
            
            GUILayout.Label("Context");
            
            for (int i = 0; i < SWF.Control.uwfDefaultController.Contexts.Count; i++)
                PaintControl(SWF.Control.uwfDefaultController.Contexts[i]);

            GUILayout.Space(24);
            GUILayout.Label("Modal Forms");

            for (int i = 0; i < SWF.Control.uwfDefaultController.ModalForms.Count; i++)
                PaintControl(SWF.Control.uwfDefaultController.ModalForms[i]);

            GUILayout.Space(24);
            GUILayout.Label("Forms");
            
            for (int i = 0; i < SWF.Control.uwfDefaultController.Forms.Count; i++)
                PaintControl(SWF.Control.uwfDefaultController.Forms[i]);

            GUILayout.Space(24);
            GUILayout.Label("Hovered Control");

            var hoveredControl = SWF.Control.uwfDefaultController.hoveredControl;
            if (hoveredControl != null) 
                PaintControl(hoveredControl);
            
            GUILayout.EndVertical();
            GUILayout.EndScrollView();
        }

        private void PaintControl(SWF.Control control)
        {
            string controlType = control.GetType().ToString().Replace("System.Windows.Forms", "SWF");
            string controlName = control.Name;
                
            if (controlName == null) 
                controlName = "";
                
            if (!string.IsNullOrEmpty(filter))
            {
                if (!controlType.ToLower().Contains(filter) && !controlName.ToLower().Contains(filter))
                    return;
            }

            GUILayout.BeginHorizontal();
                
            if (GUILayout.Button("...", GUILayout.Width(24)))
            {
                EditorMenu.ShowInspector();
                ControlInspector.DesignerObject = control;
            }
                
            GUILayout.Label(control.GetHashCode().ToString("X2"), GUILayout.Width(64));
            GUILayout.Label(controlType);
            GUILayout.Label(controlName);
            GUILayout.EndHorizontal();
        }
    }
}

#endif

<|start_filename|>Assets/Unity/Views/ControlInspector.cs<|end_filename|>
﻿#if UNITY_EDITOR

namespace Unity.Views
{
    using System;
    using System.Windows.Forms;

    using UnityEngine;
    using UnityEditor;

    public class ControlInspector : EditorWindow
    {
        private IObjectDesigner designer;
        private float repaintWait;
        private Vector2 scrollPosition;

        internal static object DesignerObject;
        
        void Awake()
        {
            var iDisposable = DesignerObject as IDisposable;
            if (iDisposable != null)
                iDisposable.Dispose();
            
            DesignerObject = null;
        }
        void Update()
        {
            if (repaintWait < 1f)
                repaintWait += Time.deltaTime;
            else
            {
                Repaint();
                repaintWait = 0;
            }
        }
        void OnGUI()
        {
            if (DesignerObject == null) return;

            var control = DesignerObject as Control;
            if (control != null && (control.Disposing || control.IsDisposed) || !UnityEngine.Application.isPlaying)
            {
                DesignerObject = null;
                return;
            }

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            if (designer == null || designer.Value != DesignerObject)
                designer = new ObjectDesigner(DesignerObject);
            
            var newObject = designer.Draw((int)position.width - 8, int.MaxValue);
            if (newObject != null)
                DesignerObject = newObject;
            
            GUILayout.EndScrollView();
        }
    }
}

#endif

<|start_filename|>Assets/System/Windows/Forms/FlatStyle.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum FlatStyle
    {
        Flat,
        Popup,
        Standard,
        System,
    }
}


<|start_filename|>Assets/Examples/Panels/PanelFontDialog.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;
    
    public class PanelFontDialog : BaseExamplePanel
    {
        public override void Initialize()
        {
            var label = this.Create<Label>("Selected font:");
            var button = this.Create<Button>("Show");
            button.Click += (sender, args) =>
            {
                var fd = new FontDialog();
                fd.Font = label.Font;
                fd.FormClosed += (o, eventArgs) =>
                {
                    if (fd.DialogResult == DialogResult.OK)
                    {
                        label.Font = fd.Font;
                        label.Text = "Selected font: " + fd.Font;
                    }
                };
                fd.ShowDialog();
            };
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/AppGdiImages.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    internal class AppGdiImages
    {
        public Bitmap ArrowDown;
        public Bitmap ArrowLeft;
        public Bitmap ArrowRight;
        public Bitmap ArrowUp;
        public Bitmap Circle;
        public Bitmap Checked;
        public Bitmap Close;
        public CursorImages Cursors = new CursorImages();
        public Bitmap CurvedArrowDown;
        public Bitmap CurvedArrowLeft;
        public Bitmap CurvedArrowRight;
        public Bitmap CurvedArrowUp;
        public Bitmap DateTimePicker;
        public Bitmap DropDownRightArrow;
        public Bitmap FileDialogBack;
        public Bitmap FileDialogFile;
        public Bitmap FileDialogFolder;
        public Bitmap FileDialogRefresh;
        public Bitmap FileDialogUp;
        public Bitmap FormResize;
        public Bitmap NumericDown;
        public Bitmap NumericUp;
        public Bitmap RadioButton_Checked;
        public Bitmap RadioButton_Hovered;
        public Bitmap RadioButton_Unchecked;
        public Bitmap TreeNodeCollapsed;
        public Bitmap TreeNodeExpanded;

        public struct CursorImages
        {
            public Bitmap Default;

            public Bitmap Hand;
            public Bitmap Help;
            public Bitmap HSplit;
            public Bitmap IBeam;
            public Bitmap SizeAll;
            public Bitmap SizeNESW;
            public Bitmap SizeNS;
            public Bitmap SizeNWSE;
            public Bitmap SizeWE;
            public Bitmap VSplit;
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/LayoutEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.ComponentModel;

    public class LayoutEventArgs : EventArgs
    {
        private readonly IComponent affectedComponent;
        private readonly string     affectedProperty;

        public LayoutEventArgs(IComponent affectedComponent, string affectedProperty)
        {
            this.affectedComponent = affectedComponent;
            this.affectedProperty = affectedProperty;
        }
        public LayoutEventArgs(Control affectedControl, string affectedProperty) : this((IComponent)affectedControl, affectedProperty)
        {
        }

        public IComponent AffectedComponent
        {
            get
            {
                return this.affectedComponent;
            }
        }
        public Control AffectedControl
        {
            get
            {
                return this.affectedComponent as Control;
            }
        }
        public string AffectedProperty
        {
            get
            {
                return this.affectedProperty;
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ListBox.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Drawing;

    public class ListBox : ListControl
    {
        public const int DefaultItemHeight = 13;

        private readonly Pen borderPen = new Pen(Color.Black);
        private readonly ObjectCollection items;
        private readonly VScrollBar vScroll;

        private int borderOffset = 2;
        private BorderStyle borderStyle = BorderStyle.Fixed3D;
        private int hoveredItem = -1;
        private bool integralHeight = true;
        private bool integralHeightAdjust = true;
        private int itemHeight = DefaultItemHeight;
        private string keyFilter = "";
        private Timer keyTimer;
        private int keyFilterResetTime = 3; // seconds.
        private int visibleItemsCount = 0;
        private bool scrollAlwaysVisible;
        private int selectedIndex = -1;

        public ListBox()
        {
            items = new ObjectCollection(this);

            BackColor = Color.White;
            DrawMode = DrawMode.Normal;
            DrawItem = InternalDrawItem;
            uwfWrapText = true;

            uwfItemDisabledColor = Color.Gray;
            uwfItemHoverColor = Color.FromArgb(221, 238, 253);
            uwfSelectionBackColor = SystemColors.Highlight;
            uwfSelectionDisabledColor = Color.FromArgb(101, 203, 255);
            uwfSelectionForeColor = SystemColors.HighlightText;
            
            vScroll = new VScrollBar();
            vScroll.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            vScroll.Location = new Point(Width - vScroll.Width, 0);
            vScroll.Height = Height;
            vScroll.Visible = false;
            Controls.Add(vScroll);

            UpdateBorder();
        }

        public event EventHandler SelectedIndexChanged;
        public event DrawItemEventHandler DrawItem;

        public BorderStyle BorderStyle
        {
            get { return borderStyle; }
            set
            {
                borderStyle = value;

                UpdateBorder();
            }
        }
        public virtual DrawMode DrawMode { get; set; }
        [Obsolete("Use with caution, 'Anchor' property can resize this control unexpectedly")]
        public bool IntegralHeight
        {
            get { return integralHeight; }
            set
            {
                integralHeight = value;
                if (integralHeight)
                {
                    integralHeightAdjust = true;
                    AdjustHeight();
                }
            }
        }
        public virtual int ItemHeight
        {
            get { return itemHeight; }
            set
            {
                itemHeight = value;
                RefreshItems();
            }
        }
        public ObjectCollection Items { get { return items; } }
        public int PreferredHeight
        {
            get
            {
                int height = 0;
                var itemsCount = Items.Count;
                if (itemsCount == 0) itemsCount = 1;
                height = ItemHeight * itemsCount + borderOffset * 2;
                return height;
            }
        }
        public bool ScrollAlwaysVisible
        {
            get { return scrollAlwaysVisible; }
            set
            {
                scrollAlwaysVisible = value;
                RefreshItems();
            }
        }
        public override int SelectedIndex
        {
            get { return selectedIndex; }
            set
            {
                if (value < -1 || value >= items.Count) return;

                bool changed = selectedIndex != value && value != -1;
                selectedIndex = value;
                if (changed) OnSelectedIndexChanged(EventArgs.Empty);
            }
        }
        public object SelectedItem
        {
            get
            {
                if (SelectedIndex == -1 || SelectedIndex >= Items.Count) 
                    return null;
                
                return Items[SelectedIndex];
            }
            set
            {
                for (int i = 0; i < Items.Count; i++)
                    if (value == Items[i])
                    {
                        SelectItem(i);
                        break;
                    }
            }
        }
        
        internal Color uwfItemDisabledColor { get; set; }
        internal Color uwfItemHoverColor { get; set; }
        internal Color uwfSelectionBackColor { get; set; }
        internal Color uwfSelectionDisabledColor { get; set; }
        internal Color uwfSelectionForeColor { get; set; }
        internal int uwfScrollIndex
        {
            get { return vScroll.Value / ItemHeight; }
            set { vScroll.Value = value * ItemHeight; }
        }
        internal bool uwfWrapText { get; set; }
        
        protected override Size DefaultSize
        {
            get { return new Size(120, 96); }
        }

        internal void EnsureVisible()
        {
            if (SelectedIndex < uwfScrollIndex)
                uwfScrollIndex = SelectedIndex;

            if (SelectedIndex > uwfScrollIndex + visibleItemsCount - 1)
                uwfScrollIndex = SelectedIndex - visibleItemsCount + 1;

            if (uwfScrollIndex < 0)
                uwfScrollIndex = 0;
        }
        internal int FindItemIndex(Predicate<object> match)
        {
            for (int i = 0; i < Items.Count; i++)
            {
                var item = Items[i];
                if (match(item)) return i;
            }
            return -1;
        }
        internal int IndexAt(Point mclient)
        {
            return uwfScrollIndex + (int)((mclient.Y - borderOffset) / ItemHeight);
        }
        internal void SelectItem(int index)
        {
            if (index < 0 && Items.Count == 0) return;

            if (index < 0) index = 0;
            if (index >= Items.Count) index = Items.Count - 1;

            SelectedIndex = index;
            EnsureVisible();
            OnSelectedValueChanged(EventArgs.Empty);
        }
        internal void RefreshItems()
        {
            visibleItemsCount = (int)Math.Ceiling((float)(Height - borderOffset * 2) / ItemHeight);

            if (vScroll != null)
            {
                vScroll.Maximum = Items.Count * ItemHeight;
                vScroll.SmallChange = ItemHeight;
                vScroll.LargeChange = vScroll.Height;
                vScroll.Visible = ScrollAlwaysVisible || visibleItemsCount < Items.Count;
            }
        }
        internal void UpdateBorder()
        {
            switch (borderStyle)
            {
                case BorderStyle.None:
                    borderOffset = 0;
                    borderPen.Width = 0;
                    vScroll.Location = new Point(Width - vScroll.Width, 0);
                    vScroll.Height = Height;
                    break;
                case BorderStyle.FixedSingle:
                case BorderStyle.Fixed3D:
                    borderOffset = 2;
                    borderPen.Width = 1;
                    vScroll.Location = new Point(Width - vScroll.Width - borderOffset, borderOffset);
                    vScroll.Height = Height - borderOffset * 2;
                    break;
            }
        }
        
        protected internal override void uwfOnLatePaint(PaintEventArgs e)
        {
            base.uwfOnLatePaint(e);

            ControlPaint.PrintBorder(e.Graphics, ClientRectangle, BorderStyle, Border3DStyle.Flat);
        }

        protected virtual void OnDrawItem(DrawItemEventArgs e)
        {
            if (DrawItem != null)
                DrawItem(this, e);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            
            switch (e.KeyCode)
            {
                case Keys.Down:
                case Keys.Right:
                    SelectItem(SelectedIndex + 1);
                    break;
                case Keys.Left:
                case Keys.Up:
                    SelectItem(SelectedIndex - 1);
                    break;

                case Keys.PageDown:
                    SelectItem(SelectedIndex + visibleItemsCount - 1);
                    break;
                case Keys.PageUp:
                    SelectItem(SelectedIndex - visibleItemsCount + 1);
                    break;

                case Keys.Home:
                    SelectItem(0);
                    break;
                case Keys.End:
                    SelectItem(Items.Count - 1);
                    break;

                default:

                    // Key filter.
                    char c = KeyHelper.GetLastInputChar();
                    if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
                    {
                        keyFilter += char.ToLower(c);
                        var itemIndex = FindItemIndex(x =>
                        {
                            if (x == null)
                                return false;

                            var xStr = x.ToString();
                            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                            return xStr != null && xStr.ToLower().StartsWith(keyFilter);
                        });
                        SelectItem(itemIndex);

                        if (keyTimer == null)
                        {
                            keyTimer = new Timer();
                            keyTimer.Interval = keyFilterResetTime * 1000;
                            keyTimer.Tick += (sender, args) => ResetKeyFilter();
                        }
                        
                        keyTimer.Stop();
                        keyTimer.Start();
                    }
                    break;
            }
        }
        protected override void OnMouseHover(EventArgs e)
        {
            base.OnMouseHover(e);
            var mclient = PointToClient(MousePosition);
            var itemIndex = IndexAt(mclient);

            hoveredItem = itemIndex;
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            hoveredItem = -1;
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            if (e.Delta < 0)
                vScroll.DoScroll(ScrollEventType.SmallIncrement);
            else
                vScroll.DoScroll(ScrollEventType.SmallDecrement);
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            var mclient = PointToClient(MousePosition);
            var itemIndex = IndexAt(mclient);

            SelectItem(itemIndex);

            base.OnMouseUp(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var g = e.Graphics;

            const int itemTextVerticalPadding = -3;

            // Paint list.
            g.uwfFillRectangle(BackColor, 0, 0, Width, Height);
            
            for (int i = 0; i < visibleItemsCount && i + uwfScrollIndex < Items.Count; i++)
            {
                var itemIndex = i + uwfScrollIndex;
                if (itemIndex < 0) continue;

                var item = Items[itemIndex];
                var itemY = borderOffset + i * ItemHeight;
                var itemW = uwfWrapText ? Width : Width * 5;
                var itemSelected = itemIndex == SelectedIndex;
                var itemHovered = itemIndex == hoveredItem;
                var itemForeColor = ForeColor;

                if (itemSelected)
                    itemForeColor = uwfSelectionForeColor;

                var itemBackColor = Color.Transparent;
                if (itemSelected || itemHovered)
                {
                    itemBackColor = uwfItemHoverColor;
                    if (itemSelected)
                        itemBackColor = uwfSelectionBackColor;
                }

                var fillWidth = Width;
                if (vScroll.Visible)
                    fillWidth = vScroll.Location.X - borderOffset;

                var itemText = "";
                if (item != null)
                    itemText = item.ToString();

                if (DrawMode == DrawMode.Normal)
                {
                    g.uwfFillRectangle(itemBackColor, borderOffset, itemY, fillWidth, ItemHeight);
                    g.uwfDrawString(
                        itemText,
                        Font,
                        itemForeColor,
                        borderOffset + 2,
                        itemY + itemTextVerticalPadding,
                        itemW,
                        ItemHeight - itemTextVerticalPadding * 2,
                        ContentAlignment.MiddleLeft);
                }
                else
                {
                    var itemRect = new Rectangle(
                        borderOffset + 2,
                        itemY,
                        fillWidth,
                        ItemHeight);
                    
                    var state = itemSelected ? DrawItemState.Selected : DrawItemState.Default;
                    var args = new DrawItemEventArgs(g, Font, itemRect, itemIndex, state, itemForeColor, itemBackColor);
                    
                    OnDrawItem(args);
                }
            }
        }
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            if (IntegralHeight && integralHeightAdjust)
                AdjustHeight();

            RefreshItems();
        }
        protected override void OnSelectedIndexChanged(EventArgs e)
        {
            var selectedIndexChanged = SelectedIndexChanged;
            if (selectedIndexChanged != null)
                selectedIndexChanged(this, e);
        }

        private void AdjustHeight()
        {
            // TODO: precise losing in long term.
            integralHeightAdjust = false;
            Height = (int)(Math.Ceiling((float)Height / ItemHeight) * ItemHeight) + borderOffset * 2;
            integralHeightAdjust = true;
        }
        private void InternalDrawItem(object sender, DrawItemEventArgs e)
        {
            var item = Items[e.Index];
            var itemText = "";
            if (item != null)
                itemText = item.ToString();

            e.DrawBackground();
            e.Graphics.uwfDrawString(itemText, e.Font, e.ForeColor, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height, ContentAlignment.MiddleLeft);
            e.DrawFocusRectangle();
        }
        private void ResetKeyFilter()
        {
            keyFilter = "";
            keyTimer.Dispose();
            keyTimer = null;
        }

        public class ObjectCollection : IList
        {
            private readonly List<object> items = new List<object>();
            private readonly ListBox owner;

            public ObjectCollection(ListBox owner)
            {
                this.owner = owner;
            }
            public ObjectCollection(ListBox owner, ObjectCollection value)
            {
                this.owner = owner;
                AddRange(value);
            }
            public ObjectCollection(ListBox owner, object[] value)
            {
                this.owner = owner;
                AddRange(value);
            }

            public int Count { get { return items.Count; } }
            public bool IsFixedSize
            {
                get { return false; }
            }
            public bool IsReadOnly { get { return false; } }
            public bool IsSynchronized
            {
                get { return false; }
            }
            public object SyncRoot
            {
                get { return this; }
            }

            public virtual object this[int index]
            {
                get { return items[index]; }
                set { items[index] = value; }
            }

            public int Add(object item)
            {
                var index = AddInternal(item);
                return index;
            }
            public void AddRange(ObjectCollection value)
            {
                for (int i = 0; i < value.Count; i++)
                    AddInternal(value[i]);
            }
            public void AddRange(object[] array)
            {
                for (int i = 0; i < array.Length; i++)
                    AddInternal(array[i]);
            }
            public void Clear()
            {
                items.Clear();
                owner.uwfScrollIndex = 0;
                owner.selectedIndex = -1;
            }
            public bool Contains(object value)
            {
                return items.Contains(value);
            }
            public void CopyTo(Array array, int index)
            {
                items.CopyTo((object[])array, index);
            }
            public void CopyTo(object[] destination, int arrayIndex)
            {
                items.CopyTo(destination, arrayIndex);
            }
            public IEnumerator GetEnumerator()
            {
                return items.GetEnumerator();
            }
            public int IndexOf(object value)
            {
                return items.IndexOf(value);
            }
            public void Insert(int index, object value)
            {
                items.Insert(index, value);
            }
            public void Remove(object value)
            {
                items.Remove(value);
                owner.RefreshItems();
            }
            public void RemoveAt(int index)
            {
                items.RemoveAt(index);
                owner.RefreshItems();
            }

            private int AddInternal(object item)
            {
                items.Add(item);
                owner.RefreshItems();

                return items.Count - 1;
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/InputLanguage.cs<|end_filename|>
#if UNITY_STANDALONE_WIN
#define KEYBOARD_LAYOUT_SUPPORTED
#endif

namespace System.Windows.Forms
{
    using System.Globalization;

    public sealed class InputLanguage
    {
        private readonly IntPtr handle;

        internal InputLanguage(IntPtr handle)
        {
            this.handle = handle;
        }

        public CultureInfo Culture
        {
            get { return new CultureInfo((int) handle & 0xFFFF); }
        }

        public static InputLanguage CurrentInputLanguage
        {
            get
            {
#if KEYBOARD_LAYOUT_SUPPORTED
                return new InputLanguage(SafeNativeMethods.GetKeyboardLayout(0));
#else
                throw new NotSupportedException("keyboard layout");
#endif
            }
        }
        public IntPtr Handle
        {
            get { return handle; }
        }

        public override int GetHashCode()
        {
            return unchecked((int) (long) handle);
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/RightToLeft.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum RightToLeft
    {
        No = 0,
        Yes = 1,
        Inherit = 2
    }
}


<|start_filename|>Assets/Examples/Panels/PanelNumericUpDown.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelNumericUpDown : BaseExamplePanel
    {
        public override void Initialize()
        {
            this.Create<NumericUpDown>();
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ContextMenuStrip.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.ComponentModel;

    public class ContextMenuStrip : ToolStripDropDownMenu
    {
        public ContextMenuStrip()
        {
        }
        public ContextMenuStrip(IContainer container)
        {
            if (container == null)
                throw new ArgumentNullException("container");
            container.Add(this);
        }
    }
}


<|start_filename|>Assets/System/Drawing/ColorTranslator.cs<|end_filename|>
﻿namespace System.Drawing
{
    public static class ColorTranslator
    {
        public static Color FromHtml(string htmlColor)
        {
            if (string.IsNullOrEmpty(htmlColor)) return Color.Empty;

            Color result = Color.Empty;
            if (htmlColor[0] == '#')
                htmlColor = htmlColor.Substring(1);

            switch (htmlColor.Length)
            {
                case 3: // half.
                    string halfRed = char.ToString(htmlColor[0]);
                    string halfGreen = char.ToString(htmlColor[1]);
                    string halfBlue = char.ToString(htmlColor[2]);
                    int red = Convert.ToInt32(halfRed + halfRed, 16);
                    int green = Convert.ToInt32(halfGreen + halfGreen, 16);
                    int blue = Convert.ToInt32(halfBlue + halfBlue, 16);
                    result = Color.FromArgb(red, green, blue);
                    break;
                case 6: // rgb.
                    result = Color.FromArgb(
                    Convert.ToInt32(htmlColor.Substring(0, 2), 16),
                    Convert.ToInt32(htmlColor.Substring(2, 2), 16),
                    Convert.ToInt32(htmlColor.Substring(4, 2), 16));
                    break;
                case 8: // argb.
                    result = Color.FromArgb(
                    Convert.ToInt32(htmlColor.Substring(0, 2), 16),
                    Convert.ToInt32(htmlColor.Substring(2, 2), 16),
                    Convert.ToInt32(htmlColor.Substring(4, 2), 16),
                    Convert.ToInt32(htmlColor.Substring(6, 2), 16));
                    break;
            }

            return result;
        }
        public static Color FromOle(int oleColor)
        {
            throw new NotImplementedException();
        }
        public static Color FromWin32(int win32Color)
        {
            return FromOle(win32Color);
        }
        public static string ToHtml(Color c)
        {
            return string.Concat("#", c.A.ToString("X2"), c.R.ToString("X2"), c.G.ToString("X2"), c.B.ToString("X2"));
        }
        public static int ToOle(Color c)
        {
            throw new NotImplementedException();
        }
        public static int ToWin32(Color c)
        {
            return c.R | c.G << 8 | c.B << 16;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/BoundsSpecified.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    [Flags]
    public enum BoundsSpecified
    {
        X = 1,
        Y = 2,
        Width = 4,
        Height = 8,
        Location = Y | X,
        Size = Height | Width,
        All = Size | Location,
        None = 0,
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripItemCollection.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Drawing;

    public class ToolStripItemCollection : IEnumerator<ToolStripItem>, IEnumerable<ToolStripItem>
    {
        private readonly List<ToolStripItem> items = new List<ToolStripItem>();
        private readonly ToolStrip owner;

        public ToolStripItemCollection(ToolStrip owner, ToolStripItem[] value)
        {
            this.owner = owner;
            if (value != null)
                items.AddRange(value);
        }

        public int Count { get { return items.Count; } }
        public ToolStripItem Current
        {
            get { return items.GetEnumerator().Current; }
        }
        object IEnumerator.Current
        {
            get { return items.GetEnumerator().Current; }
        }

        public virtual ToolStripItem this[int index] { get { return items[index]; } }

        public ToolStripItem Add(string text)
        {
            var item = new ToolStripButton();
            item.Text = text;
            AddInternal(item);
            return item;
        }
        public int Add(ToolStripItem value)
        {
            AddInternal(value);
            return items.Count - 1;
        }
        public void AddRange(ToolStripItem[] toolStripItems)
        {
            AddInternal(toolStripItems);
        }
        public void AddRange(ToolStripItemCollection toolStripItems)
        {
            foreach (var item in toolStripItems)
                AddInternal(item);
        }
        public virtual void Clear()
        {
            items.Clear();
        }
        public bool Contains(ToolStripItem value)
        {
            return items.Contains(value);
        }
        public void CopyTo(ToolStripItem[] array, int index)
        {
            items.CopyTo(array, index);
        }
        public int IndexOf(ToolStripItem value)
        {
            for (int i = 0, index = 0; i < items.Count; i++)
            {
                if (items[i] == value)
                    return index;
                index++;
            }

            return -1;
        }
        public void Insert(int index, ToolStripItem value)
        {
            items.Insert(index, value);
            SetOwner(value);
        }
        public void Remove(ToolStripItem value)
        {
            items.Remove(value);
            OnAfterRemove(value);
        }
        public void RemoveAt(int index)
        {
            if (index < 0 || index >= items.Count)
                return;

            var item = items[index];
            items.RemoveAt(index);
            OnAfterRemove(item);
        }

        public bool MoveNext()
        {
            return items.GetEnumerator().MoveNext();
        }
        public void Reset()
        {
        }
        public void Dispose()
        {
            items.GetEnumerator().Dispose();
        }
        public IEnumerator<ToolStripItem> GetEnumerator()
        {
            return items.GetEnumerator();
        }
        IEnumerator IEnumerable.GetEnumerator()
        {
            return items.GetEnumerator();
        }

        private void AddInternal(params ToolStripItem[] newItems)
        {
            this.items.AddRange(newItems);
            for (int i = 0; i < newItems.Length; i++)
            {
                var item = newItems[i];
                if (item == null)
                    throw new ArgumentException("item is null");

                SetOwner(item);
            }

            if (owner != null)
                owner.UpdateSize();
        }
        private void OnAfterRemove(ToolStripItem item)
        {
            if (item == null)
                return;
            item.SetOwner(null);
        }
        private void SetOwner(ToolStripItem item)
        {
            if (item == null) return;
            if (item.Owner != null)
                item.Owner.Items.Remove(item);

            item.SetOwner(owner);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/FormBorderStyle.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum FormBorderStyle
    {
        [Obsolete("not supported yet")]
        None = 0,
        FixedSingle = 1,
        [Obsolete("not supported yet")]
        Fixed3D = 2,
        [Obsolete("not supported yet")]
        FixedDialog = 3,
        Sizable = 4,
        [Obsolete("not supported yet")]
        FixedToolWindow = 5,
        [Obsolete("not supported yet, same as Sizable")]
        SizableToolWindow = 6,
    }
}


<|start_filename|>Assets/System/Windows/Forms/ComboBox.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Drawing;

    public class ComboBox : ListControl
    {
        internal Color uwfBackColorDropDownList = Color.FromArgb(235, 235, 235);
        internal Color uwfBorderColor = Color.DarkGray;
        internal Color uwfBorderColorDisabled = Color.FromArgb(217, 217, 217);
        internal Color uwfBorderColorHovered = Color.FromArgb(126, 180, 234);
        internal Color uwfDisabledColor = SystemColors.Control;
        internal Color uwfHoverColor = Color.White;
        internal Color uwfHoverColorDropDownList = Color.FromArgb(227, 240, 252);
        internal Color uwfListItemHoverColor = Color.FromArgb(221, 238, 253);
        internal Color uwfListItemSelectedBackgroundColor = SystemColors.Highlight;
        internal Color uwfListItemSelectedForeColor = SystemColors.HighlightText;
        internal bool  uwfWrapText;
        
        private const int DOWN_BUTTON_WIDTH = 17;
        private const int ARROW_IMAGE_SIZE = 16;

        private readonly Pen borderPen = new Pen(Color.Transparent);
        private readonly Pen downButtonBorderPen = new Pen(Color.Transparent);

        private string keyFilter;
        private bool resetKeyFilter;
        private int itemHeight = 15;
        private ComboListBoxPanel listBoxPanel; // Need this to move a listBox down and overlap it's painting. 
        private bool listBoxOpened;
        private bool listBoxRecentlyClosed;
        private int maxDropDownItems = 8;
        private int selectedIndex = -1;
        private bool selectTextOnFocus;

        public ComboBox()
        {
            Items = new ObjectCollection(this);

            AutoCompleteMode = AutoCompleteMode.None;
            AutoCompleteSource = AutoCompleteSource.None;
            BackColor = Color.White;
            DropDownStyle = ComboBoxStyle.DropDown;
            Padding = new Padding(4, 0, 4, 0);
            Text = ""; // At the start DrawTextField will return string.Empty, it should be equal to filter value.
        }

        public event EventHandler DropDown;
        public event EventHandler DropDownClosed;
        public event EventHandler SelectedIndexChanged;

        public AutoCompleteMode AutoCompleteMode { get; set; }
        public AutoCompleteSource AutoCompleteSource { get; set; }
        public ComboBoxStyle DropDownStyle { get; set; }
        public int ItemHeight
        {
            get { return itemHeight; }
            set
            {
                if (value < 1)
                    throw new ArgumentOutOfRangeException("value");
                
                itemHeight = value;
            }
        }
        public ComboBox.ObjectCollection Items { get; private set; }
        public int MaxDropDownItems
        {
            get { return maxDropDownItems; }
            set { if (value > 1 && value <= 100) maxDropDownItems = value; }
        }
        public override int SelectedIndex
        {
            get { return selectedIndex; }
            set
            {
                if (selectedIndex == value) return;

                selectedIndex = value;
                UpdateText();

                OnSelectedItemChanged(EventArgs.Empty);
                OnSelectedIndexChanged(EventArgs.Empty);
            }
        }
        public object SelectedItem
        {
            get
            {
                if (SelectedIndex > -1 && SelectedIndex < Items.Count)
                    return Items[SelectedIndex];
                
                return null;
            }
            set { SelectedIndex = Items.IndexOf(value); }
        }

        protected override Size DefaultSize
        {
            get { return new Size(121, 21); }
        }

        private int SelectedIndexInternal
        {
            get { return listBoxPanel == null ? SelectedIndex : listBoxPanel.listBox.SelectedIndex; }
        }
        
        internal override bool FocusInternal()
        {
            if (Enabled && DropDownStyle == ComboBoxStyle.DropDown && !Focused)
                selectTextOnFocus = true;
            
            return base.FocusInternal();
        }

        protected virtual void OnDropDown(EventArgs e)
        {
            var handler = DropDown;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnDropDownClosed(EventArgs e)
        {
            var handler = DropDownClosed;
            if (handler != null)
                handler(this, e);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            switch (e.KeyCode)
            {
                case Keys.Down:
                    SelectItem(SelectedIndexInternal + 1);
                    break;
             
                case Keys.Left:
                    if (DropDownStyle == ComboBoxStyle.DropDownList)
                        SelectItem(SelectedIndexInternal - 1);
                    break;
                
                case Keys.Right:
                    if (DropDownStyle == ComboBoxStyle.DropDownList)
                        SelectItem(SelectedIndexInternal + 1);
                    break;
                
                case Keys.Up:
                    SelectItem(SelectedIndexInternal - 1);
                    break;
                
                case Keys.PageDown:
                    SelectItem(SelectedIndexInternal + MaxDropDownItems);
                    break;
                
                case Keys.PageUp:
                    SelectItem(SelectedIndexInternal - MaxDropDownItems);
                    break;
                
                case Keys.Home:
                    SelectItem(0);
                    break;
                
                case Keys.End:
                    SelectItem(Items.Count);
                    break;
                
                case Keys.Return:
                    if (listBoxPanel != null && !listBoxPanel.Disposing && !listBoxPanel.IsDisposed)
                    {
                        listBoxPanel.listBox.SelectItem(listBoxPanel.listBox.SelectedIndex);
                        ApplySelectedItem();
                    }
                    break;
            }
            
            if (listBoxPanel != null && DropDownStyle == ComboBoxStyle.DropDownList)
            {
                // Filter with key input.
                if (resetKeyFilter)
                {
                    resetKeyFilter = false;
                    keyFilter = "";
                }

                char c = KeyHelper.GetLastInputChar();
                if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
                {
                    keyFilter += char.ToLower(c);
                    var itemIndex = listBoxPanel.listBox.FindItemIndex(x => x != null && x.ToString().ToLower().Contains(keyFilter));
                    if (itemIndex > -1)
                        listBoxPanel.listBox.SelectItem(itemIndex);
                }
            }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            
            Focus();
            
            if (DropDownStyle == ComboBoxStyle.DropDownList || e.X >= Width - DOWN_BUTTON_WIDTH)
            {
                resetKeyFilter = true;
                ToggleListBox();
            }
        }
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            
            OnMouseDown(e);
        }
        protected override void OnMouseHover(EventArgs e)
        {
            base.OnMouseHover(e);

            if (Enabled && DropDownStyle == ComboBoxStyle.DropDown)
            {
                var localMouse = PointToClient(MousePosition);
                if (localMouse.X < Width - DOWN_BUTTON_WIDTH)
                    Cursor.Current = Cursors.IBeam;
                else
                    Cursor.Current = Cursors.Default;
            }            
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            
            Cursor.Current = Cursors.Default;
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);
            
            if (Focused)
            {
                bool down = e.Delta < 0;
                if (down)
                {
                    if (selectedIndex + 1 < Items.Count)
                        SelectedIndex++;
                }
                else
                {
                    if (selectedIndex > 0)
                        SelectedIndex--;
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (listBoxRecentlyClosed) 
                // Wait for a frame to prevent creating new listBox when previous was recently closed.
                // (issue with disposing context controls and processing mouse input at the same time)
                listBoxRecentlyClosed = false;
            
            var g = e.Graphics;
            
            // Colors.
            var backColor = BackColor;
            var borderColor = uwfBorderColor;
            var arrowColor = Color.FromArgb(96, 96, 96);
            
            if (Enabled)
            {
                switch (DropDownStyle)
                {
                    case ComboBoxStyle.DropDown:
                        if (Focused || uwfHovered)
                        {
                            backColor = uwfHoverColor;
                            borderColor = uwfBorderColorHovered;
                        }
                        break;
                    
                    case ComboBoxStyle.DropDownList:
                        backColor = Focused || uwfHovered ? uwfHoverColorDropDownList : uwfBackColorDropDownList;
                        break;
                }

                if (Focused || uwfHovered)
                    borderColor = uwfBorderColorHovered;
            }
            else
            {
                backColor = uwfDisabledColor;
                borderColor = uwfBorderColorDisabled;
            }

            borderPen.Color = borderColor;

            var height = Height;
            var width = Width;
            var textWidth = width - DOWN_BUTTON_WIDTH;
            if (uwfWrapText == false)
                textWidth *= 2;

            // Back.
            g.uwfFillRectangle(backColor, 0, 0, width, height);

            // Style.
            switch (DropDownStyle)
            {
                case ComboBoxStyle.DropDown:

                    if (Focused && Enabled)
                    {
                        // Select text.
                        if (selectTextOnFocus || shouldFocus)
                            g.uwfFocusNext();

                        var filterBuffer = g.uwfDrawTextField(Text, Font, ForeColor, 2, 0, textWidth, height, HorizontalAlignment.Left);
                        if (filterBuffer != Text)
                        {
                            if (listBoxPanel == null || listBoxPanel.IsDisposed || listBoxPanel.Disposing) 
                                CreateListBox();

                            listBoxPanel.UpdateListBoxItems(filterBuffer);
                        }
                        
                        Text = filterBuffer;

                        if (shouldFocus)
                        {
                            e.Graphics.uwfFocus();
                            shouldFocus = false;
                        }
                        
                        if (selectTextOnFocus)
                        {
                            var te = UnityEngine.GUIUtility.GetStateObject(typeof(UnityEngine.TextEditor),
                                UnityEngine.GUIUtility.keyboardControl) as UnityEngine.TextEditor;
                            if (te != null)
                                te.SelectAll();

                            selectTextOnFocus = false;
                        }
                    }
                    else
                        g.uwfDrawString(Text, Font, ForeColor, 5, 0, textWidth, height);

                    if (uwfHovered)
                    {
                        var bRect = GetButtonRect();
                        var mclient = PointToClient(MousePosition);
                        var downButtonBackColor = backColor;

                        if (bRect.Contains(mclient))
                        {
                            arrowColor = Color.Black;
                            downButtonBackColor = uwfHoverColorDropDownList;
                            downButtonBorderPen.Color = uwfBorderColorHovered;
                        }
                        else
                            downButtonBorderPen.Color = Color.Transparent;

                        g.uwfFillRectangle(downButtonBackColor, bRect);
                        g.DrawLine(downButtonBorderPen, bRect.X, bRect.Y, bRect.X, bRect.Y + bRect.Height);
                    }
                    break;
                
                case ComboBoxStyle.DropDownList:
                    g.uwfDrawString(Text, Font, ForeColor, 5, -2, textWidth, height + 4, ContentAlignment.MiddleLeft);
                    break;
            }

            // Arrow.
            var arrowImage = uwfAppOwner.Resources.CurvedArrowDown; 
            var arrowX = width - ARROW_IMAGE_SIZE;
            var arrowY = (height - ARROW_IMAGE_SIZE) / 2f;

            g.uwfFillRectangle(backColor, arrowX, 0, ARROW_IMAGE_SIZE, height);
            g.uwfDrawImage(arrowImage, arrowColor, arrowX, arrowY, ARROW_IMAGE_SIZE, ARROW_IMAGE_SIZE);

            // Border.
            g.DrawRectangle(borderPen, 0, 0, Width, Height);
        }
        protected override void OnSelectedIndexChanged(EventArgs e)
        {
            var handler = SelectedIndexChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnSelectedItemChanged(EventArgs e)
        {
        }

        private void ApplySelectedItem()
        {
            if (listBoxPanel == null) return;
            var listSelectedItem = listBoxPanel.listBox.SelectedItem;
            
            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i] != listSelectedItem) continue;
                
                Text = listSelectedItem != null ? listSelectedItem.ToString() : "";
                SelectedItem = listSelectedItem;
                break;
            }
            
            listBoxPanel.Dispose();
            listBoxPanel = null;
        }
        private void CloseListBox()
        {
            listBoxOpened = false;
            
            if (listBoxPanel == null)
                return;

            listBoxPanel.listBox.SelectedIndexChanged -= ListBoxOnSelectedIndexChanged;
            listBoxPanel.listBox.MouseUp -= ListBoxOnMouseUp;
            listBoxPanel.listBox.KeyDown -= ListBoxOnKeyDown;
            listBoxPanel.listBox.Disposed -= ListBoxOnDisposed;
            listBoxPanel.Dispose();
            listBoxPanel = null;
            
            OnDropDownClosed(EventArgs.Empty);
            
            listBoxRecentlyClosed = true;
        }
        private void CreateListBox()
        {
            if (listBoxPanel != null)
            {
                listBoxPanel = null;
                return;
            }
            
            if (listBoxRecentlyClosed)
                return;

            var screenLocation = PointToScreen(Point.Empty);
            var height = ItemHeight * (Items.Count > MaxDropDownItems ? MaxDropDownItems : Items.Count);
            if (height < ItemHeight) 
                height = ItemHeight;
            
            listBoxPanel = new ComboListBoxPanel(this);
            listBoxPanel.Location = new Point(screenLocation.X, screenLocation.Y + Height);
            listBoxPanel.Size = new Size(Width, height + 4); // + Vertical padding for borders.
            listBoxPanel.InitializeComponent();
            
            listBoxPanel.listBox.SelectedIndexChanged += ListBoxOnSelectedIndexChanged;
            listBoxPanel.listBox.MouseUp += ListBoxOnMouseUp;
            listBoxPanel.listBox.KeyDown += ListBoxOnKeyDown;
            listBoxPanel.listBox.Disposed += ListBoxOnDisposed;

            listBoxPanel.uwfContext = true;
            
            listBoxPanel.UpdateListBoxItems(string.Empty);
            
            OnDropDown(EventArgs.Empty);
            
            listBoxOpened = true;
        }
        private Rectangle GetButtonRect()
        {
            return new Rectangle(Width - DOWN_BUTTON_WIDTH, 1, DOWN_BUTTON_WIDTH, Height - 2);
        }
        private void ListBoxOnMouseUp(object sender, MouseEventArgs mouseEventArgs)
        {
            if (mouseEventArgs.Button != MouseButtons.Left) return;

            ApplySelectedItem();
        }
        private void ListBoxOnKeyDown(object sender, KeyEventArgs keyEventArgs)
        {
            if (keyEventArgs.KeyCode != Keys.Return && keyEventArgs.KeyCode != Keys.Space) return;

            ApplySelectedItem();
        }
        private void ListBoxOnDisposed(object sender, EventArgs eventArgs)
        {
            CloseListBox();
        }
        private void ListBoxOnSelectedIndexChanged(object sender, EventArgs e)
        {
            SelectedIndex = Items.FindIndex(x => x == listBoxPanel.listBox.SelectedItem);
        }
        private void SelectItem(int index)
        {
            if (listBoxPanel != null)
            {
                listBoxPanel.listBox.SelectItem(index);
                return;
            }
            
            if (index < 0 && Items.Count == 0) return;

            if (index < 0) index = 0;
            if (index >= Items.Count) index = Items.Count - 1;

            SelectedIndex = index;
        }
        private void ToggleListBox()
        {
            if (listBoxOpened)
                CloseListBox();
            else
                CreateListBox();
        }
        
        private void UpdateText()
        {
            string text = string.Empty;

            if (SelectedIndex != -1)
            {
                var item = SelectedItem;
                if (item != null)
                    text = item.ToString();
            }

            Text = text;
        }

        public class ObjectCollection : IList
        {
            private readonly List<object> items;
            private readonly ComboBox owner;

            public ObjectCollection(ComboBox owner)
            {
                this.owner = owner;
                items = new List<object>();
            }

            public int Count { get { return items.Count; } }
            public bool IsFixedSize
            {
                get { return false; }
            }
            public bool IsReadOnly { get { return false; } }
            public bool IsSynchronized
            {
                get { return false; }
            }
            public object SyncRoot
            {
                get { return false; }
            }

            public virtual object this[int index]
            {
                get { return items[index]; }
                set { items[index] = value; }
            }

            public int Add(object item)
            {
                items.Add(item);
                return items.Count - 1;
            }
            public void AddRange(object[] array)
            {
                items.AddRange(array);
            }
            public void Clear()
            {
                items.Clear();
            }
            public bool Contains(object value)
            {
                return items.Contains(value);
            }
            public void CopyTo(Array array, int index)
            {
                items.CopyTo((object[])array, index);
            }
            public void CopyTo(object[] destination, int arrayIndex)
            {
                items.CopyTo(destination, arrayIndex);
            }
            public object Find(Predicate<object> match)
            {
                return items.Find(match);
            }
            public int FindIndex(Predicate<object> match)
            {
                return items.FindIndex(match);
            }
            public IEnumerator GetEnumerator()
            {
                return items.GetEnumerator();
            }
            public int IndexOf(object value)
            {
                return items.IndexOf(value);
            }
            public void Insert(int index, object item)
            {
                items.Insert(index, item);
            }
            public void Remove(object value)
            {
                items.Remove(value);
            }
            public void RemoveAt(int index)
            {
                items.RemoveAt(index);
            }
        }

        private class ComboListBoxPanel : Control
        {
            public ComboListBox listBox;

            private readonly ComboBox owner;
            private float currentY;
            private float listMoveSpeed;
            
            public ComboListBoxPanel(ComboBox owner)
            {
                this.owner = owner;

                BackColor = Color.Transparent;

                uwfShadowBox = true;
                uwfShadowHandler += UwfShadowHandler;
            }
            
            public void InitializeComponent()
            {
                listBox = new ComboListBox();
                listBox.BackColor = owner.BackColor;
                listBox.BorderColor = owner.uwfBorderColorHovered;
                listBox.Font = owner.Font;
                listBox.ForeColor = owner.ForeColor;
                listBox.Width = owner.Width;
                listBox.IntegralHeight = false;
                listBox.ItemHeight = owner.ItemHeight;
                listBox.Size = new Size(Width, Height);
                listBox.Location = new Point(0, -listBox.Height);

                currentY = listBox.Location.Y;
                
                listBox.uwfWrapText = false;
                //listBox.uwfShadowBox = true;
                listBox.uwfItemHoverColor = owner.uwfListItemHoverColor;
                listBox.uwfSelectionBackColor = owner.uwfListItemSelectedBackgroundColor;
                listBox.uwfSelectionForeColor = owner.uwfListItemSelectedForeColor;

                Controls.Add(listBox);

                listMoveSpeed = Math.Max(240, Height * 2);
            }
            public void UpdateListBoxItems(string listFilter)
            {
                if (listBox == null)
                    return;

                var filterLower = listFilter != null ? listFilter.ToLower() : "";
            
                listBox.Items.Clear();
            
                bool selectedIndexChanged = false;
                for (int i = 0; i < owner.Items.Count; i++)
                {
                    var item = owner.Items[i];
                    if (owner.DropDownStyle == ComboBoxStyle.DropDownList || string.IsNullOrEmpty(filterLower))
                        listBox.Items.Add(item);
                    else
                    {
                        var itemString = item.ToString().ToLower();
                        if (!itemString.StartsWith(filterLower)) continue;

                        listBox.Items.Add(item);
                        
                        if (itemString != filterLower) continue;

                        listBox.SelectedIndex = i;
                        selectedIndexChanged = true;
                    }
                }
                
                if (!selectedIndexChanged)
                {
                    listBox.SelectedIndex = owner.SelectedIndex;
                    listBox.EnsureVisible();
                }
            }

            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                
                if (currentY < 0)
                {
                    currentY = MathHelper.Step(currentY, 0, listMoveSpeed);
                    listBox.Location = new Point(0, (int) currentY);
                }
            }
            
            private void UwfShadowHandler(PaintEventArgs e)
            {
                if (listBox == null)
                    return;
            
                var listScreenLocation = listBox.uwfShadowPointToScreen(Point.Empty);
                var thisScreenLocation = this.uwfShadowPointToScreen(Point.Empty);
                
                int shX = listScreenLocation.X + 6;
                int shY = thisScreenLocation.Y + 6;
                var shadowColor = defaultShadowColor;
                var localWidth = listBox.Width;
                var localHeight = listBox.Height - (thisScreenLocation.Y - listScreenLocation.Y);
                var graphics = e.Graphics;
                
                graphics.uwfFillRectangle(shadowColor, shX + 6, shY + 6, localWidth - 12, localHeight - 12);
                graphics.uwfFillRectangle(shadowColor, shX + 5, shY + 5, localWidth - 10, localHeight - 10);
                graphics.uwfFillRectangle(shadowColor, shX + 4, shY + 4, localWidth - 8, localHeight - 8);
                graphics.uwfFillRectangle(shadowColor, shX + 3, shY + 3, localWidth - 6, localHeight - 6);
                graphics.uwfFillRectangle(shadowColor, shX + 2, shY + 2, localWidth - 4, localHeight - 4);
            }
        }
        
        private class ComboListBox : ListBox
        {
            private readonly Pen borderPen = new Pen(Color.Gray);
            
            public ComboListBox()
            {
                BorderStyle = BorderStyle.FixedSingle;
            }

            public Color BorderColor
            {
                get { return borderPen.Color; }
                set { borderPen.Color = value; }
            }

            

            protected override Size DefaultSize
            {
                get { return new Size(base.DefaultSize.Width, 0); }
            }

            protected internal override void uwfOnLatePaint(PaintEventArgs e)
            {
                e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/AnchorStyles.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    [Flags]
    public enum AnchorStyles
    {
        None = 0,
        Top = 1,
        Bottom = 2,
        Left = 4,
        Right = 8,
    }
}


<|start_filename|>Assets/System/Windows/Forms/Border3DSide.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    [Flags]
    public enum Border3DSide
    {
        Left = NativeMethods.BF_LEFT,
        Top = NativeMethods.BF_TOP,
        Right = NativeMethods.BF_RIGHT,
        Bottom = NativeMethods.BF_BOTTOM,
        Middle = NativeMethods.BF_MIDDLE,
        All = Left | Top | Right | Bottom | Middle,
    }
}


<|start_filename|>Assets/System/Windows/Forms/IDropTarget.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public interface IDropTarget
    {
        void OnDragEnter(DragEventArgs e);
        void OnDragLeave(EventArgs e);
        void OnDragDrop(DragEventArgs e);
        void OnDragOver(DragEventArgs e);
    }
}


<|start_filename|>Assets/Controls/BitmapFont.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Unity.Controls
{
    public class BitmapFont
    {
        internal Dictionary<int, BitmapChar> textureList;

        public bool Loaded { get; private set; }

        public BitmapFont()
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fontImage"></param>
        /// <param name="format">GHL format (FontBuilder)</param>
        public void Load(Bitmap fontImage, byte[] format)
        {
            var ser = new XmlSerializer(typeof(font));
            using (var str = new System.IO.MemoryStream(format))
            {
                var font = (font)ser.Deserialize(str);
                textureList = new Dictionary<int, BitmapChar>();
                for (int i = 0; i < font.chars.Length; i++)
                {
                    var fChar = font.chars[i];

                    var bChar = new BitmapChar();
                    bChar.Id = fChar.id[0];
                    bChar.Advance = fChar.advance;

                    var charRect = fChar.rect.Split(' ');
                    int charX = Convert.ToInt32(charRect[0]);
                    int charY = Convert.ToInt32(charRect[1]);
                    int charW = Convert.ToInt32(charRect[2]);
                    int charH = Convert.ToInt32(charRect[3]);

                    var offset = fChar.offset.Split(' ');
                    bChar.OffsetX = Convert.ToInt32(offset[0]);
                    bChar.OffsetY = Convert.ToInt32(offset[1]);

                    bChar.Texture = new Bitmap(charW, charH);
                    if (charW > 0 && charH > 0)
                    {
                        
                    }

                    if (charW > 0 && charH > 0)
                        for (int y = charY, by = 0; by < charH; y++, by++)
                            for (int x = charX, bx = 0; bx < charW; x++, bx++)
                            {
                                var c1 = fontImage.GetPixel(x, y);
                                bChar.Texture.SetPixel(bx, by, c1);
                            }

                    bChar.Texture.Apply();
                    textureList.Add(bChar.Id, bChar);
                }
            }

            Loaded = true;
        }

        public class BitmapChar
        {
            public byte Advance { get; set; }
            public int Id { get; set; }
            public int OffsetX { get; set; }
            public int OffsetY { get; set; }
            public Bitmap Texture { get; set; }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
        [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
        public partial class font
        {

            private fontDescription descriptionField;

            private fontMetrics metricsField;

            private fontTexture textureField;

            private fontChar[] charsField;

            private string typeField;

            /// <remarks/>
            public fontDescription description
            {
                get
                {
                    return descriptionField;
                }
                set
                {
                    descriptionField = value;
                }
            }

            /// <remarks/>
            public fontMetrics metrics
            {
                get
                {
                    return metricsField;
                }
                set
                {
                    metricsField = value;
                }
            }

            /// <remarks/>
            public fontTexture texture
            {
                get
                {
                    return textureField;
                }
                set
                {
                    textureField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlArrayItemAttribute("char", IsNullable = false)]
            public fontChar[] chars
            {
                get
                {
                    return charsField;
                }
                set
                {
                    charsField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string type
            {
                get
                {
                    return typeField;
                }
                set
                {
                    typeField = value;
                }
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
        public partial class fontDescription
        {

            private byte sizeField;

            private string familyField;

            private string styleField;

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public byte size
            {
                get
                {
                    return sizeField;
                }
                set
                {
                    sizeField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string family
            {
                get
                {
                    return familyField;
                }
                set
                {
                    familyField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string style
            {
                get
                {
                    return styleField;
                }
                set
                {
                    styleField = value;
                }
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
        public partial class fontMetrics
        {

            private byte ascenderField;

            private byte heightField;

            private sbyte descenderField;

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public byte ascender
            {
                get
                {
                    return ascenderField;
                }
                set
                {
                    ascenderField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public byte height
            {
                get
                {
                    return heightField;
                }
                set
                {
                    heightField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public sbyte descender
            {
                get
                {
                    return descenderField;
                }
                set
                {
                    descenderField = value;
                }
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
        public partial class fontTexture
        {

            private ushort widthField;

            private ushort heightField;

            private string fileField;

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public ushort width
            {
                get
                {
                    return widthField;
                }
                set
                {
                    widthField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public ushort height
            {
                get
                {
                    return heightField;
                }
                set
                {
                    heightField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string file
            {
                get
                {
                    return fileField;
                }
                set
                {
                    fileField = value;
                }
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
        public partial class fontChar
        {

            private string offsetField;

            private string rectField;

            private byte advanceField;

            private string idField;

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string offset
            {
                get
                {
                    return offsetField;
                }
                set
                {
                    offsetField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string rect
            {
                get
                {
                    return rectField;
                }
                set
                {
                    rectField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public byte advance
            {
                get
                {
                    return advanceField;
                }
                set
                {
                    advanceField = value;
                }
            }

            /// <remarks/>
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string id
            {
                get
                {
                    return idField;
                }
                set
                {
                    idField = value;
                }
            }
        }
    }
}



<|start_filename|>Assets/Unity/UnitWinFormsExamples.cs<|end_filename|>
﻿namespace UnityWinForms
{
    using UnityEngine;

    using UnityWinForms.Examples;

    public class UnitWinFormsExamples : MonoBehaviour
    {
        public static Material s_chartGradient;
        public Material ChartGradient;
        
        private void Start()
        {
            s_chartGradient = ChartGradient;
            
            var form = new FormExamples();

            form.Show();
        }
    }
}

<|start_filename|>Assets/Controls/Highcharts/AxisCollection.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    
    public class AxisCollection : IList<Axis>
    {
        private readonly List<Axis> items = new List<Axis>();
        private readonly Highchart owner;
        
        public AxisCollection(Highchart chart)
        {
            owner = chart;
        }
        
        public Axis this[int index]
        {
            get { return items[index]; }
            set
            {
                Unsubscribe(items[index]);
                
                items[index] = value;
                
                Unsubscribe(value);
                Subscribe(value);
            }
        }
        
        public int Count
        {
            get { return items.Count; }
        }
        public bool IsReadOnly
        {
            get { return false; }
        }
        
        public IEnumerator<Axis> GetEnumerator()
        {
            return items.GetEnumerator();
        }
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
        public void Add(Axis item)
        {
            items.Add(item);
            
            Unsubscribe(item);
            Subscribe(item);
        }
        public void Clear()
        {
            for (int i = 0; i < items.Count; i++)
                Unsubscribe(items[i]);
            
            items.Clear();
        }
        public bool Contains(Axis item)
        {
            return items.Contains(item);
        }
        public void CopyTo(Axis[] array, int arrayIndex)
        {
            items.CopyTo(array, arrayIndex);
        }
        public bool Remove(Axis item)
        {
            Unsubscribe(item);
            
            return items.Remove(item);
        }
        public int IndexOf(Axis item)
        {
            return items.IndexOf(item);
        }
        public void Insert(int index, Axis item)
        {
            Unsubscribe(item);
            Subscribe(item);
            
            items.Insert(index, item);
        }
        public void RemoveAt(int index)
        {
            Unsubscribe(items[index]);
            
            items.RemoveAt(index);
        }

        private void Subscribe(Axis axis)
        {
            if (axis == null)
                return;
            
            axis.OffsetChanged += AxisOnOffsetChanged;
        }
        private void Unsubscribe(Axis axis)
        {
            if (axis == null)
                return;
            
            axis.OffsetChanged -= AxisOnOffsetChanged;
        }
        
        private void AxisOnOffsetChanged(object sender, EventArgs e)
        {
            // Adjust plot left position.
            // TODO: adjust plot bottom position.
            var marginLeftValue = owner.chart.spacingLeft + 38;
            if (owner.chart.marginLeft != null)
                marginLeftValue = owner.chart.marginLeft.Value;

            var nextLeft = marginLeftValue;
            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i] as YAxis;
                if (item == null)
                    continue;
                
                nextLeft = marginLeftValue + item.offset;
            }

            if (nextLeft < 8) // Add minimum padding to show left category.
                nextLeft = 8;
            
            if (nextLeft == owner.cachedPlotLeft)
                return;
            
            owner.cachedPlotLeft = nextLeft;
            owner.Refresh();
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/BaseCollection.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections;

    public class BaseCollection : ICollection
    {
        private readonly ArrayList list;

        public BaseCollection()
        {
            list = new ArrayList();
        }

        public virtual int Count { get { return list.Count; } }
        public bool IsReadOnly { get { return list.IsReadOnly; } }
        public bool IsSynchronized { get { return list.IsSynchronized; } }
        public object SyncRoot { get { return list.SyncRoot; } }

        protected virtual ArrayList List { get { return list; } }

        public void CopyTo(Array array, int index)
        {
            list.CopyTo(array, index);
        }
        public IEnumerator GetEnumerator()
        {
            return list.GetEnumerator();
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/Form.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class Form : ContainerControl, IResizableControl
    {
        internal readonly Pen borderPen = new Pen(defaultFormBorderColor);
        internal readonly Pen innerBorderPen = new Pen(defaultFormInnerBorderColor);
        internal bool dialog;
        internal bool formMoving;
        internal Color uwfHeaderColor = defaultFormHeaderColor;
        internal Font uwfHeaderFont;
        internal int uwfHeaderHeight;
        internal Padding uwfHeaderPadding = defaultFormPadding;
        internal ContentAlignment uwfHeaderTextAlign;
        internal Color uwfHeaderTextColor = defaultFormHeaderTextColor;
        internal bool uwfMovable = true;

        protected internal Button uwfSizeGripRenderer;

        #region Private vars.

        private const int RESIZE_OFFSET = 8;
        private static readonly Color defaultFormBorderColor = Color.FromArgb(192, 192, 192);
        private static readonly Color defaultFormInnerBorderColor = Color.FromArgb(214, 214, 214);
        private static readonly Color defaultFormHeaderColor = Color.FromArgb(238, 238, 242);
        private static readonly Color defaultFormHeaderTextColor = Color.FromArgb(64, 64, 64);
        private static readonly Padding defaultFormPadding = new Padding(32, 0, 32, 0);
        private static readonly Color defaultFormShadowColor = Color.FromArgb(12, 64, 64, 64);
        private static Point nextLocation = new Point(156, 156);
        private static Form lastAcceptForm;
        private static Timer lastAcceptFormTimer;

        private formSystemButton closeButton;
        private bool controlBox;
        private Action<Form, DialogResult> dialogCallback;
        private FormWindowState formState;
        private bool maximizeBox = true;
        private MdiClient mdiClient;
        private Form mdiParent;
        private FormBorderStyle minimizedBorderStyle;
        private Point minimizedLocation;
        private Size minimizedSize;
        private bool minimizedMovable;
        private Point windowMove_StartPosition;
        private ControlResizeTypes resizeType;
        private Size resizeOriginal;
        private Point resizePosition;
        private Point resizeDelta;
        private SizeGripStyle sizeGripStyle;
        private Pen shadowPen;
        private bool topMost;
        private bool visibleReady;

        #endregion

        public Form()
        {
            ControlBox = true;
            Font = SystemFonts.uwfArial_14;
            FormBorderStyle = FormBorderStyle.Sizable;
            MinimumSize = new Size(128, 48);
            StartPosition = FormStartPosition.WindowsDefaultLocation;

            visibleReady = true;
            Visible = false;

            uwfHeaderHeight = SystemInformation.CaptionHeight;
            uwfHeaderFont = Font;
            uwfHeaderTextAlign = ContentAlignment.MiddleLeft;
            uwfShadowBox = true;
            uwfShadowHandler = DrawShadow;

            Application.UpdateEvent += Application_UpdateEvent;
            MouseHook.MouseUp += MouseHook_MouseUp;
        }

        public event FormClosedEventHandler FormClosed;
        public event FormClosingEventHandler FormClosing;
        public event EventHandler Shown;

        public static Form ActiveForm { get; internal set; }

        public IButtonControl AcceptButton { get; set; }
        public IButtonControl CancelButton { get; set; }
        public bool ControlBox
        {
            get { return controlBox; }
            set
            {
                if (controlBox == value)
                    return;

                controlBox = value;
                
                if (value)
                {
                    if (Visible && CloseButton == null)
                    {
                        _MakeButtonClose();
                    }
                }
                else if (CloseButton != null)
                {
                    Controls.Remove(CloseButton);

                    CloseButton.Dispose();
                    closeButton = null;
                }
            }
        }
        public DialogResult DialogResult { get; set; }
        public bool IsMdiChild
        {
            get { return mdiParent != null; }
        }
        public bool IsMdiContainer
        {
            get { return mdiClient != null; }
            set
            {
                if (IsMdiContainer == value)
                    return;

                if (value)
                {
                    mdiClient = new MdiClient();
                    mdiClient.Location = new Point(0, uwfHeaderHeight);
                    mdiClient.Size = new Size(Width, Height - uwfHeaderHeight);
                    Controls.Add(mdiClient);
                }
                else
                {
                    mdiClient.Dispose();
                    mdiClient = null;
                }
            }
        }
        public bool IsModal
        {
            get { return dialog; }
        }
        public FormBorderStyle FormBorderStyle { get; set; }
        public bool KeyPreview { get; set; }
        public MenuStrip MainMenuStrip { get; set; }
        public bool MaximizeBox
        {
            get { return maximizeBox; }
            set { maximizeBox = value; }
        }
        public Form MdiParent
        {
            get { return mdiParent; }
            set
            {
                if (mdiParent == value && (value != null || Parent == null))
                    return;

                if (value == null)
                    Parent = null;
                else
                {
                    mdiParent = value;
                    Parent = value.MdiClient;
                }
            }
        }
        public Form Owner { get; set; }
        public SizeGripStyle SizeGripStyle
        {
            get { return sizeGripStyle; }
            set
            {
                if (sizeGripStyle == value) return;

                sizeGripStyle = value;
                if (value == SizeGripStyle.Hide)
                {
                    if (uwfSizeGripRenderer != null && !uwfSizeGripRenderer.IsDisposed)
                        uwfSizeGripRenderer.Dispose();
                    uwfSizeGripRenderer = null;
                }
                else
                    _MakeButtonResize();

                PerformLayout();
            }
        }
        public FormStartPosition StartPosition { get; set; }
        public bool TopMost
        {
            get { return topMost; }
            set
            {
                topMost = value;
                uwfAppOwner.Forms.Sort();
            }
        }
        public FormWindowState WindowState
        {
            get { return formState; }
            set
            {
                if (formState == value)
                    return;

                SetWindowState(value);
            }
        }
        
        internal Button CloseButton { get { return closeButton; } }
        internal MdiClient MdiClient
        {
            get { return mdiClient; }
        }
        internal Color uwfBorderColor
        {
            get { return borderPen.Color; }
            set { borderPen.Color = value; }
        }

        protected override Size DefaultSize
        {
            get { return new Size(300, 300); }
        }

        public void Close()
        {
            CloseInternal(CloseReason.UserClosing);
        }
        public virtual ControlResizeTypes GetResizeAt(Point mclient)
        {
#pragma warning disable 618
            if (!(FormBorderStyle == FormBorderStyle.Sizable || FormBorderStyle == FormBorderStyle.SizableToolWindow)) return ControlResizeTypes.None;
#pragma warning restore 618

            var r_type = ControlResizeTypes.None;

            // Left side.
            if (mclient.X < RESIZE_OFFSET)
            {
                r_type = ControlResizeTypes.Left;
                if (mclient.Y < RESIZE_OFFSET)
                    r_type = ControlResizeTypes.LeftUp;
                else if (mclient.Y > Height - RESIZE_OFFSET)
                    r_type = ControlResizeTypes.LeftDown;
            }
            else if (mclient.X > Width - RESIZE_OFFSET)
            {
                // Right side.
                r_type = ControlResizeTypes.Right;
                if (mclient.Y < RESIZE_OFFSET)
                    r_type = ControlResizeTypes.RightUp;
                else if (mclient.Y > Height - RESIZE_OFFSET)
                    r_type = ControlResizeTypes.RightDown;
            }
            else if (mclient.Y < RESIZE_OFFSET)
                r_type = ControlResizeTypes.Up;
            else if (mclient.Y > Height - RESIZE_OFFSET)
                r_type = ControlResizeTypes.Down;

            return r_type;
        }
        public void SetResize(ControlResizeTypes resize)
        {
            resizeType = resize;
            resizeDelta = MousePosition;
            resizeOriginal = Size;
            resizePosition = Location;

            switch (resize)
            {
                case ControlResizeTypes.None:
                    Application.activeResizeControl = null;
                    break;

                default:
                    Application.activeResizeControl = this;
                    break;
            }
        }
        public void Show(Form owner) // original: public void Show(IWin32Window owner)
        {
            this.Owner = owner;

            Show();
        }
        public DialogResult ShowDialog(Action<Form, DialogResult> onClosed = null)
        {
            return ShowDialog(null, onClosed);
        }
        public DialogResult ShowDialog(Form owner, Action<Form, DialogResult> onClosed = null)
        {
            this.Owner = owner;

            dialog = true;
            dialogCallback = onClosed;

            Visible = true;
            
            return DialogResult;
        }

        internal virtual void Application_UpdateEvent()
        {
            // ResizeComponent.
#pragma warning disable 618
            if (resizeType != ControlResizeTypes.None && (FormBorderStyle == FormBorderStyle.Sizable || FormBorderStyle == FormBorderStyle.SizableToolWindow))
#pragma warning restore 618
            {
                int estimatedX = Location.X;
                int estimatedY = Location.Y;
                int estimatedWidth = 0;
                int estimatedHeight = 0;

                switch (resizeType)
                {
                    case ControlResizeTypes.Right:
                        estimatedWidth = resizeOriginal.Width + (MousePosition.X - resizeDelta.X);
                        estimatedHeight = resizeOriginal.Height;
                        break;
                    case ControlResizeTypes.Down:
                        estimatedWidth = resizeOriginal.Width;
                        estimatedHeight = resizeOriginal.Height + (MousePosition.Y - resizeDelta.Y);
                        break;
                    case ControlResizeTypes.RightDown:
                        estimatedWidth = resizeOriginal.Width + (MousePosition.X - resizeDelta.X);
                        estimatedHeight = resizeOriginal.Height + (MousePosition.Y - resizeDelta.Y);
                        break;
                    case ControlResizeTypes.Left:
                        estimatedX = resizePosition.X + (MousePosition.X - resizeDelta.X);
                        estimatedY = resizePosition.Y;
                        estimatedWidth = resizeOriginal.Width + resizePosition.X - estimatedX;
                        estimatedHeight = resizeOriginal.Height;
                        break;
                    case ControlResizeTypes.Up:
                        estimatedX = resizePosition.X;
                        estimatedY = resizePosition.Y + (MousePosition.Y - resizeDelta.Y);
                        estimatedWidth = resizeOriginal.Width;
                        estimatedHeight = resizeOriginal.Height + resizePosition.Y - estimatedY;
                        break;
                    case ControlResizeTypes.LeftUp:
                        estimatedX = resizePosition.X + (MousePosition.X - resizeDelta.X);
                        estimatedY = resizePosition.Y + (MousePosition.Y - resizeDelta.Y);
                        estimatedWidth = resizeOriginal.Width + resizePosition.X - estimatedX;
                        estimatedHeight = resizeOriginal.Height + resizePosition.Y - estimatedY;
                        break;
                    case ControlResizeTypes.RightUp:
                        estimatedX = resizePosition.X;
                        estimatedY = resizePosition.Y + (MousePosition.Y - resizeDelta.Y);
                        estimatedWidth = resizeOriginal.Width + (MousePosition.X - resizeDelta.X);
                        estimatedHeight = resizeOriginal.Height + resizePosition.Y - estimatedY;
                        break;
                    case ControlResizeTypes.LeftDown:
                        estimatedX = resizePosition.X + (MousePosition.X - resizeDelta.X);
                        estimatedY = resizePosition.Y;
                        estimatedWidth = resizeOriginal.Width + resizePosition.X - estimatedX;
                        estimatedHeight = resizeOriginal.Height + (MousePosition.Y - resizeDelta.Y);
                        break;
                }

                // Minimum size check.
                if (estimatedWidth < MinimumSize.Width)
                {
                    estimatedX = Location.X;
                    estimatedWidth = Width;
                }

                if (estimatedHeight < MinimumSize.Height)
                {
                    estimatedY = Location.Y;
                    estimatedHeight = Height;
                }

                // Maximum size check.
                if (MaximumSize.Width > 0 && estimatedWidth > MaximumSize.Width)
                {
                    estimatedX = Location.X;
                    estimatedWidth = Width;
                }

                if (MaximumSize.Height > 0 && estimatedHeight > MaximumSize.Height)
                {
                    estimatedY = Location.Y;
                    estimatedHeight = Height;
                }

                SetBounds(estimatedX, estimatedY, estimatedWidth, estimatedHeight);
            }
        }
        internal virtual void MouseHook_MouseUp(object sender, MouseEventArgs e)
        {
            if (formMoving)
            {
                // Fix location here.
                if (Location.Y < 0) // Preventing Form to go over top of rendering window and mdiclient parent.
                    Location = new Point(Location.X, 0);
            }

            formMoving = false;
            resizeType = ControlResizeTypes.None;
            if (Application.activeResizeControl == this)
                Application.activeResizeControl = null;
        }
        internal void CloseInternal(CloseReason closeReason)
        {
            var closingEventArgs = new FormClosingEventArgs(closeReason, false);

            OnFormClosing(closingEventArgs);

            if (!closingEventArgs.Cancel)
            {
                var closedEventArgs = new FormClosedEventArgs(closeReason);
                OnFormClosed(closedEventArgs);
                Dispose();
            }

            // Invoke dialog result action.
            if (dialog && dialogCallback != null)
                dialogCallback.Invoke(this, DialogResult);
        }
        internal void ResetGripRendererLocation()
        {
            if (uwfSizeGripRenderer == null)
                return;

            uwfSizeGripRenderer.Location = new Point(Width - 12, Height - 12); // TODO: img error: Internal_GetWidth.
        }
        internal void SetWindowState(FormWindowState state)
        {
            if (formState == FormWindowState.Minimized && state != FormWindowState.Minimized)
                Visible = true;
            
            formState = state;
            
            switch (state)
            {
                case FormWindowState.Normal:
                    FormBorderStyle = minimizedBorderStyle;
                    uwfMovable = minimizedMovable;

                    SetBounds(minimizedLocation.X, minimizedLocation.Y, minimizedSize.Width, minimizedSize.Height);
                    break;
                    
                case FormWindowState.Maximized:
                    minimizedBorderStyle = FormBorderStyle;
                    minimizedLocation = Location;
                    minimizedMovable = uwfMovable;
                    minimizedSize = Size;
            
                    FormBorderStyle = FormBorderStyle.FixedSingle;
                    uwfMovable = false;

                    var nx = 0;
                    var ny = 0;
                    var nw = Screen.width;
                    var nh = Screen.height;

                    SetBounds(nx, ny, nw, nh);
                    break;
                    
                case FormWindowState.Minimized:
                    Visible = false; // ?
                    break;
            }
        }

        protected internal override void uwfOnLatePaint(PaintEventArgs e)
        {
            var g = e.Graphics;
            var headerHeight = uwfHeaderHeight;
            var headerPadding = uwfHeaderPadding;
            var width = Width;

            g.uwfFillRectangle(uwfHeaderColor, 0, 0, width, headerHeight);
            g.uwfDrawString(Text, uwfHeaderFont, uwfHeaderTextColor, headerPadding.Left, headerPadding.Top, width - headerPadding.Horizontal, headerHeight - headerPadding.Vertical, uwfHeaderTextAlign);

            // System controls.
            if (closeButton != null)
            {
                closeButton.formPainting = true;
                closeButton.RaiseOnPaint(e);
                closeButton.formPainting = false;
            }

            g.DrawLine(innerBorderPen, 0, uwfHeaderHeight - 1, width, uwfHeaderHeight - 1);
            g.DrawRectangle(borderPen, 0, 0, width, Height);
        }
        protected internal override Point uwfShadowPointToScreen(Point p)
        {
            // PointToScreen is not checking for AutoGroup, 
            // which is creating new gui group and thats why shadow cannot be drawn normally inside controls.
            if (uwfAutoGroup)
                return p;

            return base.uwfShadowPointToScreen(p);
        }

        protected override Control.ControlCollection CreateControlsInstance()
        {
            return new ControlCollection(this);
        }
        protected override void Dispose(bool release_all)
        {
            MouseHook.MouseUp -= MouseHook_MouseUp;
            Application.UpdateEvent -= Application_UpdateEvent;

            RemoveFormFromCollection();
            
            base.Dispose(release_all);
        }
        protected virtual void OnFormClosed(FormClosedEventArgs e)
        {
            var formClosed = FormClosed;
            if (formClosed != null)
                formClosed(this, e);
        }
        protected virtual void OnFormClosing(FormClosingEventArgs e)
        {
            var formClosing = FormClosing;
            if (formClosing != null)
                formClosing(this, e);
        }
        protected virtual void OnLoad(EventArgs e)
        {
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.KeyCode == Keys.Enter && AcceptButton != null && lastAcceptForm == null)
            {
                lastAcceptForm = this;
                
                // Start timer that will reset the last form with the accept button.
                if (lastAcceptFormTimer != null)
                    lastAcceptFormTimer.Dispose();
                
                lastAcceptFormTimer = new Timer();
                lastAcceptFormTimer.Interval = 1000; // Interval between the accepting forms.
                lastAcceptFormTimer.Tick += (sender, args) =>
                {
                    lastAcceptForm = null;
                    lastAcceptFormTimer.Dispose();
                    lastAcceptFormTimer = null;
                };
                lastAcceptFormTimer.Start();

                AcceptButton.PerformClick();
            }

            if (e.KeyCode == Keys.Escape && CancelButton != null)
            {
                CancelButton.PerformClick();
            }
        }
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            
            if (e.Location.Y < uwfHeaderHeight && maximizeBox)
            {
                if (WindowState == FormWindowState.Maximized)
                    SetWindowState(FormWindowState.Normal);
                else if (WindowState == FormWindowState.Normal)
                    SetWindowState(FormWindowState.Maximized);
            }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == MouseButtons.Left)
            {
                resizeType = GetResizeAt(e.Location);
                SetResize(resizeType);

                if (resizeType == ControlResizeTypes.None && uwfMovable && e.Location.Y < uwfHeaderHeight)
                {
                    // Move then.
                    windowMove_StartPosition = e.Location;
                    formMoving = true;
                }
            }
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (formMoving)
            {
                if (Parent == null)
                    Location = PointToScreen(e.Location).Subtract(windowMove_StartPosition);
                else
                    Location = Parent.PointToClient(PointToScreen(e.Location).Subtract(windowMove_StartPosition));
            }
            else
                GetResizeAt(e.Location);
        }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            e.Graphics.uwfFillRectangle(BackColor, 0, uwfHeaderHeight, Width, Height - uwfHeaderHeight);
        }
        protected virtual void OnShown(EventArgs e)
        {
            var shown = Shown;
            if (shown != null)
                shown(this, e);
        }
        protected override void OnVisibleChanged(EventArgs e)
        {
            if (Visible)
            {
                if (ControlBox && CloseButton == null)
                    _MakeButtonClose();
                
                PlaceAtStartPosition(StartPosition);

                if (MdiParent == null) 
                    AddFormToCollection();

                TryFocus();

                OnShown(EventArgs.Empty);
            }
            else
            {
                RemoveFormFromCollection();
            }

            base.OnVisibleChanged(e);
        }
        protected override void SetVisibleCore(bool value)
        {
            if (!visibleReady)
                return;
            
            base.SetVisibleCore(value);
        }

        private void DrawShadow(PaintEventArgs e)
        {
            var loc = uwfShadowPointToScreen(Location);
            var locX = loc.X;
            var locY = loc.Y;
            var width = Width;
            var height = Height;
            var g = e.Graphics;

            if (BackColor.A < 255)
            {
                g.uwfFillRectangle(defaultFormShadowColor, locX - 3, locY, width + 6, height + 3);
                g.uwfFillRectangle(defaultFormShadowColor, locX - 2, locY, width + 4, height + 2);
                g.uwfFillRectangle(defaultFormShadowColor, locX - 1, locY - 1, width + 2, height + 2);
            }
            else
            {
                // Reducing fill rate when the background color don't have opacity.
                if (shadowPen == null)
                    shadowPen = new Pen(defaultFormShadowColor);

                shadowPen.Color = defaultFormShadowColor;
                var shadowAlphaOffset = shadowPen.Color.A;
                var shadowAlpha = shadowAlphaOffset;
                
                g.DrawRectangle(shadowPen, locX - 3, locY + 1, width + 6, height + 2);

                shadowAlpha += shadowAlphaOffset;
                shadowPen.Color = Color.FromArgb(shadowAlpha, shadowPen.Color);
                
                g.DrawRectangle(shadowPen, locX - 2, locY + 1, width + 4, height + 1);
                
                shadowAlpha += shadowAlphaOffset;
                shadowPen.Color = Color.FromArgb(shadowAlpha, shadowPen.Color);
                
                g.DrawRectangle(shadowPen, locX - 1, locY, width + 2, height + 1);
            }
        }
        private void _MakeButtonClose()
        {
            closeButton = new formSystemButton();

            closeButton.Anchor = AnchorStyles.Right;
            closeButton.Text = "";
            if (uwfAppOwner.Resources != null && uwfAppOwner.Resources.Close != null)
                closeButton.Image = uwfAppOwner.Resources.Close;
            else
                closeButton.Text = "X";
            closeButton.Location = new Point(Width - 32, 1);
            closeButton.Name = "buttonClose";
            closeButton.BackColor = Color.FromArgb(0, 238, 238, 242);
            closeButton.Size = new Size(24, 16);
            closeButton.ForeColor = Color.FromArgb(64, 64, 64);

            closeButton.uwfBorderColor = Color.Transparent;
            closeButton.uwfBorderHoverColor = Color.Transparent;
            closeButton.uwfHoverColor = Color.FromArgb(64, 252, 252, 252);
            closeButton.uwfImageColor = Color.FromArgb(64, 64, 64);
            closeButton.uwfImageHoverColor = Color.FromArgb(128, 128, 128);

            closeButton.BringToFront();
            closeButton.Click += OnCloseButtonOnClick;

            Controls.Add(closeButton);
        }
        private void _MakeButtonResize()
        {
            var img = uwfAppOwner.Resources.FormResize;
            if (img == null) return;

            uwfSizeGripRenderer = new ResizeButton(this, img);
            uwfSizeGripRenderer.uwfSystem = true;

            Controls.Add(uwfSizeGripRenderer);

            ResetGripRendererLocation();
        }
        private void OnCloseButtonOnClick(object o, EventArgs e)
        {
            Close();
        }
        private void PlaceAtStartPosition(FormStartPosition formStartPosition)
        {
            var workingSize = Screen.PrimaryScreen.WorkingArea.Size;

            if (MdiParent != null)
                workingSize = MdiParent.MdiClient.Size;

            switch (formStartPosition)
            {
                case FormStartPosition.CenterParent:
                    {
                        if (Owner != null)
                        {
                            var ex = Owner.Location.X + (Owner.Width - Width) / 2;
                            var ey = Owner.Location.Y + (Owner.Height - Height) / 2;

                            if (ex < 0) ex = 0;
                            if (ey < 0) ey = 0;

                            Location = new Point(ex, ey);
                        }
                        else

                            // Use default position.
                            PlaceAtStartPosition(FormStartPosition.WindowsDefaultLocation);
                    }
                    break;
                
                case FormStartPosition.CenterScreen:
                    {
                        var ex = (workingSize.Width - Width) / 2;
                        var ey = (workingSize.Height - Height) / 2;

                        if (ex < 0) ex = 0;
                        if (ey < 0) ey = 0;

                        Location = new Point(ex, ey);
                    }
                    break;
                
#pragma warning disable 618
                case FormStartPosition.WindowsDefaultBounds: // TODO: Need size calculation algorithm.
#pragma warning restore 618
                case FormStartPosition.WindowsDefaultLocation:
                    {
                        var ex = nextLocation.X;
                        var ey = nextLocation.Y;

                        if (ex + Width > workingSize.Width)
                            ex = workingSize.Width - Width;
                        if (ey + Height > workingSize.Height)
                            ey = workingSize.Height - Height;

                        if (ex < 0) ex = 0;
                        if (ey < 0) ey = 0;

                        Location = new Point(ex, ey);

                        nextLocation = new Point(nextLocation.X + 26, nextLocation.Y + 26);
                        if (nextLocation.X >= 260) nextLocation = new Point(26, nextLocation.Y);
                        if (nextLocation.Y >= 260) nextLocation = new Point(nextLocation.X, 26);
                    }
                    break;
            }
        }
        private void SelectFirstControl()
        {
            for (int i = 0; i < Controls.Count; i++)
                if (Controls[i].CanSelect)
                {
                    Controls[i].Select();
                    return;
                }
        }
        private bool TryFocus()
        {
            // Check if we should focus form.
            if ((CreateParams.ExStyle & (NativeMethods.WS_DISABLED | NativeMethods.WS_EX_TOOLWINDOW)) == 0)
            {
                Focus();
                SelectFirstControl();

                return true;
            }

            return false;
        }

        private void AddFormToCollection()
        {
            if (dialog)
            {
                if (!uwfAppOwner.ModalForms.Contains(this))
                    uwfAppOwner.ModalForms.Add(this);
            }
            else if (!uwfAppOwner.Forms.Contains(this))
            {
                uwfAppOwner.Forms.Add(this);   
            }
        }
        private void RemoveFormFromCollection()
        {
            if (dialog)
            {
                if (uwfAppOwner.ModalForms.Contains(this))
                    uwfAppOwner.ModalForms.Remove(this);
            }
            else if (uwfAppOwner.Forms.Contains(this))
            {
                uwfAppOwner.Forms.Remove(this);   
            }
        }
        
        private new class ControlCollection : Control.ControlCollection
        {
            private readonly Form owner;

            public ControlCollection(Form owner) : base(owner)
            {
                this.owner = owner;
            }

            public override void Add(Control value)
            {
                var client = value as MdiClient;
                if (client != null && owner.mdiClient == null)
                    owner.mdiClient = client;

                base.Add(value);

                if (client != null)
                    client.SendToBack();
            }
            public override void Remove(Control item)
            {
                if (item == owner.mdiClient)
                    owner.mdiClient = null;

                base.Remove(item);
            }
        }

        internal class formSystemButton : Button
        {
            internal bool formPainting;

            public formSystemButton()
            {
                SetStyle(ControlStyles.Selectable, false);

                uwfSystem = true;
            }

            protected override void OnPaint(PaintEventArgs e)
            {
                if (formPainting && Visible)
                    base.OnPaint(e);
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/MouseEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public enum MouseButtons
    {
        None = 0,
        Left = 1048576,
        Right = 2097152,
        Middle = 4194304,
        XButton1 = 8388608,
        XButton2 = 16777216,
    }

    public class MouseEventArgs : EventArgs
    {
        public MouseEventArgs(MouseButtons button, int clicks, int x, int y, int delta)
        {
            Button = button;
            Clicks = clicks;
            X = x;
            Y = y;
            Location = new Point(X, Y);
            Delta = delta;
        }

        internal MouseEventArgs()
        {
        }

        public MouseButtons Button { get; internal set; }
        public int Clicks { get; internal set; }
        public Point Location { get; internal set; }
        public int X { get; internal set; }
        public int Y { get; internal set; }
        public int Delta { get; internal set; }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelLinkLabel.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelLinkLabel : BaseExamplePanel
    {
        public override void Initialize()
        {
            var linkLabel = this.Create<LinkLabel>("linkLabel");
            linkLabel.LinkClicked += (sender, args) => linkLabel.LinkVisited = true;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/DrawItemEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void DrawItemEventHandler(object sender, DrawItemEventArgs e);
}


<|start_filename|>Assets/Unity/Views/EditorMenu.cs<|end_filename|>
﻿#if UNITY_EDITOR
namespace Unity.Views
{
    using System.Collections.Generic;
    using System.Linq;

    using Unity.API;

    using UnityEditor;

    using UnityEngine;

    public static class EditorMenu
    {
        [MenuItem("Window/UnityWinForms/AppControlList")]
        public static void ShowControlList()
        {
            EditorWindow.GetWindow(typeof(AppControlList), false, "AppControlList");
        }

        [MenuItem("Window/UnityWinForms/SWF Inspector")]
        public static EditorWindow ShowInspector()
        {
            return EditorWindow.GetWindow(typeof(ControlInspector), false, "SWF Inspector");
        }

        [MenuItem("Window/UnityWinForms/Validate resources")]
        public static void ValidateResources()
        {
            var uwfObjects = Resources.FindObjectsOfTypeAll<UnityWinForms>();
            var fonts = Resources.FindObjectsOfTypeAll<Font>();
            var images = Resources.LoadAll<Texture2D>("").ToList();

            var imgArrowDown = images.Find(x => x.name == "arrow_down");
            var imgArrowLeft = images.Find(x => x.name == "arrow_left");
            var imgArrowRight = images.Find(x => x.name == "arrow_right");
            var imgArrowUp = images.Find(x => x.name == "arrow_up");
            var imgChecked = images.Find(x => x.name == "checked");
            var imgCircle = images.Find(x => x.name == "circle");
            var imgClose = images.Find(x => x.name == "close");

            var imgCursorHand = images.Find(x => x.name == "hand");
            var imgCursorHelp = images.Find(x => x.name == "help");
            var imgCursorHSplit = images.Find(x => x.name == "hsplit");
            var imgCursorIBeam = images.Find(x => x.name == "ibeam");
            var imgCursorSizeAll = images.Find(x => x.name == "sizeall");
            var imgCursorSizeNESW = images.Find(x => x.name == "sizenesw");
            var imgCursorSizeNS = images.Find(x => x.name == "sizens");
            var imgCursorSizeNWSE = images.Find(x => x.name == "sizenwse");
            var imgCursorSizeWE = images.Find(x => x.name == "sizewe");
            var imgCursorVSplit = images.Find(x => x.name == "vsplit");

            var imgCArrowDown = images.Find(x => x.name == "curved_arrow_down");
            var imgCArrowLeft = images.Find(x => x.name == "curved_arrow_left");
            var imgCArrowRight = images.Find(x => x.name == "curved_arrow_right");
            var imgCArrowUp = images.Find(x => x.name == "curved_arrow_up");
            var imgDateTimePicker = images.Find(x => x.name == "datetimepicker");
            var imgDDRightArrow = images.Find(x => x.name == "dropdown_rightarrow");
            var imgFileDialogBack = images.Find(x => x.name == "filedialog_back");
            var imgFileDialogFile = images.Find(x => x.name == "filedialog_file");
            var imgFileDialogFolder = images.Find(x => x.name == "filedialog_folder");
            var imgFileDialogRefresh = images.Find(x => x.name == "filedialog_refresh");
            var imgFileDialogUp = images.Find(x => x.name == "filedialog_up");
            var imgFormResize = images.Find(x => x.name == "form_resize");
            var imgNumericDown = images.Find(x => x.name == "numeric_down");
            var imgNumericUp = images.Find(x => x.name == "numeric_up");
            var imgRadioChecked = images.Find(x => x.name == "radioButton_checked");
            var imgRadioHovered = images.Find(x => x.name == "radioButton_hovered");
            var imgRadioUnchecked = images.Find(x => x.name == "radioButton_unchecked");
            var imgTreeCollapsed = images.Find(x => x.name == "treenode_collapsed");
            var imgTreeExpanded = images.Find(x => x.name == "treenode_expanded");

            for (int i = 0; i < uwfObjects.Length; i++)
            {
                var obj = uwfObjects[i];
                if (obj.Resources.Fonts == null)
                    obj.Resources.Fonts = new List<Font>();
                if (obj.Resources.Fonts.Count == 0 && fonts != null && fonts.Length > 0)
                {
                    foreach (var font in fonts)
                        obj.Resources.Fonts.Add(font);
                }

                var objResources = obj.Resources;

                if (objResources.Images.ArrowDown == null) objResources.Images.ArrowDown = imgArrowDown;
                if (objResources.Images.ArrowLeft == null) objResources.Images.ArrowLeft = imgArrowLeft;
                if (objResources.Images.ArrowRight == null) objResources.Images.ArrowRight = imgArrowRight;
                if (objResources.Images.ArrowUp == null) objResources.Images.ArrowUp = imgArrowUp;
                if (objResources.Images.Checked == null) objResources.Images.Checked = imgChecked;
                if (objResources.Images.Circle == null) objResources.Images.Circle = imgCircle;
                if (objResources.Images.Close == null) objResources.Images.Close = imgClose;
                if (objResources.Images.Cursors.Hand == null) objResources.Images.Cursors.Hand = imgCursorHand;
                if (objResources.Images.Cursors.Help == null) objResources.Images.Cursors.Help = imgCursorHelp;
                if (objResources.Images.Cursors.HSplit == null) objResources.Images.Cursors.HSplit = imgCursorHSplit;
                if (objResources.Images.Cursors.IBeam == null) objResources.Images.Cursors.IBeam = imgCursorIBeam;
                if (objResources.Images.Cursors.SizeAll == null) objResources.Images.Cursors.SizeAll = imgCursorSizeAll;
                if (objResources.Images.Cursors.SizeNESW == null) objResources.Images.Cursors.SizeNESW = imgCursorSizeNESW;
                if (objResources.Images.Cursors.SizeNS == null) objResources.Images.Cursors.SizeNS = imgCursorSizeNS;
                if (objResources.Images.Cursors.SizeNWSE == null) objResources.Images.Cursors.SizeNWSE = imgCursorSizeNWSE;
                if (objResources.Images.Cursors.SizeWE == null) objResources.Images.Cursors.SizeWE = imgCursorSizeWE;
                if (objResources.Images.Cursors.VSplit == null) objResources.Images.Cursors.VSplit = imgCursorVSplit;
                if (objResources.Images.CurvedArrowDown == null) objResources.Images.CurvedArrowDown = imgCArrowDown;
                if (objResources.Images.CurvedArrowLeft == null) objResources.Images.CurvedArrowLeft = imgCArrowLeft;
                if (objResources.Images.CurvedArrowRight == null) objResources.Images.CurvedArrowRight = imgCArrowRight;
                if (objResources.Images.CurvedArrowUp == null) objResources.Images.CurvedArrowUp = imgCArrowUp;
                if (objResources.Images.DateTimePicker == null) objResources.Images.DateTimePicker = imgDateTimePicker;
                if (objResources.Images.DropDownRightArrow == null) objResources.Images.DropDownRightArrow = imgDDRightArrow;
                if (objResources.Images.FileDialogBack == null) objResources.Images.FileDialogBack = imgFileDialogBack;
                if (objResources.Images.FileDialogFile == null) objResources.Images.FileDialogFile = imgFileDialogFile;
                if (objResources.Images.FileDialogFolder == null) objResources.Images.FileDialogFolder = imgFileDialogFolder;
                if (objResources.Images.FileDialogRefresh == null) objResources.Images.FileDialogRefresh = imgFileDialogRefresh;
                if (objResources.Images.FileDialogUp == null) objResources.Images.FileDialogUp = imgFileDialogUp;
                if (objResources.Images.FormResize == null) objResources.Images.FormResize = imgFormResize;
                if (objResources.Images.NumericDown == null) objResources.Images.NumericDown = imgNumericDown;
                if (objResources.Images.NumericUp == null) objResources.Images.NumericUp = imgNumericUp;
                if (objResources.Images.RadioButton_Checked == null) objResources.Images.RadioButton_Checked = imgRadioChecked;
                if (objResources.Images.RadioButton_Hovered == null) objResources.Images.RadioButton_Hovered = imgRadioHovered;
                if (objResources.Images.RadioButton_Unchecked == null) objResources.Images.RadioButton_Unchecked = imgRadioUnchecked;
                if (objResources.Images.TreeNodeCollapsed == null) objResources.Images.TreeNodeCollapsed = imgTreeCollapsed;
                if (objResources.Images.TreeNodeExpanded == null) objResources.Images.TreeNodeExpanded = imgTreeExpanded;
            }

            Debug.Log("UWF: Resources validated.");
        }
    }
}
#endif

<|start_filename|>Assets/System/Windows/Forms/DrawItemState.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    [Flags]
    public enum DrawItemState
    {
        Checked = 8,
        ComboBoxEdit = 4096,
        Default = 32,
        Disabled = 4,
        Focus = 16,
        Grayed = 2,
        HotLight = 64,
        Inactive = 128,
        NoAccelerator = 256,
        NoFocusRect = 512,
        Selected = 1,
        None = 0,
    }
}


<|start_filename|>Assets/System/Windows/Forms/LinkLabelLinkClickedEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void LinkLabelLinkClickedEventHandler(object sender, LinkLabelLinkClickedEventArgs e);
}


<|start_filename|>Assets/System/Windows/Forms/DragEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void DragEventHandler(object sender, DragEventArgs e);
}


<|start_filename|>Assets/System/Drawing/Size.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Globalization;
    
    [Serializable]
    public struct Size : IEquatable<Size>
    {
        public static readonly Size Empty = new Size();

        public Size(Point pt) : this()
        {
            Width = pt.X;
            Height = pt.Y;
        }
        public Size(int width, int height) : this()
        {
            Width = width;
            Height = height;
        }
        
        public static implicit operator SizeF(Size p)
        {
            return new SizeF(p.Width, p.Height);
        }
        public static explicit operator Point(Size size)
        {
            return new Point(size.Width, size.Height);
        }

        public static Size operator +(Size sz1, Size sz2)
        {
            return Add(sz1, sz2);
        }
        public static Size operator -(Size sz1, Size sz2)
        {
            return Subtract(sz1, sz2);
        }
        public static bool operator ==(Size sz1, Size sz2)
        {
            return sz1.Width == sz2.Width && sz1.Height == sz2.Height;
        }
        public static bool operator !=(Size sz1, Size sz2)
        {
            return !(sz1 == sz2);
        }

        public int Height { get; set; }
        public bool IsEmpty
        {
            get { return Width == 0 && Height == 0; }
        }
        public int Width { get; set; }

        public static Size Add(Size sz1, Size sz2)
        {
            return new Size(sz1.Width + sz2.Width, sz1.Height + sz2.Height);
        }
        public static Size Ceiling(SizeF value)
        {
            return new Size((int)Math.Ceiling(value.Width), (int)Math.Ceiling(value.Height));
        }
        public static Size Subtract(Size sz1, Size sz2)
        {
            return new Size(sz1.Width - sz2.Width, sz1.Height - sz2.Height);
        }
        public static Size Truncate(SizeF value)
        {
            return new Size((int)value.Width, (int)value.Height);
        }
        public static Size Round(SizeF value)
        {
            return new Size((int)Math.Round(value.Width), (int)Math.Round(value.Height));
        }
        
        public bool Equals(Size other)
        {
            return Width == other.Width && Height == other.Height;
        }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            return obj is Size && Equals((Size) obj);
        }
        public override int GetHashCode()
        {
            return Width ^ Height;
        }
        public override string ToString()
        {
            return "{Width=" + Width.ToString(CultureInfo.CurrentCulture) + ", Height=" + Height.ToString(CultureInfo.CurrentCulture) + "}";
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/FormClosedEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class FormClosedEventArgs : EventArgs
    {
        public FormClosedEventArgs(CloseReason closeReason)
        {
            CloseReason = closeReason;
        }

        public CloseReason CloseReason { get; private set; }
    }
}


<|start_filename|>Assets/Controls/Highcharts/Axis.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;

    public class Axis : IDisposable
    {
        internal Pen  gridPen = new Pen(Color.Transparent);
        internal bool horizontal;
        internal Pen  linePen = new Pen(Color.Transparent);
        internal Pen  tickPen = new Pen(Color.Transparent);

        private int _offset;

        internal Axis(bool type)
        {
            horizontal = type;

            categories = new List<string>();
            gridFont = Highchart.DefaultFont10;
            max = null;
            min = null;
            tickLength = 10;
            title = new AxisTitle(this);
            visible = true;
        }

        public event EventHandler OffsetChanged;

        public List<string> categories { get; private set; }

        /// <summary>
        /// Color of the grid lines extending the ticks across the plot area.
        /// </summary>
        public Color gridLineColor
        {
            get { return gridPen.Color; }
            set { gridPen.Color = value; }
        }
        [Obsolete("dunno")]
        public Font gridFont { get; set; }

        /// <summary>
        /// The width of the grid lines extending the ticks across the plot area.
        /// </summary>
        public int gridLineWidth
        {
            get { return (int) gridPen.Width; }
            set { gridPen.Width = value; }
        }

        /// <summary>
        /// The color of the line marking the axis itself.
        /// </summary>
        public Color lineColor
        {
            get { return linePen.Color; }
            set { linePen.Color = value; }
        }

        /// <summary>
        /// The width of the line marking the axis itself.
        /// </summary>
        public int lineWidth
        {
            get { return (int) linePen.Width; }
            set { linePen.Width = value; }
        }

        public double? max { get; set; }
        public double? min { get; set; }

        /// <summary>
        /// The distance in pixels from the plot area to the axis line. A positive offset moves the axis
        /// with it's line, labels and ticks away from the plot area. This is typically used when two or
        /// more axes are displayed on the same side of the plot. With multiple axes the offset is dynamically
        /// adjusted to avoid collision, this can be overridden by setting offset explicitly.
        ///
        /// Defaults to 0.
        /// </summary>
        public int offset
        {
            get { return _offset; }
            set
            {
                if (_offset == value)
                    return;
                
                _offset = value;
                OnOffsetChanged();
            }
        }

        /// <summary>
        /// Color for the main tick marks.
        /// </summary>
        public Color tickColor
        {
            get { return tickPen.Color; }
            set { tickPen.Color = value; }
        }

        /// <summary>
        /// The pixel length of the main tick marks.
        /// </summary>
        public int tickLength { get; set; }

        /// <summary>
        /// The pixel width of the major tick marks.
        /// </summary>
        public int tickWidth { get; set; }

        /// <summary>
        /// The axis title, showing next to the axis line.
        /// </summary>
        public AxisTitle title { get; set; }

        /// <summary>
        /// Whether axis, including axis title, line, ticks and labels, should be visible.
        ///
        /// Defaults to true.
        /// </summary>
        public bool visible { get; set; }

        public void Dispose()
        {
            if (gridPen != null) gridPen.Dispose();
            if (tickPen != null) tickPen.Dispose();
        }

        protected virtual void OnOffsetChanged()
        {
            var handler = OffsetChanged;
            if (handler != null)
                handler(this, EventArgs.Empty);
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/ScrollEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class ScrollEventArgs : EventArgs
    {
        public ScrollEventArgs(ScrollEventType type, int newValue)
        {
            Type = type;
            NewValue = newValue;
        }
        public ScrollEventArgs(ScrollEventType type, int oldValue, int newValue)
        {
            Type = type;
            this.OldValue = oldValue;
            NewValue = newValue;
        }
        public ScrollEventArgs(ScrollEventType type, int newValue, ScrollOrientation scroll)
        {
            Type = type;
            NewValue = newValue;
            ScrollOrientation = scroll;
        }
        public ScrollEventArgs(ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
        {
            Type = type;
            this.OldValue = oldValue;
            NewValue = newValue;
            ScrollOrientation = scroll;
        }

        public int NewValue { get; set; }
        public int OldValue { get; private set; }
        public ScrollOrientation ScrollOrientation { get; private set; }
        public ScrollEventType Type { get; private set; }
    }
}


<|start_filename|>Assets/System/Windows/Forms/PaintEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class PaintEventArgs
    {
        public Rectangle ClipRectangle { get; set; }
        public Graphics Graphics { get; set;  }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ItemDragEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class ItemDragEventArgs : EventArgs
    {
        public ItemDragEventArgs(MouseButtons button)
        {
            Button = button;
        }
        public ItemDragEventArgs(MouseButtons button, object item)
        {
            Button = button;
            Item = item;
        }

        public MouseButtons Button { get; private set; }
        public object Item { get; private set; }
    }
}


<|start_filename|>Assets/System/Windows/Forms/FormClosingEventHandler.cs<|end_filename|>
namespace System.Windows.Forms
{
    public delegate void FormClosingEventHandler(object sender, FormClosingEventArgs e);
}

<|start_filename|>Assets/Controls/Highcharts/ZoomTypes.cs<|end_filename|>
namespace Highcharts
{
    public enum ZoomTypes
    {
        none,
        x,
        y,
        xy
    }
}

<|start_filename|>Assets/Controls/Highcharts/Series.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Drawing;

    public abstract class Series : IDisposable
    {
        internal SeriesCollection collection;
        internal readonly Pen pen = new Pen(Color.Transparent);

        private string _name;

        protected Series() : this("")
        { }
        
        protected Series(string name)
        {
            color = Color.Gray;
            data = new DataCollection(this);
            pointInterval = 1;
            visible = true;
            
            this.name = name;
        }

        public event EventHandler NameChanged;

        public Color color
        {
            get { return pen.Color; }
            set { pen.Color = value; }
        }
        public DataCollection data { get; private set; }
        public int index { get; internal set; }
        public string name
        {
            get { return _name; }
            set
            {
                if (_name == value)
                    return;

                _name = value;
                OnNameChanged(EventArgs.Empty);
            }
        }
        /// <summary>
        /// If no x values are given for the points in a series, pointInterval defines the interval of the x values. 
        /// For example, if a series contains one value every decade starting from year 0, set pointInterval to 10.
        /// Defaults to 1.
        /// </summary>
        public float pointInterval { get; set; }
        public object tag { get; set; }
        public bool visible { get; set; }
        public int yAxis { get; set; }

        public void Dispose()
        {
            if (pen != null) pen.Dispose();
        }

        public override string ToString()
        {
            return "{name=" + name + "}";
        }
        
        internal void Paint(Graphics g, Rectangle clipRectangle)
        {
            if (!visible || data.Count == 0 || pointInterval <= 0) return;
            
            OnPaint(g, clipRectangle);
        }

        internal void PaintIcon(Graphics g, Rectangle clipRectangle)
        {
            OnPaintIcon(g, clipRectangle);
        }

        public double GetValueRange()
        {
            return collection.chart.cachedPlotMax - collection.chart.cachedPlotMin;
        }

        public float GetXFromIndex(float dataIndex, float xStep, Rectangle clipRectangle)
        {
            return (float) Math.Ceiling(clipRectangle.Left + xStep * dataIndex);
        }
        
        public float GetXStep()
        {
            var chartDataAmount = collection.chart.GetSeriesMaximumDataAmount();
            if (chartDataAmount < 1)
                return collection.chart.cachedPlotWidth / 2f; // Middle point of the plot.
            
            return (float) collection.chart.cachedPlotWidth / (chartDataAmount - 1);
        }

        public float GetYFromValue(double value, double range, Rectangle clipRectangle)
        {
            return (float) Math.Ceiling(clipRectangle.Bottom - clipRectangle.Height * GetYModFromValue(value, range));
        }

        public float GetYModFromValue(double value, double range)
        {
            return (float) ((value - collection.chart.cachedPlotMin) / range);
        }
        
        protected virtual void OnNameChanged(EventArgs e)
        {
            var handler = NameChanged;
            if (handler != null)
                handler(this, e);
        }
        protected abstract void OnPaint(Graphics g, Rectangle clipRectangle);
        protected abstract void OnPaintIcon(Graphics g, Rectangle clipRectangle);
    }
}

<|start_filename|>Assets/Examples/Panels/PanelMenuStrip.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Drawing;
    using System.Windows.Forms;

    public class PanelMenuStrip : BaseExamplePanel
    {
        public override void Initialize()
        {
            var itemFile_New = new ToolStripMenuItem("New");
            var itemFile_Open = new ToolStripMenuItem("Open");
            var itemFile_Save = new ToolStripMenuItem("Save");
            var itemFile_Exit = new ToolStripMenuItem("Exit");

            itemFile_New.ShortcutKeys = Keys.Control | Keys.N;
            itemFile_Save.ShortcutKeys = Keys.Control | Keys.S;
            itemFile_Exit.ShortcutKeys = Keys.Control | Keys.W;

            itemFile_Open.DropDownItems.Add(new ToolStripMenuItem("file1.txt"));
            itemFile_Open.DropDownItems.Add(new ToolStripMenuItem("file2.txt"));
            itemFile_Open.DropDownItems.Add(new ToolStripMenuItem("file3.txt"));
            itemFile_Open.DropDownItems.Add(new ToolStripSeparator());
            itemFile_Open.DropDownItems.Add(new ToolStripMenuItem("last"));

            itemFile_Exit.Image = uwfAppOwner.Resources.Close;
            itemFile_Exit.uwfImageColor = Color.FromArgb(64, 64, 64);

            var itemEdit_Undo = new ToolStripMenuItem("Undo");
            var itemEdit_Redo = new ToolStripMenuItem("Redo");

            itemEdit_Undo.ShortcutKeys = Keys.Control | Keys.Z;
            itemEdit_Redo.ShortcutKeys = Keys.Control | Keys.Y;

            var itemFile = new ToolStripMenuItem("File");
            var itemEdit = new ToolStripMenuItem("Edit");
            var itemView = new ToolStripMenuItem("View");

            itemFile.DropDownItems.Add(itemFile_New);
            itemFile.DropDownItems.Add(itemFile_Open);
            itemFile.DropDownItems.Add(itemFile_Save);
            itemFile.DropDownItems.Add(new ToolStripSeparator());
            itemFile.DropDownItems.Add(itemFile_Exit);

            itemEdit.DropDownItems.Add(itemEdit_Undo);
            itemEdit.DropDownItems.Add(itemEdit_Redo);

            itemView.DropDownItems.Add(new ToolStripMenuItem("nothing"));
            
            var menu = new MenuStrip();
            menu.Items.Add(itemFile);
            menu.Items.Add(itemEdit);
            menu.Items.Add(itemView);

            Controls.Add(menu);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/AutoCompleteSource.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum AutoCompleteSource
    {
        FileSystem = 1,
        HistoryList = 2,
        RecentlyUsedList = 4,
        AllUrl = 6,
        AllSystemSources = 7,
        FileSystemDirectories = 32,
        CustomSource = 64,
        None = 128,
        ListItems = 256,
    }
}


<|start_filename|>Assets/System/Windows/Forms/MenuStrip.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;
    
    public class MenuStrip : ToolStrip
    {
        public MenuStrip()
        {
            ShowItemToolTips = false;
        }

        protected override Padding DefaultPadding
        {
            get { return new Padding(6, 2, 0, 2); }
        }
        protected override Size DefaultSize
        {
            get { return new Size(200, 24); }
        }
    }
}


<|start_filename|>Assets/Utility/MathHelper.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public static class MathHelper
    {
        public static float CatmullRom(float value1, float value2, float value3, float value4, float amount)
        {
            // originaly from https://github.com/mono/MonoGame/
            // Using formula from http://www.mvps.org/directx/articles/catmull/
            // Internally using doubles not to lose precission
            double amountSquared = amount * amount;
            double amountCubed = amountSquared * amount;
            return (float)(0.5 * (2.0 * value2 +
                (value3 - value1) * amount +
                (2.0 * value1 - 5.0 * value2 + 4.0 * value3 - value4) * amountSquared +
                (3.0 * value2 - value1 - 3.0 * value3 + value4) * amountCubed));
        }
        public static byte Clamp(byte value, byte min, byte max)
        {
            if (value > max)
                value = max;

            if (value < min)
                value = min;

            return value;
        }
        public static int Clamp(int value, int min, int max)
        {
            if (value > max)
                value = max;

            if (value < min)
                value = min;

            return value;
        }
        public static float Clamp(float value, float min, float max)
        {
            if (value > max)
                value = max;

            if (value < min)
                value = min;

            return value;
        }
        public static double Clamp(double value, double min, double max)
        {
            if (value > max)
                value = max;

            if (value < min)
                value = min;

            return value;
        }
        public static Color ColorLerp(Color from, Color to, float speed)
        {
            if (from == to) return from;
            var r = (int)Math.Ceiling(FloatLerp(from.R, to.R, speed));
            var g = (int)Math.Ceiling(FloatLerp(from.G, to.G, speed));
            var b = (int)Math.Ceiling(FloatLerp(from.B, to.B, speed));
            var a = (int)Math.Ceiling(FloatLerp(from.A, to.A, speed));
            return Color.FromArgb(a, r, g, b);
        }
        public static void ColorLerp(Color to, float speed, ref float a, ref float r, ref float g, ref float b)
        {
            r = FloatLerp(r, to.R, speed);
            g = FloatLerp(g, to.G, speed);
            b = FloatLerp(b, to.B, speed);
            a = FloatLerp(a, to.A, speed);
        }
        public static double DistanceD(float x1, float y1, float x2, float y2)
        {
            return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
        }
        public static double DistanceD(PointF p1, PointF p2)
        {
            return DistanceD(p1.X, p1.Y, p2.X, p2.Y);
        }
        public static float DistanceF(float value1, float value2)
        {
            return Math.Abs(value1 - value2);
        }
        public static float DistanceF(float x1, float y1, float x2, float y2)
        {
            return (float)DistanceD(x1, y1, x2, y2);
        }
        public static float DistanceF(PointF p1, PointF p2)
        {
            return (float)DistanceD(p1, p2);
        }
        /// <summary>
        /// Linear interpolation between two values.
        /// </summary>
        /// <param name="from_value"></param>
        /// <param name="to_value"></param>
        /// <param name="speed"></param>
        /// <returns></returns>
        public static float FloatLerp(float from_value, float to_value, float speed)
        {
            return from_value + (to_value - from_value) * speed * swfHelper.GetDeltaTime();
        }
        public static bool InRange(int val, int min, int max)
        {
            return (val >= min && val <= max);
        }
        public static bool InRange(float val, float min, float max)
        {
            return (val >= min && val <= max);
        }
        public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
        {
            // originaly from https://github.com/mono/MonoGame/
            // All transformed to double not to lose precission
            // Otherwise, for high numbers of param:amount the result is NaN instead of Infinity
            double v1 = value1, v2 = value2, t1 = tangent1, t2 = tangent2, s = amount, result;
            double sCubed = s * s * s;
            double sSquared = s * s;

            if (amount == 0f)
                result = value1;
            else if (amount == 1f)
                result = value2;
            else
                result = (2 * v1 - 2 * v2 + t2 + t1) * sCubed +
                    (3 * v2 - 3 * v1 - 2 * t1 - t2) * sSquared +
                    t1 * s +
                    v1;
            return (float)result;
        }
        /// <summary>
        /// Interpolates between two values using a cubic equation.
        /// </summary>
        /// <param name="value1">Source value.</param>
        /// <param name="value2">Source value.</param>
        /// <param name="amount">Weighting value.</param>
        /// <returns>Interpolated value.</returns>
        public static float SmoothStep(float value1, float value2, float amount)
        {
            // originaly from https://github.com/mono/MonoGame/
            // It is expected that 0 < amount < 1
            // If amount < 0, return value1
            // If amount > 1, return value2
            float deltaTime = swfHelper.GetDeltaTime();
            float result = MathHelper.Clamp(amount * deltaTime, 0f, 1f);
            result = MathHelper.Hermite(value1, 0f, value2, 0f, result);

            return result;
        }
        public static float Step(float from_value, float to_value, float speed)
        {
            float uSpeed = speed * swfHelper.GetDeltaTime();
            if (Math.Abs(from_value - to_value) < uSpeed) return to_value;

            if (from_value < to_value)
                return from_value + uSpeed;
            else
                return from_value - uSpeed;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ControlEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void ControlEventHandler(object sender, ControlEventArgs e);

    public class ControlEventArgs : EventArgs
    {
        public ControlEventArgs(Control control)
        {
            Control = control;
        }

        public Control Control { get; private set; }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelForm.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    public class PanelForm : BaseExamplePanel
    {
        public override void Initialize()
        {
            var buttonForm = this.Create<Button>("Form");
            buttonForm.Click += (sender, args) =>
            {
                var form = new Form();
                form.Text = "Form";
                form.Show();
            };

            var buttonDialog = this.Create<Button>("Dialog");
            buttonDialog.Click += OnButtonDialogOnClick;

            var buttonMdi = this.Create<Button>("Mdi");
            buttonMdi.Click += OnButtonMdiOnClick;
        }
        
        private void OnButtonDialogOnClick(object sender, EventArgs args)
        {
            var form = new Form();
            form.Text = "Dialog";
            form.ShowDialog();
            var buttonDialog = form.Create<Button>("Dialog");
            buttonDialog.Click += OnButtonDialogOnClick;
        }
        private void OnButtonMdiOnClick(object sender, EventArgs args)
        {
            var form = new Form();
            form.IsMdiContainer = true;
            form.Text = "Mdi Form";
            form.Size = new Size(640, 480);
            form.SizeGripStyle = SizeGripStyle.Show;
            form.Show();

            var formTree = new Form();
            formTree.BackColor = Color.White;
            formTree.Text = "Inner Form";
            formTree.MdiParent = form;

            var tree = new TreeView();
            tree.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top;
            tree.BackColor = Color.White;
            tree.BorderStyle = BorderStyle.None;
            tree.Location = new Point(0, formTree.uwfHeaderHeight);
            tree.Size = new Size(formTree.Width, formTree.Height - formTree.uwfHeaderHeight - 16);

            for (int i = 0; i < 50; i++)
                tree.Nodes.Add("test node " + i);

            tree.Refresh();

            formTree.Controls.Add(tree);
            formTree.SizeGripStyle = SizeGripStyle.Show;
            formTree.Show();
            
            var formColor = new ColorPickerForm();
            formColor.MdiParent = form;
            formColor.Color = tree.BackColor;
            formColor.Show();
            formColor.ColorChanged += (o, eventArgs) => tree.BackColor = formColor.Color;
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/ScrollOrientation.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum ScrollOrientation
    {
        HorizontalScroll = 0,
        VerticalScroll = 1,
    }
}


<|start_filename|>Assets/Examples/Panels/PanelGroupBox.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;
    
    public class PanelGroupBox : BaseExamplePanel
    {
        public override void Initialize()
        {
            this.Create<Label>("Without text");
            this.Create<GroupBox>("", true);
            
            this.Create<Label>("With text", false, 8, 112);
            this.Create<GroupBox>("GroupBox", true);
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/ItemDragEventHandler.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public delegate void ItemDragEventHandler(object sender, ItemDragEventArgs e);
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripDropDown.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class ToolStripDropDown : ToolStrip
    {
        internal ToolStripDropDownDirection direction;
        internal readonly Pen borderPen = new Pen(Color.FromArgb(128, 128, 128));
        internal Color uwfColumnBackColor = SystemColors.Control; // ?
        
        private ToolStripItem ownerItem;

        public ToolStripDropDown()
        {
            Orientation = Orientation.Vertical;
            ShowItemToolTips = false; // I'm not really sure.
            Visible = false;
        }

        public ToolStripItem OwnerItem { get; set; }

        public new void Show()
        {
            Location = new Point();
            SetVisibleCore();
        }
        public void Show(Control control, Point position)
        {
            Location = control == null ? position : control.PointToScreen(Point.Empty).Add(position);

            SetVisibleCore();
        }
        public void Show(Control control, int x, int y)
        {
            Show(control, new Point(x, y));
        }
        public void Show(Point screenLocation)
        {
            Location = screenLocation;
            SetVisibleCore();
        }
        public void Show(int x, int y)
        {
            Location = new Point(x, y);
            SetVisibleCore();
        }

        protected override void Dispose(bool release_all)
        {
            var disposeIsBlocked = false; // By something unnatural.

            for (int i = 0; i < Items.Count; i++)
            {
                var dropDownItem = Items[i] as ToolStripDropDownItem;
                if (dropDownItem == null)
                    continue;

                if (dropDownItem.DropDown == null || 
                    dropDownItem.DropDown.IsDisposed) continue;

                disposeIsBlocked = true; // We can't dispose parent before child.
                break;
            }

            if (disposeIsBlocked)
                return;

            base.Dispose(release_all);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            switch (e.KeyCode)
            {
                case Keys.Escape:
                case Keys.Left:
                    {
                        if (selectedItem != null)
                        {
                            var ownerDropDownItem = selectedItem.OwnerItem as ToolStripDropDownItem;
                            if (ownerDropDownItem != null)
                                ownerDropDownItem.CloseToolStrip();
                        }
                    }
                    break;
                case Keys.Right:
                    {
                        var dropDownItem = selectedItem as ToolStripDropDownItem;
                        if (dropDownItem != null)
                            dropDownItem.RaiseClick();
                    }
                    break;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            var graphics = e.Graphics;

            graphics.uwfFillRectangle(uwfColumnBackColor, 2, 2, 22, Height - 4);

            base.OnPaint(e);

            graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
        }
        protected override void SetBoundsCore(int argX, int argY, int argWidth, int argHeight, BoundsSpecified specified)
        {
            // Fix location
            var workingArea = Screen.PrimaryScreen.WorkingArea;
            var newBounds = WindowsFormsUtils.ConstrainToBounds(workingArea, new Rectangle(argX, argY, argWidth, argHeight));
            ////var xFixed = argX != newBounds.X;

            // TODO: need some code to prevent child going outside of screen.
            /*if (OwnerItem != null)
            {
                var parentDropDown = OwnerItem.Owner as ToolStripDropDown;
                if (parentDropDown != null && direction == ToolStripDropDownDirection.Right)
                {
                    // TODO: need to add other direction. Should be ToolStripDropDownItem, but the problem is that 
                    // it's invoked after Graphics.MeasureString, which can only be done on paint thread.
                    if (xFixed && newBounds.X + newBounds.Width - 2 >= parentDropDown.Location.X)
                        newBounds = new Rectangle(parentDropDown.Location.X - argWidth + 2, newBounds.Y, newBounds.Width, newBounds.Height);
                }
            }*/

            base.SetBoundsCore(newBounds.X, newBounds.Y, newBounds.Width, newBounds.Height, specified);
        }
        protected void SetVisibleCore()
        {
            var itemsCount = Items.Count;
            if (itemsCount == 0)
                return;

            Visible = true;

            for (int i = 0; i < itemsCount; i++)
            {
                var item = Items[i];
                item.TextAlign = ContentAlignment.MiddleLeft; // I think it's impossible to use user text align consider to WinForms.
            }

            Focus();
        }

        private bool ContainsMouse()
        {


            return false;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ImageLayout.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum ImageLayout
    {
        None = 0,
        Tile = 1,
        Center = 2,
        Stretch = 3,
        Zoom = 4,
        CenterZoom = 5,
    }
}


<|start_filename|>Assets/Unity/API/UnityGdiSprite.cs<|end_filename|>
﻿namespace Unity.API
{
    using System.Drawing;
    using System.Drawing.API;

    public class UnityGdiSprite : ITexture
    {
        internal readonly UnityEngine.Sprite sprite;

        public UnityGdiSprite(UnityEngine.Sprite spr)
        {
            sprite = spr;
        }

        public int Height
        {
            get { return (int)sprite.rect.height; }
        }
        public int Width
        {
            get { return (int)sprite.rect.width; }
        }

        public void Apply()
        {
        }
        public void Clear(Color color)
        {
        }
        public Color GetPixel(int x, int y)
        {
            throw new System.NotImplementedException();
        }
        public Color[] GetPixels()
        {
            throw new System.NotImplementedException();
        }
        public Color[] GetPixels(int x, int y, int width, int height)
        {
            throw new System.NotImplementedException();
        }
        public void SetPixel(int x, int y, Color color)
        {
            throw new System.NotImplementedException();
        }
        public void SetPixels(Color[] colors)
        {
            throw new System.NotImplementedException();
        }
        public void SetPixels(int x, int y, int width, int height, Color[] colors)
        {
            throw new System.NotImplementedException();
        }
    }
}


<|start_filename|>Assets/Controls/Highcharts/DataCollection.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Collections;
    using System.Collections.Generic;

    public class DataCollection : IEnumerable
    {
        private static readonly double[] emptyArray = new double[0];

        private readonly Series owner;

        private double[] items = new double[0]; // TODO: nullable type.
        private double max;
        private double min;
        private int size;
        
        public DataCollection(Series s)
        {
            owner = s;

            DefaultMax = 1d;

            Clear();
        }

        public int Count
        {
            get { return size; }
        }
        public double DefaultMax { get; set; }
        public double[] Items
        {
            get { return items; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                
                items = value;
                size = value.Length;
            
                UpdateMinimum();
                UpdateMaximum();
            }
        }
        
        public double this[int index]
        {
            get { return items[index]; }
            set { items[index] = value; }
        }

        public void Add(double val)
        {
            if (size == items.Length)
                EnsureCapacity(size + 1);

            items[size++] = val;
            
            if (val < min) min = val;
            if (val > max) max = val;
        }
        public void Clear()
        {
            if (size > 0)
            {
                Array.Clear(items, 0, size);
                size = 0;
            }

            min = 0;
            max = DefaultMax;
        }
        public IEnumerator GetEnumerator()
        {
            return items.GetEnumerator();
        }
        public double GetMax()
        {
            UpdateMaximum();
            return max;
        }
        public double GetMin()
        {
            UpdateMinimum();
            return min;
        }
        public void RemoveAt(int index)
        {
            double valAt = items[index];

            if ((uint) index >= (uint) size)
                throw new ArgumentOutOfRangeException("index");
            
            --size;
            
            if (index < size)
                Array.Copy(items, index + 1, items, index, size - index);
            
            items[size] = 0;

            if (valAt <= min)
                UpdateMinimum();

            if (valAt >= max)
                UpdateMaximum();
        }
        
        private void EnsureCapacity(int minCapacity)
        {
            if (items.Length >= minCapacity)
                return;
            
            int newCapacity = items.Length == 0 ? 4 : items.Length * 2;
            if (newCapacity < minCapacity)
                newCapacity = minCapacity;
            
            SetCapacity(newCapacity);
        }
        private void SetCapacity(int value)
        {
            if (value == items.Length)
                return;
            
            if (value < size)
                throw new ArgumentOutOfRangeException("value");
                
            if (value > 0)
            {
                var objArray = new double[value];
                if (size > 0)
                    Array.Copy(items, 0, objArray, 0, size);
                
                items = objArray;
            }
            else
                items = emptyArray;   
        }
        private void UpdateMaximum()
        {
            var changed = false;
            max = 0;

            // Find a new max value.
            for (int i = 0; i < items.Length; i++)
            {
                var item = items[i];
                if (changed == false || item > max)
                {
                    max = item;
                    changed = true;
                }
            }

            // Reset max.
            if (changed == false)
                max = DefaultMax;
        }
        private void UpdateMinimum()
        {
            var changed = false;
            min = 0;

            // Find a new min value.
            for (int i = 0; i < items.Length; i++)
            {
                var item = items[i];
                if (changed == false || item < min)
                {
                    min = item;
                    changed = true;
                }
            }

            // Reset min.
            if (changed == false)
                min = 0;
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/DrawMode.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum DrawMode
    {
        Normal,
        OwnerDrawFixed,
        OwnerDrawVariable,
    }
}


<|start_filename|>Assets/System/Windows/Forms/ScrollBars.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum ScrollBars
    {
        None = 0,
        Horizontal = 1,
        Vertical = 2,
        Both = 3,
    }
}


<|start_filename|>Assets/System/Windows/Forms/ButtonState.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum ButtonState
    {
        Normal = 0,
        Inactive = 256,
        Pushed = 512,
        Checked = 1024,
        Flat = 16384,
        All = 18176,
    }
}


<|start_filename|>Assets/System/Drawing/Brushes.cs<|end_filename|>
﻿namespace System.Drawing
{
    public static class Brushes
    {
        private static Brush aliceBlue;
        private static Brush antiqueWhite;
        private static Brush aqua;
        private static Brush aquamarine;
        private static Brush azure;
        private static Brush beige;
        private static Brush bisque;
        private static Brush black;
        private static Brush blanchedAlmond;
        private static Brush blue;
        private static Brush blueViolet;
        private static Brush brown;
        private static Brush burlyWood;
        private static Brush cadetBlue;
        private static Brush chartreuse;
        private static Brush chocolate;
        private static Brush coral;
        private static Brush cornflowerBlue;
        private static Brush cornsilk;
        private static Brush crimson;
        private static Brush cyan;
        private static Brush darkBlue;
        private static Brush darkCyan;
        private static Brush darkGoldenrod;
        private static Brush darkGray;
        private static Brush darkGreen;
        private static Brush darkKhaki;
        private static Brush darkMagenta;
        private static Brush darkOliveGreen;
        private static Brush darkOrange;
        private static Brush darkOrchid;
        private static Brush darkRed;
        private static Brush darkSalmon;
        private static Brush darkSeaGreen;
        private static Brush darkSlateBlue;
        private static Brush darkSlateGray;
        private static Brush darkTurquoise;
        private static Brush darkViolet;
        private static Brush deepPink;
        private static Brush deepSkyBlue;
        private static Brush dimGray;
        private static Brush dodgerBlue;
        private static Brush firebrick;
        private static Brush floralWhite;
        private static Brush forestGreen;
        private static Brush fuchsia;
        private static Brush gainsboro;
        private static Brush ghostWhite;
        private static Brush gold;
        private static Brush green;
        private static Brush greenYellow;
        private static Brush goldenrod;
        private static Brush gray;
        private static Brush honeydew;
        private static Brush hotPink;
        private static Brush indianRed;
        private static Brush indigo;
        private static Brush ivory;
        private static Brush khaki;
        private static Brush lavender;
        private static Brush lavenderBlush;
        private static Brush lawnGreen;
        private static Brush lemonChiffon;
        private static Brush lightBlue;
        private static Brush lightCoral;
        private static Brush lightCyan;
        private static Brush lightGoldenrodYellow;
        private static Brush lightGray;
        private static Brush lightGreen;
        private static Brush lightPink;
        private static Brush lightSalmon;
        private static Brush lightSeaGreen;
        private static Brush lightSlateGray;
        private static Brush lightSkyBlue;
        private static Brush lightSteelBlue;
        private static Brush lightYellow;
        private static Brush lime;
        private static Brush limeGreen;
        private static Brush linen;
        private static Brush magenta;
        private static Brush maroon;
        private static Brush mediumAquamarine;
        private static Brush mediumBlue;
        private static Brush mediumOrchid;
        private static Brush mediumPurple;
        private static Brush mediumSeaGreen;
        private static Brush mediumSlateBlue;
        private static Brush mediumSpringGreen;
        private static Brush mediumTurquoise;
        private static Brush mediumVioletRed;
        private static Brush midnightBlue;
        private static Brush mintCream;
        private static Brush mistyRose;
        private static Brush moccasin;
        private static Brush navajoWhite;
        private static Brush navy;
        private static Brush oldLace;
        private static Brush olive;
        private static Brush oliveDrab;
        private static Brush orange;
        private static Brush orangeRed;
        private static Brush orchid;
        private static Brush paleGoldenrod;
        private static Brush paleGreen;
        private static Brush paleTurquoise;
        private static Brush paleVioletRed;
        private static Brush papayaWhip;
        private static Brush peachPuff;
        private static Brush peru;
        private static Brush pink;
        private static Brush plum;
        private static Brush powderBlue;
        private static Brush purple;
        private static Brush red;
        private static Brush rosyBrown;
        private static Brush royalBlue;
        private static Brush saddleBrown;
        private static Brush salmon;
        private static Brush sandyBrown;
        private static Brush seaGreen;
        private static Brush seaShell;
        private static Brush sienna;
        private static Brush silver;
        private static Brush slateBlue;
        private static Brush slateGray;
        private static Brush skyBlue;
        private static Brush snow;
        private static Brush springGreen;
        private static Brush steelBlue;
        private static Brush tan;
        private static Brush teal;
        private static Brush thistle;
        private static Brush tomato;
        private static Brush transparent;
        private static Brush turquoise;
        private static Brush violet;
        private static Brush wheat;
        private static Brush white;
        private static Brush whiteSmoke;
        private static Brush yellow;
        private static Brush yellowGreen;

        public static Brush AliceBlue
        {
            get
            {
                if (aliceBlue == null)
                    aliceBlue = new SolidBrush(Color.AliceBlue);

                return aliceBlue;
            }
        }
        public static Brush AntiqueWhite
        {
            get
            {
                if (antiqueWhite == null)
                    antiqueWhite = new SolidBrush(Color.AntiqueWhite);

                return antiqueWhite;
            }
        }
        public static Brush Aqua
        {
            get
            {
                if (aqua == null)
                    aqua = new SolidBrush(Color.Aqua);

                return aqua;
            }
        }
        public static Brush Aquamarine
        {
            get
            {
                if (aquamarine == null)
                    aquamarine = new SolidBrush(Color.Aquamarine);

                return aquamarine;
            }
        }
        public static Brush Azure
        {
            get
            {
                if (azure == null)
                    azure = new SolidBrush(Color.Azure);

                return azure;
            }
        }
        public static Brush Beige
        {
            get
            {
                if (beige == null)
                    beige = new SolidBrush(Color.Beige);

                return beige;
            }
        }
        public static Brush Bisque
        {
            get
            {
                if (bisque == null)
                    bisque = new SolidBrush(Color.Bisque);

                return bisque;
            }
        }
        public static Brush Black
        {
            get
            {
                if (black == null)
                    black = new SolidBrush(Color.Black);

                return black;
            }
        }
        public static Brush BlanchedAlmond
        {
            get
            {
                if (blanchedAlmond == null)
                    blanchedAlmond = new SolidBrush(Color.BlanchedAlmond);

                return blanchedAlmond;
            }
        }
        public static Brush Blue
        {
            get
            {
                if (blue == null)
                    blue = new SolidBrush(Color.Blue);

                return blue;
            }
        }
        public static Brush BlueViolet
        {
            get
            {
                if (blueViolet == null)
                    blueViolet = new SolidBrush(Color.BlueViolet);

                return blueViolet;
            }
        }
        public static Brush Brown
        {
            get
            {
                if (brown == null)
                    brown = new SolidBrush(Color.Brown);

                return brown;
            }
        }
        public static Brush BurlyWood
        {
            get
            {
                if (burlyWood == null)
                    burlyWood = new SolidBrush(Color.BurlyWood);

                return burlyWood;
            }
        }
        public static Brush CadetBlue
        {
            get
            {
                if (cadetBlue == null)
                    cadetBlue = new SolidBrush(Color.CadetBlue);

                return cadetBlue;
            }
        }
        public static Brush Chartreuse
        {
            get
            {
                if (chartreuse == null)
                    chartreuse = new SolidBrush(Color.Chartreuse);

                return chartreuse;
            }
        }
        public static Brush Chocolate
        {
            get
            {
                if (chocolate == null)
                    chocolate = new SolidBrush(Color.Chocolate);

                return chocolate;
            }
        }
        public static Brush Coral
        {
            get
            {
                if (coral == null)
                    coral = new SolidBrush(Color.Coral);

                return coral;
            }
        }
        public static Brush CornflowerBlue
        {
            get
            {
                if (cornflowerBlue == null)
                    cornflowerBlue = new SolidBrush(Color.CornflowerBlue);

                return cornflowerBlue;
            }
        }
        public static Brush Cornsilk
        {
            get
            {
                if (cornsilk == null)
                    cornsilk = new SolidBrush(Color.Cornsilk);

                return cornsilk;
            }
        }
        public static Brush Crimson
        {
            get
            {
                if (crimson == null)
                    crimson = new SolidBrush(Color.Crimson);

                return crimson;
            }
        }
        public static Brush Cyan
        {
            get
            {
                if (cyan == null)
                    cyan = new SolidBrush(Color.Cyan);

                return cyan;
            }
        }
        public static Brush DarkBlue
        {
            get
            {
                if (darkBlue == null)
                    darkBlue = new SolidBrush(Color.DarkBlue);

                return darkBlue;
            }
        }
        public static Brush DarkCyan
        {
            get
            {
                if (darkCyan == null)
                    darkCyan = new SolidBrush(Color.DarkCyan);

                return darkCyan;
            }
        }
        public static Brush DarkGoldenrod
        {
            get
            {
                if (darkGoldenrod == null)
                    darkGoldenrod = new SolidBrush(Color.DarkGoldenrod);

                return darkGoldenrod;
            }
        }
        public static Brush DarkGray
        {
            get
            {
                if (darkGray == null)
                    darkGray = new SolidBrush(Color.DarkGray);

                return darkGray;
            }
        }
        public static Brush DarkGreen
        {
            get
            {
                if (darkGreen == null)
                    darkGreen = new SolidBrush(Color.DarkGreen);

                return darkGreen;
            }
        }
        public static Brush DarkKhaki
        {
            get
            {
                if (darkKhaki == null)
                    darkKhaki = new SolidBrush(Color.DarkKhaki);

                return darkKhaki;
            }
        }
        public static Brush DarkMagenta
        {
            get
            {
                if (darkMagenta == null)
                    darkMagenta = new SolidBrush(Color.DarkMagenta);

                return darkMagenta;
            }
        }
        public static Brush DarkOliveGreen
        {
            get
            {
                if (darkOliveGreen == null)
                    darkOliveGreen = new SolidBrush(Color.DarkOliveGreen);

                return darkOliveGreen;
            }
        }
        public static Brush DarkOrange
        {
            get
            {
                if (darkOrange == null)
                    darkOrange = new SolidBrush(Color.DarkOrange);

                return darkOrange;
            }
        }
        public static Brush DarkOrchid
        {
            get
            {
                if (darkOrchid == null)
                    darkOrchid = new SolidBrush(Color.DarkOrchid);

                return darkOrchid;
            }
        }
        public static Brush DarkRed
        {
            get
            {
                if (darkRed == null)
                    darkRed = new SolidBrush(Color.DarkRed);

                return darkRed;
            }
        }
        public static Brush DarkSalmon
        {
            get
            {
                if (darkSalmon == null)
                    darkSalmon = new SolidBrush(Color.DarkSalmon);

                return darkSalmon;
            }
        }
        public static Brush DarkSeaGreen
        {
            get
            {
                if (darkSeaGreen == null)
                    darkSeaGreen = new SolidBrush(Color.DarkSeaGreen);

                return darkSeaGreen;
            }
        }
        public static Brush DarkSlateBlue
        {
            get
            {
                if (darkSlateBlue == null)
                    darkSlateBlue = new SolidBrush(Color.DarkSlateBlue);

                return darkSlateBlue;
            }
        }
        public static Brush DarkSlateGray
        {
            get
            {
                if (darkSlateGray == null)
                    darkSlateGray = new SolidBrush(Color.DarkSlateGray);

                return darkSlateGray;
            }
        }
        public static Brush DarkTurquoise
        {
            get
            {
                if (darkTurquoise == null)
                    darkTurquoise = new SolidBrush(Color.DarkTurquoise);

                return darkTurquoise;
            }
        }
        public static Brush DarkViolet
        {
            get
            {
                if (darkViolet == null)
                    darkViolet = new SolidBrush(Color.DarkViolet);

                return darkViolet;
            }
        }
        public static Brush DeepPink
        {
            get
            {
                if (deepPink == null)
                    deepPink = new SolidBrush(Color.DeepPink);

                return deepPink;
            }
        }
        public static Brush DeepSkyBlue
        {
            get
            {
                if (deepSkyBlue == null)
                    deepSkyBlue = new SolidBrush(Color.DeepSkyBlue);

                return deepSkyBlue;
            }
        }
        public static Brush DimGray
        {
            get
            {
                if (dimGray == null)
                    dimGray = new SolidBrush(Color.DimGray);

                return dimGray;
            }
        }
        public static Brush DodgerBlue
        {
            get
            {
                if (dodgerBlue == null)
                    dodgerBlue = new SolidBrush(Color.DodgerBlue);

                return dodgerBlue;
            }
        }
        public static Brush Firebrick
        {
            get
            {
                if (firebrick == null)
                    firebrick = new SolidBrush(Color.Firebrick);

                return firebrick;
            }
        }
        public static Brush FloralWhite
        {
            get
            {
                if (floralWhite == null)
                    floralWhite = new SolidBrush(Color.FloralWhite);

                return floralWhite;
            }
        }
        public static Brush ForestGreen
        {
            get
            {
                if (forestGreen == null)
                    forestGreen = new SolidBrush(Color.ForestGreen);

                return forestGreen;
            }
        }
        public static Brush Fuchsia
        {
            get
            {
                if (fuchsia == null)
                    fuchsia = new SolidBrush(Color.Fuchsia);

                return fuchsia;
            }
        }
        public static Brush Gainsboro
        {
            get
            {
                if (gainsboro == null)
                    gainsboro = new SolidBrush(Color.Gainsboro);

                return gainsboro;
            }
        }
        public static Brush GhostWhite
        {
            get
            {
                if (ghostWhite == null)
                    ghostWhite = new SolidBrush(Color.GhostWhite);

                return ghostWhite;
            }
        }
        public static Brush Gold
        {
            get
            {
                if (gold == null)
                    gold = new SolidBrush(Color.Gold);

                return gold;
            }
        }
        public static Brush Green
        {
            get
            {
                if (green == null)
                    green = new SolidBrush(Color.Green);

                return green;
            }
        }
        public static Brush GreenYellow
        {
            get
            {
                if (greenYellow == null)
                    greenYellow = new SolidBrush(Color.GreenYellow);

                return greenYellow;
            }
        }
        public static Brush Goldenrod
        {
            get
            {
                if (goldenrod == null)
                    goldenrod = new SolidBrush(Color.Goldenrod);

                return goldenrod;
            }
        }
        public static Brush Gray
        {
            get
            {
                if (gray == null)
                    gray = new SolidBrush(Color.Gray);

                return gray;
            }
        }
        public static Brush Honeydew
        {
            get
            {
                if (honeydew == null)
                    honeydew = new SolidBrush(Color.Honeydew);

                return honeydew;
            }
        }
        public static Brush HotPink
        {
            get
            {
                if (hotPink == null)
                    hotPink = new SolidBrush(Color.HotPink);

                return hotPink;
            }
        }
        public static Brush IndianRed
        {
            get
            {
                if (indianRed == null)
                    indianRed = new SolidBrush(Color.IndianRed);

                return indianRed;
            }
        }
        public static Brush Indigo
        {
            get
            {
                if (indigo == null)
                    indigo = new SolidBrush(Color.Indigo);

                return indigo;
            }
        }
        public static Brush Ivory
        {
            get
            {
                if (ivory == null)
                    ivory = new SolidBrush(Color.Ivory);

                return ivory;
            }
        }
        public static Brush Khaki
        {
            get
            {
                if (khaki == null)
                    khaki = new SolidBrush(Color.Khaki);

                return khaki;
            }
        }
        public static Brush Lavender
        {
            get
            {
                if (lavender == null)
                    lavender = new SolidBrush(Color.Lavender);

                return lavender;
            }
        }
        public static Brush LavenderBlush
        {
            get
            {
                if (lavenderBlush == null)
                    lavenderBlush = new SolidBrush(Color.LavenderBlush);

                return lavenderBlush;
            }
        }
        public static Brush LawnGreen
        {
            get
            {
                if (lawnGreen == null)
                    lawnGreen = new SolidBrush(Color.LawnGreen);

                return lawnGreen;
            }
        }
        public static Brush LemonChiffon
        {
            get
            {
                if (lemonChiffon == null)
                    lemonChiffon = new SolidBrush(Color.LemonChiffon);

                return lemonChiffon;
            }
        }
        public static Brush LightBlue
        {
            get
            {
                if (lightBlue == null)
                    lightBlue = new SolidBrush(Color.LightBlue);

                return lightBlue;
            }
        }
        public static Brush LightCoral
        {
            get
            {
                if (lightCoral == null)
                    lightCoral = new SolidBrush(Color.LightCoral);

                return lightCoral;
            }
        }
        public static Brush LightCyan
        {
            get
            {
                if (lightCyan == null)
                    lightCyan = new SolidBrush(Color.LightCyan);

                return lightCyan;
            }
        }
        public static Brush LightGoldenrodYellow
        {
            get
            {
                if (lightGoldenrodYellow == null)
                    lightGoldenrodYellow = new SolidBrush(Color.LightGoldenrodYellow);

                return lightGoldenrodYellow;
            }
        }
        public static Brush LightGray
        {
            get
            {
                if (lightGray == null)
                    lightGray = new SolidBrush(Color.LightGray);

                return lightGray;
            }
        }
        public static Brush LightGreen
        {
            get
            {
                if (lightGreen == null)
                    lightGreen = new SolidBrush(Color.LightGreen);

                return lightGreen;
            }
        }
        public static Brush LightPink
        {
            get
            {
                if (lightPink == null)
                    lightPink = new SolidBrush(Color.LightPink);

                return lightPink;
            }
        }
        public static Brush LightSalmon
        {
            get
            {
                if (lightSalmon == null)
                    lightSalmon = new SolidBrush(Color.LightSalmon);

                return lightSalmon;
            }
        }
        public static Brush LightSeaGreen
        {
            get
            {
                if (lightSeaGreen == null)
                    lightSeaGreen = new SolidBrush(Color.LightSeaGreen);

                return lightSeaGreen;
            }
        }
        public static Brush LightSlateGray
        {
            get
            {
                if (lightSlateGray == null)
                    lightSlateGray = new SolidBrush(Color.SlateGray);

                return lightSlateGray;
            }
        }
        public static Brush LightSkyBlue
        {
            get
            {
                if (lightSkyBlue == null)
                    lightSkyBlue = new SolidBrush(Color.LightSkyBlue);

                return lightSkyBlue;
            }
        }
        public static Brush LightSteelBlue
        {
            get
            {
                if (lightSteelBlue == null)
                    lightSteelBlue = new SolidBrush(Color.SteelBlue);

                return lightSteelBlue;
            }
        }
        public static Brush LightYellow
        {
            get
            {
                if (lightYellow == null)
                    lightYellow = new SolidBrush(Color.LightYellow);

                return lightYellow;
            }
        }
        public static Brush Lime
        {
            get
            {
                if (lime == null)
                    lime = new SolidBrush(Color.Lime);

                return lime;
            }
        }
        public static Brush LimeGreen
        {
            get
            {
                if (limeGreen == null)
                    limeGreen = new SolidBrush(Color.LimeGreen);

                return limeGreen;
            }
        }
        public static Brush Linen
        {
            get
            {
                if (linen == null)
                    linen = new SolidBrush(Color.Linen);

                return linen;
            }
        }
        public static Brush Magenta
        {
            get
            {
                if (magenta == null)
                    magenta = new SolidBrush(Color.Magenta);

                return magenta;
            }
        }
        public static Brush Maroon
        {
            get
            {
                if (maroon == null)
                    maroon = new SolidBrush(Color.Maroon);

                return maroon;
            }
        }
        public static Brush MediumAquamarine
        {
            get
            {
                if (mediumAquamarine == null)
                    mediumAquamarine = new SolidBrush(Color.MediumAquamarine);

                return mediumAquamarine;
            }
        }
        public static Brush MediumBlue
        {
            get
            {
                if (mediumBlue == null)
                    mediumBlue = new SolidBrush(Color.MediumBlue);

                return mediumBlue;
            }
        }
        public static Brush MediumOrchid
        {
            get
            {
                if (mediumOrchid == null)
                    mediumOrchid = new SolidBrush(Color.MediumOrchid);

                return mediumOrchid;
            }
        }
        public static Brush MediumPurple
        {
            get
            {
                if (mediumPurple == null)
                    mediumPurple = new SolidBrush(Color.MediumPurple);

                return mediumPurple;
            }
        }
        public static Brush MediumSeaGreen
        {
            get
            {
                if (mediumSeaGreen == null)
                    mediumSeaGreen = new SolidBrush(Color.MediumSeaGreen);

                return mediumSeaGreen;
            }
        }
        public static Brush MediumSlateBlue
        {
            get
            {
                if (mediumSlateBlue == null)
                    mediumSlateBlue = new SolidBrush(Color.MediumSlateBlue);

                return mediumSlateBlue;
            }
        }
        public static Brush MediumSpringGreen
        {
            get
            {
                if (mediumSpringGreen == null)
                    mediumSpringGreen = new SolidBrush(Color.MediumSpringGreen);

                return mediumSpringGreen;
            }
        }
        public static Brush MediumTurquoise
        {
            get
            {
                if (mediumTurquoise == null)
                    mediumTurquoise = new SolidBrush(Color.MediumTurquoise);

                return mediumTurquoise;
            }
        }
        public static Brush MediumVioletRed
        {
            get
            {
                if (mediumVioletRed == null)
                    mediumVioletRed = new SolidBrush(Color.MediumVioletRed);

                return mediumVioletRed;
            }
        }
        public static Brush MidnightBlue
        {
            get
            {
                if (midnightBlue == null)
                    midnightBlue = new SolidBrush(Color.MidnightBlue);

                return midnightBlue;
            }
        }
        public static Brush MintCream
        {
            get
            {
                if (mintCream == null)
                    mintCream = new SolidBrush(Color.MintCream);

                return mintCream;
            }
        }
        public static Brush MistyRose
        {
            get
            {
                if (mistyRose == null)
                    mistyRose = new SolidBrush(Color.MistyRose);

                return mistyRose;
            }
        }
        public static Brush Moccasin
        {
            get
            {
                if (moccasin == null)
                    moccasin = new SolidBrush(Color.Moccasin);

                return moccasin;
            }
        }
        public static Brush NavajoWhite
        {
            get
            {
                if (navajoWhite == null)
                    navajoWhite = new SolidBrush(Color.NavajoWhite);

                return navajoWhite;
            }
        }
        public static Brush Navy
        {
            get
            {
                if (navy == null)
                    navy = new SolidBrush(Color.Navy);

                return navy;
            }
        }
        public static Brush OldLace
        {
            get
            {
                if (oldLace == null)
                    oldLace = new SolidBrush(Color.OldLace);

                return oldLace;
            }
        }
        public static Brush Olive
        {
            get
            {
                if (olive == null)
                    olive = new SolidBrush(Color.Olive);

                return olive;
            }
        }
        public static Brush OliveDrab
        {
            get
            {
                if (oliveDrab == null)
                    oliveDrab = new SolidBrush(Color.OliveDrab);

                return oliveDrab;
            }
        }
        public static Brush Orange
        {
            get
            {
                if (orange == null)
                    orange = new SolidBrush(Color.Orange);

                return orange;
            }
        }
        public static Brush OrangeRed
        {
            get
            {
                if (orangeRed == null)
                    orangeRed = new SolidBrush(Color.OrangeRed);

                return orangeRed;
            }
        }
        public static Brush Orchid
        {
            get
            {
                if (orchid == null)
                    orchid = new SolidBrush(Color.Orchid);

                return orchid;
            }
        }
        public static Brush PaleGoldenrod
        {
            get
            {
                if (paleGoldenrod == null)
                    paleGoldenrod = new SolidBrush(Color.PaleGoldenrod);

                return paleGoldenrod;
            }
        }
        public static Brush PaleGreen
        {
            get
            {
                if (paleGreen == null)
                    paleGreen = new SolidBrush(Color.PaleGreen);

                return paleGreen;
            }
        }
        public static Brush PaleTurquoise
        {
            get
            {
                if (paleTurquoise == null)
                    paleTurquoise = new SolidBrush(Color.PaleTurquoise);

                return paleTurquoise;
            }
        }
        public static Brush PaleVioletRed
        {
            get
            {
                if (paleVioletRed == null)
                    paleVioletRed = new SolidBrush(Color.PaleVioletRed);

                return paleVioletRed;
            }
        }
        public static Brush PapayaWhip
        {
            get
            {
                if (papayaWhip == null)
                    papayaWhip = new SolidBrush(Color.PapayaWhip);

                return papayaWhip;
            }
        }
        public static Brush PeachPuff
        {
            get
            {
                if (peachPuff == null)
                    peachPuff = new SolidBrush(Color.PeachPuff);

                return peachPuff;
            }
        }
        public static Brush Peru
        {
            get
            {
                if (peru == null)
                    peru = new SolidBrush(Color.Peru);

                return peru;
            }
        }
        public static Brush Pink
        {
            get
            {
                if (pink == null)
                    pink = new SolidBrush(Color.Pink);

                return pink;
            }
        }
        public static Brush Plum
        {
            get
            {
                if (plum == null)
                    plum = new SolidBrush(Color.Plum);

                return plum;
            }
        }
        public static Brush PowderBlue
        {
            get
            {
                if (powderBlue == null)
                    powderBlue = new SolidBrush(Color.PowderBlue);

                return powderBlue;
            }
        }
        public static Brush Purple
        {
            get
            {
                if (purple == null)
                    purple = new SolidBrush(Color.Purple);

                return purple;
            }
        }
        public static Brush Red
        {
            get
            {
                if (red == null)
                    red = new SolidBrush(Color.Red);

                return red;
            }
        }
        public static Brush RosyBrown
        {
            get
            {
                if (rosyBrown == null)
                    rosyBrown = new SolidBrush(Color.RosyBrown);

                return rosyBrown;
            }
        }
        public static Brush RoyalBlue
        {
            get
            {
                if (royalBlue == null)
                    royalBlue = new SolidBrush(Color.RoyalBlue);

                return royalBlue;
            }
        }
        public static Brush SaddleBrown
        {
            get
            {
                if (saddleBrown == null)
                    saddleBrown = new SolidBrush(Color.SaddleBrown);

                return saddleBrown;
            }
        }
        public static Brush Salmon
        {
            get
            {
                if (salmon == null)
                    salmon = new SolidBrush(Color.Salmon);

                return salmon;
            }
        }
        public static Brush SandyBrown
        {
            get
            {
                if (sandyBrown == null)
                    sandyBrown = new SolidBrush(Color.SandyBrown);

                return sandyBrown;
            }
        }
        public static Brush SeaGreen
        {
            get
            {
                if (seaGreen == null)
                    seaGreen = new SolidBrush(Color.SeaGreen);

                return seaGreen;
            }
        }
        public static Brush SeaShell
        {
            get
            {
                if (seaShell == null)
                    seaShell = new SolidBrush(Color.SeaShell);

                return seaShell;
            }
        }
        public static Brush Sienna
        {
            get
            {
                if (sienna == null)
                    sienna = new SolidBrush(Color.Sienna);

                return sienna;
            }
        }
        public static Brush Silver
        {
            get
            {
                if (silver == null)
                    silver = new SolidBrush(Color.Silver);

                return silver;
            }
        }
        public static Brush SlateBlue
        {
            get
            {
                if (slateBlue == null)
                    slateBlue = new SolidBrush(Color.SlateBlue);

                return slateBlue;
            }
        }
        public static Brush SlateGray
        {
            get
            {
                if (slateGray == null)
                    slateGray = new SolidBrush(Color.SlateGray);

                return slateGray;
            }
        }
        public static Brush SkyBlue
        {
            get
            {
                if (skyBlue == null)
                    skyBlue = new SolidBrush(Color.SkyBlue);

                return skyBlue;
            }
        }
        public static Brush Snow
        {
            get
            {
                if (snow == null)
                    snow = new SolidBrush(Color.Snow);

                return snow;
            }
        }
        public static Brush SpringGreen
        {
            get
            {
                if (springGreen == null)
                    springGreen = new SolidBrush(Color.SpringGreen);

                return springGreen;
            }
        }
        public static Brush SteelBlue
        {
            get
            {
                if (steelBlue == null)
                    steelBlue = new SolidBrush(Color.SteelBlue);

                return steelBlue;
            }
        }
        public static Brush Tan
        {
            get
            {
                if (tan == null)
                    tan = new SolidBrush(Color.Tan);

                return tan;
            }
        }
        public static Brush Teal
        {
            get
            {
                if (teal == null)
                    teal = new SolidBrush(Color.Teal);

                return teal;
            }
        }
        public static Brush Thistle
        {
            get
            {
                if (thistle == null)
                    thistle = new SolidBrush(Color.Thistle);

                return thistle;
            }
        }
        public static Brush Tomato
        {
            get
            {
                if (tomato == null)
                    tomato = new SolidBrush(Color.Tomato);

                return tomato;
            }
        }
        public static Brush Transparent
        {
            get
            {
                if (transparent == null)
                    transparent = new SolidBrush(Color.Transparent);

                return transparent;
            }
        }
        public static Brush Turquoise
        {
            get
            {
                if (turquoise == null)
                    turquoise = new SolidBrush(Color.Turquoise);

                return turquoise;
            }
        }
        public static Brush Violet
        {
            get
            {
                if (violet == null)
                    violet = new SolidBrush(Color.Violet);

                return violet;
            }
        }
        public static Brush Wheat
        {
            get
            {
                if (wheat == null)
                    wheat = new SolidBrush(Color.Wheat);

                return wheat;
            }
        }
        public static Brush White
        {
            get
            {
                if (white == null)
                    white = new SolidBrush(Color.White);

                return white;
            }
        }
        public static Brush WhiteSmoke
        {
            get
            {
                if (whiteSmoke == null)
                    whiteSmoke = new SolidBrush(Color.WhiteSmoke);

                return whiteSmoke;
            }
        }
        public static Brush Yellow
        {
            get
            {
                if (yellow == null)
                    yellow = new SolidBrush(Color.Yellow);

                return yellow;
            }
        }
        public static Brush YellowGreen
        {
            get
            {
                if (yellowGreen == null)
                    yellowGreen = new SolidBrush(Color.YellowGreen);

                return yellowGreen;
            }
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/DrawTreeNodeEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void DrawTreeNodeEventHandler(object sender, DrawTreeNodeEventArgs e);
}


<|start_filename|>Assets/System/Windows/Forms/TabControlCancelEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.ComponentModel;

    public delegate void TabControlCancelEventHandler(object sender, TabControlCancelEventArgs e);

    public class TabControlCancelEventArgs : CancelEventArgs
    {
        public TabControlCancelEventArgs(TabPage tabPage, int tabPageIndex, bool cancel, TabControlAction action) : base(cancel)
        {
            Action = action;
            TabPage = tabPage;
            TabPageIndex = tabPageIndex;
        }

        public TabControlAction Action { get; private set; }
        public TabPage TabPage { get; private set; }
        public int TabPageIndex { get; private set; }
    }
}


<|start_filename|>Assets/System/Drawing/Rectangle.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Globalization;

    [Serializable]
    public struct Rectangle : IEquatable<Rectangle>
    {
        public static readonly Rectangle Empty = new Rectangle();

        public Rectangle(int x, int y, int width, int height) : this()
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
        }
        public Rectangle(Point location, Size size) : this()
        {
            X = location.X;
            Y = location.Y;
            Width = size.Width;
            Height = size.Height;
        }

        public int Bottom
        {
            get { return Y + Height; }
        }
        public int Height { get; set; }
        public bool IsEmpty
        {
            get { return X == 0 && Y == 0 && Width == 0 && Height == 0; }
        }
        public int Left
        {
            get { return X; }
        }
        public Point Location
        {
            get { return new Point(X, Y); }
            set
            {
                X = value.X;
                Y = value.Y;
            }
        }
        public int Right
        {
            get { return X + Width; }
        }
        public Size Size
        {
            get { return new Size(Width, Height); }
            set
            {
                Width = value.Width;
                Height = value.Height;
            }
        }
        public int Top
        {
            get { return Y; }
        }
        public int Width { get; set; }
        public int X { get; set; }
        public int Y { get; set; }

        public static bool operator !=(Rectangle left, Rectangle right)
        {
            return !(left == right);
        }
        public static bool operator ==(Rectangle left, Rectangle right)
        {
            if (left.X == right.X && left.Y == right.Y && left.Width == right.Width && left.Height == right.Height)
                return true;
            return false;
        }

        public static Rectangle FromLTRB(int left, int top, int right, int bottom)
        {
            return new Rectangle(left,
                top,
                right - left,
                bottom - top);
        }
        public static Rectangle Inflate(Rectangle rect, int x, int y)
        {
            var r = rect;
            r.Inflate(x, y);
            return r;
        }
        public static Rectangle Intersect(Rectangle a, Rectangle b)
        {
            int x1 = Math.Max(a.X, b.X);
            int x2 = Math.Min(a.X + a.Width, b.X + b.Width);
            int y1 = Math.Max(a.Y, b.Y);
            int y2 = Math.Min(a.Y + a.Height, b.Y + b.Height);

            if (x2 >= x1 && y2 >= y1)
                return new Rectangle(x1, y1, x2 - x1, y2 - y1);

            return Empty;
        }
        public static Rectangle Union(Rectangle a, Rectangle b)
        {
            int x1 = Math.Min(a.X, b.X);
            int x2 = Math.Max(a.X + a.Width, b.X + b.Width);
            int y1 = Math.Min(a.Y, b.Y);
            int y2 = Math.Max(a.Y + a.Height, b.Y + b.Height);

            return new Rectangle(x1, y1, x2 - x1, y2 - y1);
        }

        public bool Contains(int x, int y)
        {
            return X <= x && x < X + Width && Y <= y && y < Y + Height;
        }
        public bool Contains(Point pt)
        {
            return Contains(pt.X, pt.Y);
        }
        public bool Contains(Rectangle rect)
        {
            return X <= rect.X && rect.X + rect.Width <= X + Width && Y <= rect.Y && rect.Y + rect.Height <= Y + Height;
        }
        public bool Equals(Rectangle other)
        {
            return X == other.X && Y == other.Y && Width == other.Width && Height == other.Height;
        }
        public override bool Equals(object obj)
        {
            if (!(obj is Rectangle)) return false;
            var rect = (Rectangle) obj;
            return rect.X == X && rect.Y == Y && rect.Width == Width && rect.Height == Height;
        }
        public override int GetHashCode()
        {
            return unchecked((int) ((uint) X ^
                                    (((uint) Y << 13) | ((uint) Y >> 19)) ^
                                    (((uint) Width << 26) | ((uint) Width >> 6)) ^
                                    (((uint) Height << 7) | ((uint) Height >> 25))));
        }
        public void Inflate(int width, int height)
        {
            X -= width;
            Y -= height;
            Width += 2 * width;
            Height += 2 * height;
        }
        public void Inflate(Size size)
        {
            Inflate(size.Width, size.Height);
        }
        public void Intersect(Rectangle rect)
        {
            var rectangle = Intersect(rect, this);
            X = rectangle.X;
            Y = rectangle.Y;
            Width = rectangle.Width;
            Height = rectangle.Height;
        }
        public bool IntersectsWith(Rectangle rect)
        {
            return rect.X < X + Width && X < rect.X + rect.Width && rect.Y < Y + Height && Y < rect.Y + rect.Height;
        }
        public void Offset(Point pos)
        {
            Offset(pos.X, pos.Y);
        }
        public void Offset(int x, int y)
        {
            X += x;
            Y += y;
        }
        public override string ToString()
        {
            return "{X=" + X.ToString(CultureInfo.CurrentCulture) + ",Y=" + Y.ToString(CultureInfo.CurrentCulture) +
                   ",Width=" + Width.ToString(CultureInfo.CurrentCulture) +
                   ",Height=" + Height.ToString(CultureInfo.CurrentCulture) + "}";
        }
    }
}

<|start_filename|>Assets/Controls/Highcharts/SeriesCollection.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Collections;
    using System.Collections.Generic;

    public class SeriesCollection : IList<Series>, IDisposable
    {
        internal readonly Highchart chart;
        
        private readonly List<Series> items = new List<Series>();
        
        public SeriesCollection(Highchart o)
        {
            chart = o;
        }

        public int Count { get { return items.Count; } }
        public bool IsReadOnly { get; private set; }

        public Series this[int index]
        {
            get { return items[index]; }
            set { throw new NotImplementedException(); }
        }

        public Series this[string name]
        {
            get { return items.Find(x => x.name == name); }
        }

        public Series Add(string name)
        {
            var s = new SeriesLineSolid(); // Default.
            s.name = name;
            s.collection = this;

            Add(s);
            return s;
        }
        
        public void Add(Series s)
        {
            s.index = items.Count;
            s.color = chart.GetNextColor();
            s.collection = this;
            
            s.NameChanged -= Series_OnNameChanged;
            s.NameChanged += Series_OnNameChanged;

            items.Add(s);

            chart.AsyncUpdateLegendButtons();
        }
        public void Clear()
        {
            UnsubscribeSeries();
            items.Clear();

            chart.ResetColorIndex();
            chart.AsyncUpdateLegendButtons();
        }
        public bool Contains(Series item)
        {
            return items.Contains(item);
        }
        public void CopyTo(Series[] array, int arrayIndex)
        {
            items.CopyTo(array, arrayIndex);
        }
        public Series Find(Predicate<Series> predicate)
        {
            return items.Find(predicate);
        }
        IEnumerator<Series> IEnumerable<Series>.GetEnumerator()
        {
            return items.GetEnumerator();
        }
        public IEnumerator GetEnumerator()
        {
            return items.GetEnumerator();
        }
        public int IndexOf(Series item)
        {
            return items.IndexOf(item);
        }
        public void Insert(int index, Series item)
        {
            if (item == null)
                throw new ArgumentNullException("item");
            
            items.Insert(index, item);

            UpdateIndexes();
            
            item.NameChanged += Series_OnNameChanged;
            item.NameChanged -= Series_OnNameChanged;
            
            chart.AsyncUpdateLegendButtons();
        }
        public bool Remove(Series item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            var removeResult = items.Remove(item);
            
            item.NameChanged -= Series_OnNameChanged;
            
            UpdateIndexes();
            
            chart.AsyncUpdateLegendButtons();

            return removeResult;
        }
        public void RemoveAt(int index)
        {
            Remove(items[index]);
            UpdateIndexes();
        }
        
        public void Dispose()
        {
            UnsubscribeSeries();

            if (chart != null) chart.Dispose();
        }

        internal int GetColorAlpha()
        {
            return 255 / Count;
        }

        private void Series_OnNameChanged(object sender, EventArgs eventArgs)
        {
            chart.AsyncUpdateLegendButtons();
        }
        private void UnsubscribeSeries()
        {
            for (int i = 0; i < items.Count; i++)
                items[i].NameChanged -= Series_OnNameChanged;
        }
        private void UpdateIndexes()
        {
            for (int i = 0; i < items.Count; i++) 
                items[i].index = i;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/Timer.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.ComponentModel;

    public class Timer : Component
    {
        private float currentTime;
        private bool enabled;
        private int interval;

        public Timer()
        {
            interval = 100;
        }
        public Timer(IContainer container) : this()
        {
            if (container == null)
                throw new ArgumentNullException("container");

            container.Add(this);
        }

        public event EventHandler Tick;

        public bool Enabled
        {
            get { return enabled; }
            set
            {
                if (enabled == value)
                    return;

                enabled = value;
                if (value)
                    StartTimer();
                else
                    StopTimer();
            }
        }
        public int Interval
        {
            get { return interval; }
            set
            {
                if (value < 1)
                    throw new ArgumentOutOfRangeException("value");

                if (interval == value)
                    return;

                interval = value;
                if (Enabled)
                    RestartTimer();
            }
        }
        public object Tag { get; set; }

        public void Start()
        {
            Enabled = true;
        }
        public void Stop()
        {
            Enabled = false;
        }
        public override string ToString()
        {
            return base.ToString() + ", Interval: " + interval;
        }

        protected override void Dispose(bool release_all)
        {
            base.Dispose(release_all);

            StopTimer();
        }
        protected virtual void OnTick(EventArgs e)
        {
            var handler = Tick;
            if (handler != null)
                handler(this, e);
        }

        private void Application_UpdateEvent()
        {
            if (!Enabled)
                return;
            
            currentTime += swfHelper.GetDeltaTime();
            
            if (currentTime <= interval / 1000f) 
                return;

            currentTime = 0;
            
            OnTick(EventArgs.Empty);
        }
        private void RestartTimer()
        {
            StopTimer();
            StartTimer();
        }
        private void StartTimer()
        {
            Application.UpdateEvent -= Application_UpdateEvent;
            Application.UpdateEvent += Application_UpdateEvent;
        }
        private void StopTimer()
        {
            currentTime = 0;
            Application.UpdateEvent -= Application_UpdateEvent;
        }
    }
}


<|start_filename|>Assets/System/Drawing/Bitmap.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Drawing.API;
    
    [Serializable]
    public class Bitmap : Image
    {
        public Bitmap(Image original)
        {
            if (original != null)
                Texture = original.Texture;
        }
        public Bitmap(int width, int height)
        {
            Texture = Graphics.ApiGraphics.CreateTexture(width, height);
        }

        private Bitmap()
        {
        }
        
        public void ClearColor(Color c, bool apply = true)
        {
            var colors = new Color[Width * Height];
            for (int i = 0; i < colors.Length; i++)
                colors[i] = c;
            Texture.SetPixels(colors);
            if (apply) this.Apply();
        }
        public Color GetPixel(int x, int y)
        {
            return Texture.GetPixel(x, Texture.Height - y - 1);
        }
        public Color[] GetPixels(int x, int y, int w, int h)
        {
            var ucs = Texture.GetPixels(x, Texture.Height - y - 1, w, h);
            Color[] cs = new Color[ucs.Length];
            for (int i = 0; i < cs.Length; i++)
                cs[i] = ucs[i];
            return cs;
        }
        public void SetPixel(int x, int y, Color color)
        {
            Texture.SetPixel(x, Texture.Height - y - 1, color);
        }

        internal static Bitmap FromTexture(ITexture tex)
        {
            var bmp = new Bitmap();
            bmp.Texture = tex;

            return bmp;
        }
    }
}


<|start_filename|>Assets/Controls/TableView.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;

    /// <summary>
    /// Simple implementation of DataGridView.
    /// </summary>
    public class TableView : Control
    {
        public int ColumnsDefaultWidth = 100;

        internal TableColumn lastSortedColumn;

        protected int topLeftButtonWidth = 40;

        private readonly Pen borderPen = new Pen(Color.Black);
        private bool columnHeadersHidden;
        private HScrollBar hScroll;
        private bool hScrollHidden;
        private bool rowHeadersHidden;
        private TableColumnButton topLeftButton;
        private VScrollBar vScroll;
        private bool vScrollHidden;

        public TableView()
        {
            BackColor = Color.FromArgb(171, 171, 171);
            CellPadding = 1;
            ColumnsStyle = new TableButtonStyle();
            Padding = new Padding(2);
            SkipControlsInitializations = false;

            Columns = new TableColumnCollection(this);
            Rows = new TableRowCollection(this);
            
            MouseHook.MouseUp += MouseHookOnMouseUp;
        }
        
        public delegate void RowClickHandler(object sender, TableRow row, MouseEventArgs mArgs);

        public event RowClickHandler RowClick;

        public Color BorderColor
        {
            get { return borderPen.Color; }
            set { borderPen.Color = value; }
        }
        public int CellPadding { get; set; }
        public int ColumnCount { get { return Columns.Count; } }
        public TableColumnCollection Columns { get; private set; }
        public TableButtonStyle ColumnsStyle { get; set; }
        public TableRowCollection Rows { get; private set; }
        public bool SkipControlsInitializations { get; set; }

        protected override Size DefaultSize
        {
            get { return new Size(240, 150); }
        }

        private float maxScrollHeight
        {
            get
            {
                if (Rows.Count == 0) return 1;

                var h = Rows.Last().control.Location.Y + Rows.Last().control.Height;
                if (hScroll != null)
                    h += hScroll.Height;
                return h;
            }
        }
        private float maxScrollWidth
        {
            get
            {
                if (Columns.Count == 0) return 1;

                var w = Columns.Last().control.Location.X + Columns.Last().control.Width;
                if (vScroll != null)
                    w += vScroll.Width;
                return w;
            }
        }

        public void HideColumnHeaders()
        {
            columnHeadersHidden = true;

            UpdateColumns();
        }
        public void HideRowHeaders()
        {
            rowHeadersHidden = true;

            UpdateRows();
        }
        public void HideScrolls()
        {
            hScrollHidden = true;
            vScrollHidden = true;

            if (hScroll != null) hScroll.Visible = !hScrollHidden;
            if (vScroll != null) vScroll.Visible = !vScrollHidden;
        }
        public override void Refresh()
        {
            base.Refresh();

            AlignColumns();
            AlignRows();
        }
        public void ShowColumnHeaders()
        {
            columnHeadersHidden = false;

            UpdateColumns();
        }
        public void ShowRowHeaders()
        {
            rowHeadersHidden = false;

            UpdateRows();
        }
        public void ShowScrolls()
        {
            hScrollHidden = false;
            vScrollHidden = false;

            if (hScroll != null) hScroll.Visible = !hScrollHidden;
            if (vScroll != null) vScroll.Visible = !vScrollHidden;
        }
        public virtual void Sort(TableColumn column, ListSortDirection direction)
        {
            if (column == null) return;

            int columnIndex = Columns.FindIndex(column);
            Dictionary<TableRow, object[]> items = new Dictionary<TableRow, object[]>();
            for (int i = 0; i < Rows.Count; i++)
            {
                var r = Rows[i];
                items.Add(r, r.Items);
            }

            var itemsList = items.ToList();
            if (direction == ListSortDirection.Ascending)
                itemsList.Sort((x, y) =>
                {
                    var v1 = x.Value[columnIndex];
                    var v2 = y.Value[columnIndex];

                    if (v1 == null && v2 == null)
                        return 0;

                    if (v1 == null)
                        return -1;
                    if (v2 == null)
                        return 1;

                    var we = v1.ToString().CompareTo(v2.ToString());
                    return we;
                });
            else
                itemsList.Sort((x, y) =>
                {
                    var v1 = x.Value[columnIndex];
                    var v2 = y.Value[columnIndex];

                    if (v1 == null && v2 == null)
                        return 0;

                    if (v1 == null)
                        return 1;
                    if (v2 == null)
                        return -1;

                    var we = v1.ToString().CompareTo(v2.ToString());
                    return -we;
                });

            Rows.ClearList();

            for (int i = 0; i < itemsList.Count; i++)
                Rows.Add(itemsList[i].Key);

            AlignRows();

            if (lastSortedColumn != null)
                lastSortedColumn.control.Padding = new Padding(8, 0, 8, 0);
            lastSortedColumn = column;
            lastSortedColumn.control.Padding = new Padding(24, 0, 8, 0);
            
            if (SkipControlsInitializations)
                TryInitializeDefferedControls();
        }
        public void TryInitializeDefferedControls()
        {
            var controlAdded = false;
            var offsetX = 0;
            var offsetY = 0;

            if (hScroll != null) offsetX = -(int) (maxScrollWidth * hScroll.Value / hScroll.Maximum);
            if (vScroll != null) offsetY = -(int) (maxScrollHeight * vScroll.Value / vScroll.Maximum);

            // Prepare columns X and Width.
            var columnsCount = ColumnCount;
            var columnsX = new int[columnsCount];
            var columnsWidth = new int[columnsCount];
            
            for (int columnIndex = 0; columnIndex < columnsCount; columnIndex++)
            {
                var column = Columns[columnIndex];

                columnsX[columnIndex] = column.control.Location.X;
                columnsWidth[columnIndex] = column.Width;
            }

            // Prepare scrolls values.
            var hScrollMin = 0;
            var hScrollMax = Width;
            var vScrollMin = 0;
            var vScrollMax = Height;
            
            if (hScroll != null && hScroll.Visible)
            {
                hScrollMin = hScroll.Value;
                hScrollMax = hScroll.Height + hScroll.Value + hScroll.LargeChange;
            }

            if (vScroll != null && vScroll.Visible)
            {
                vScrollMin = vScroll.Value;
                vScrollMax = vScroll.Width + vScroll.Value + vScroll.LargeChange;
            }
            
            // Update controls.
            for (int rowIndex = 0; rowIndex < Rows.Count; rowIndex++)
            {
                var row = Rows[rowIndex];
                var rowY = row.control.Location.Y;
                var rowHeight = row.control.Height;
                
                for (int columnIndex = 0; columnIndex < columnsCount; columnIndex++)
                {
                    var cellRect = new Rectangle(columnsX[columnIndex], rowY, columnsWidth[columnIndex], rowHeight);
                    var cellRectX = cellRect.X;
                    var cellRectY = cellRect.Y;
                    var cellIsVisible = 
                            cellRectX + cellRect.Width > hScrollMin && cellRectX < hScrollMax &&
                            cellRectY + cellRect.Height > vScrollMin && cellRectY < vScrollMax;

                    var rowControls = row.ItemsControls;
                    if (rowControls.CreateControlOnCellVisible != null)
                    {
                        var cellControl = rowControls[columnIndex];
                        if (cellIsVisible)
                        {
                            if (cellControl == null)
                            {
                                var newCellControl = rowControls.CreateControlOnCellVisible(columnIndex, rowIndex);
                                newCellControl.Location = cellRect.Location;
                                newCellControl.Size = cellRect.Size;
                                newCellControl.uwfOffset = new Point(offsetX, offsetY);

                                rowControls[columnIndex] = newCellControl;
                                controlAdded = true;
                            }
                        }
                        else
                        {
                            if (cellControl != null)
                            {
                                rowControls[columnIndex] = null;
                            }
                        }
                    }
                }
            }

            if (controlAdded)
            {
                if (vScroll != null)
                    vScroll.BringToFront();
                if (hScroll != null)
                    hScroll.BringToFront();
            }
        }
        
        internal void AlignColumns()
        {
            int cX = Padding.Left;
            if (topLeftButton != null)
            {
                topLeftButton.Location = new Point(Padding.Left, Padding.Top);
                cX = topLeftButton.Location.X + topLeftButton.Width + CellPadding;
            }
            for (int i = 0; i < Columns.Count; i++)
            {
                var column = Columns[i];
                column.control.Location = new Point(cX, Padding.Top);
                cX += column.Width + CellPadding;
            }

            UpdateScrolls();
        }
        internal void AlignRows()
        {
            int cY = Padding.Top;
            if (topLeftButton != null && columnHeadersHidden == false)
            {
                topLeftButton.Location = new Point(Padding.Left, Padding.Top);
                cY = topLeftButton.Location.Y + topLeftButton.Height + CellPadding;
            }
            
            for (int i = 0, cellIndex = 1; i < Rows.Count; i++)
            {
                int cX = Padding.Left;

                var row = Rows[i];
                var rowControls = row.ItemsControls;
                
                row.control.Location = new Point(cX, cY);
                row.UpdateHeaderText();
                
                if (topLeftButton != null)
                    row.control.Width = topLeftButton.Width;

                if (rowHeadersHidden == false)
                    cX += row.control.Width + CellPadding;
                
                for (int k = 0; k < rowControls.Length; k++)
                {
                    var rowIC = rowControls[k];
                    if (rowIC == null) continue;

                    rowIC.Location = new Point(cX, cY);
                    rowIC.TabIndex = cellIndex;
                    rowIC.Size = new Size(Columns[k].Width, row.Height);

                    cellIndex++;
                    cX += rowIC.Width + CellPadding;
                }

                cY += row.control.Height + CellPadding;
            }

            UpdateScrolls();
        }
        internal void RaiseOnRowClick(TableRow row, MouseEventArgs mArgs)
        {
            OnRowClick(row, mArgs);
        }
        internal void UpdateColumn(TableColumn column)
        {
            CreateTopLeftButton();

            if (column.control == null)
            {
                var cButton = new TableColumnButton(this, ColumnsStyle);
                cButton.column = column;
                cButton.EnableHorizontalResizing = true;
                cButton.Name = column.Name;
                cButton.table = this;
                cButton.Text = column.HeaderText;

                column.control = cButton;
                Controls.Add(cButton);
            }

            column.control.Visible = !columnHeadersHidden;
        }
        internal void UpdateColumns()
        {
            for (int i = 0; i < Columns.Count; i++)
                UpdateColumn(Columns[i]);
            AlignColumns();
        }
        internal void UpdateRow(TableRow row)
        {
            CreateTopLeftButton();

            if (row.control == null)
            {
                var rButton = new TableRowButton(ColumnsStyle);
                rButton.row = row;
                rButton.Size = new Size(40, row.Height);

                row.control = rButton;
                row.UpdateHeaderText();
                Controls.Add(rButton);
            }

            row.control.Visible = !rowHeadersHidden;

            if (row.Items.Length != Columns.Count)
                row.AddjustItemsCountTo(Columns.Count);


            if (row.ItemsControls == null)
                row.ItemsControls = new TableRow.TableRowControlsCollection(row, Columns.Count);
            if (row.ItemsControls.Length != row.Items.Length)
            {
                var newControls = new Control[Columns.Count];
                if (row.ItemsControls.Length > newControls.Length) // Dispose unnecessary controls.
                {
                    Array.Copy(row.ItemsControls.items, 0, newControls, 0, newControls.Length);
                    for (int i = newControls.Length; i < row.ItemsControls.Length; i++)
                    {
                        var rowC = row.ItemsControls[i];
                        if (rowC != null)
                            rowC.Dispose();
                    }
                }
                else
                    Array.Copy(row.ItemsControls.items, 0, newControls, 0, row.ItemsControls.Length);
                row.ItemsControls.items = newControls;
            }

            if (SkipControlsInitializations == false)
                for (int i = 0; i < row.Items.Length; i++)
                {
                    if (row.ItemsControls[i] != null) continue;

                    int controlColumn = i;
                    TextBox itemControl = new TextBox();
                    itemControl.uwfBorderColor = Color.Transparent;
                    itemControl.Size = new Size(Columns[i].Width, row.Height);
                    itemControl.TextChanged += (s, a) =>
                    {
                        row.Items[controlColumn] = itemControl.Text;
                    };
                    if (row.Items[i] != null)
                        itemControl.Text = row.Items[i].ToString();

                    row.ItemsControls[i] = itemControl;
                }
        }
        internal void UpdateRows()
        {
            for (int i = 0; i < Rows.Count; i++)
                UpdateRow(Rows[i]);
            AlignRows();
        }

        protected internal override void uwfOnLatePaint(PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
        }
        protected internal override void uwfChildGotFocus(Control child)
        {
            base.uwfChildGotFocus(child);

            EnsureVisibleChild(child);
        }

        protected override void Dispose(bool release_all)
        {
            base.Dispose(release_all);
            
            MouseHook.MouseUp -= MouseHookOnMouseUp;
        }
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            if (vScroll != null)
                vScroll.RaiseOnMouseWheel(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.uwfFillRectangle(BackColor, 0, 0, Width, Height);
        }
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            UpdateScrolls();
            
            if (SkipControlsInitializations)
                TryInitializeDefferedControls();
        }
        protected virtual void OnRowClick(TableRow row, MouseEventArgs e)
        {
            var handler = RowClick;
            if (handler != null)
                handler(this, row, e);
        }
        
        private void CreateTopLeftButton()
        {
            if (rowHeadersHidden)
            {
                if (topLeftButton != null && topLeftButton.IsDisposed == false)
                {
                    topLeftButton.Dispose();
                    topLeftButton = null;
                }
                return;
            }

            if (topLeftButton == null)
            {
                topLeftButton = new TableColumnButton(this, ColumnsStyle);
                topLeftButton.Name = "topLeftButton";
                topLeftButton.Size = new Size(topLeftButtonWidth, 20);
                Controls.Add(topLeftButton);
            }

            topLeftButton.Visible = !rowHeadersHidden && !columnHeadersHidden;
        }
        private void EnsureVisibleChild(Control child)
        {
            var childOffset = child.uwfOffset;
            bool horizontalScroll_Left = child.Location.X + childOffset.X < 0;
            bool horizontalScroll_Right = child.Location.X + childOffset.X + child.Width > Width;
            bool verticalScroll_Top = child.Location.Y + childOffset.Y < 0;
            bool verticalScroll_Bottom = child.Location.Y + childOffset.Y + child.Height > Height && child.Height < Height;

            if (hScroll != null && Width > 0 && (horizontalScroll_Left || horizontalScroll_Right))
            {
                var hRange = hScroll.Maximum - hScroll.Minimum;
                int estimatedPos;
                if (horizontalScroll_Right)
                    estimatedPos = child.Location.X + child.Width - Width;
                else
                    estimatedPos = child.Location.X;

                hScroll.Value = (int)((float)hRange * estimatedPos / maxScrollWidth);
            }

            if (vScroll != null && Height > 0 && (verticalScroll_Top || verticalScroll_Bottom))
            {
                var vRange = vScroll.Maximum - vScroll.Minimum;
                int estimatedPos;
                if (verticalScroll_Bottom)
                {
                    estimatedPos = child.Location.Y + child.Height - Height;
                    if (hScroll != null)
                        estimatedPos += hScroll.Height;
                }
                else
                    estimatedPos = child.Location.Y;

                vScroll.Value = (int)((float)vRange * estimatedPos / maxScrollHeight);
            }
        }
        private Rectangle GetCellRectangle(int rowIndex, int columnIndex)
        {
            if (rowIndex > Rows.Count || columnIndex > ColumnCount)
                return Rectangle.Empty;
            
            var column = Columns[columnIndex];
            var row = Rows[rowIndex];
            var x = column.control.Location.X;
            var y = row.control.Location.Y;
            var width = column.Width;
            var height = row.control.Height;
            
            return new Rectangle(x, y, width, height);
        }
        private bool IsRectIsVisible(Rectangle rect)
        {
            return IsRectIsVisible(rect.X, rect.Y, rect.Width, rect.Height);
        }
        private bool IsRectIsVisible(int x, int y, int width, int height)
        {
            if (hScroll != null && hScroll.Visible)
            {
                if (x + width < hScroll.Value)
                    return false;

                if (x > hScroll.Height + hScroll.Value + hScroll.LargeChange)
                    return false;
            }

            if (vScroll != null && vScroll.Visible)
            {
                if (y + height < vScroll.Value)
                    return false;

                if (y > vScroll.Width + vScroll.Value + vScroll.LargeChange)
                    return false;
            }
            
            return true;
        }
        private void HScroll_ValueChanged(object sender, EventArgs e)
        {
            int offsetX = -(int)(maxScrollWidth * hScroll.Value / hScroll.Maximum);
            var controlsCount = Controls.Count;
            for (int i = 0; i < controlsCount; i++)
            {
                var c = Controls[i];
                if (c == null || c is ScrollBar) continue;

                c.uwfOffset = new Point(offsetX, c.uwfOffset.Y);
            }
            
            if (SkipControlsInitializations)
                TryInitializeDefferedControls();
        }
        private void MouseHookOnMouseUp(object sender, MouseEventArgs e)
        {
            for (int i = 0; i < ColumnCount; i++)
            {
                var columnButton = Columns[i].control;
                
                // Reset resize.
                columnButton.resizing = false;
                columnButton.resizeType = TableColumnButton.resizeTypes.None;
            }
        }
        private void ResetHOffset()
        {
            for (int i = 0; i < Controls.Count; i++)
            {
                var c = Controls[i];
                var co = c.uwfOffset;
                c.uwfOffset = new Point(0, co.Y);
            }
        }
        private void ResetVOffset()
        {
            for (int i = 0; i < Controls.Count; i++)
            {
                var c = Controls[i];
                var co = c.uwfOffset;
                c.uwfOffset = new Point(co.X, 0);
            }
        }
        private void VScroll_ValueChanged(object sender, EventArgs e)
        {
            int offsetY = -(int)(maxScrollHeight * vScroll.Value / vScroll.Maximum);
            var controlsCount = Controls.Count;
            for (int i = 0; i < controlsCount; i++)
            {
                var c = Controls[i];
                if (c == null || c is ScrollBar) continue;

                c.uwfOffset = new Point(c.uwfOffset.X, offsetY);
            }
            
            if (SkipControlsInitializations)
                TryInitializeDefferedControls();
        }
        private void UpdateScrolls()
        {
            // Create or dispose scrolls.
            if (Rows.Count > 0)
            {
                if (Height < maxScrollHeight)
                {
                    if (vScroll == null)
                    {
                        vScroll = new VScrollBar();
                        vScroll.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
                        vScroll.Height = Height;
                        vScroll.Location = new Point(Width - vScroll.Width, 0);
                        vScroll.ValueChanged += VScroll_ValueChanged;
                        vScroll.Visible = !vScrollHidden;
                        Controls.Add(vScroll);
                    }
                }
                else if (vScroll != null)
                {
                    vScroll.ValueChanged -= VScroll_ValueChanged;
                    vScroll.Dispose();
                    vScroll = null;
                    ResetVOffset();
                }
            }
            else if (vScroll != null)
            {
                vScroll.ValueChanged -= VScroll_ValueChanged;
                vScroll.Dispose();
                vScroll = null;
                ResetVOffset();
            }

            if (Columns.Count > 0)
            {
                if (Width < maxScrollWidth)
                {
                    if (hScroll == null)
                    {
                        hScroll = new HScrollBar();
                        hScroll.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
                        hScroll.Width = Width;
                        hScroll.Location = new Point(0, Height - hScroll.Height);
                        hScroll.ValueChanged += HScroll_ValueChanged;
                        hScroll.Visible = !hScrollHidden;
                        Controls.Add(hScroll);
                    }
                }
                else if (hScroll != null)
                {
                    hScroll.ValueChanged -= HScroll_ValueChanged;
                    hScroll.Dispose();
                    hScroll = null;
                    ResetHOffset();
                }
            }
            else if (vScroll != null)
            {
                vScroll.ValueChanged -= VScroll_ValueChanged;
                vScroll.Dispose();
                vScroll = null;
                ResetHOffset();
            }

            // Update properties.
            if (vScroll != null)
            {
                vScroll.Maximum = (int)maxScrollHeight;
                vScroll.LargeChange = vScroll.Height;
                vScroll.BringToFront();
            }
            if (hScroll != null)
            {
                if (vScroll != null)
                    hScroll.Width = Width - vScroll.Width;
                else
                    hScroll.Width = Width;

                hScroll.Maximum = (int)maxScrollWidth;
                hScroll.LargeChange = hScroll.Width;
                hScroll.BringToFront();
            }
        }

        internal class TableColumnButton : Button, IResizableControl
        {
            internal TableColumn column;
            internal ListSortDirection lastSortDirection;
            internal TableView table;

            internal resizeTypes resizeType = resizeTypes.None;
            internal bool        resizing   = false;
            
            private Control prevButton;
            private Point resizeStartMouseLocation;
            private Point resizeStartLocation;
            private int resizeStartWidth;

            public TableColumnButton(TableView t, TableButtonStyle style)
            {
                BackColor = style.BackColor;
                uwfHoverColor = style.HoverColor;
                uwfBorderColor = style.BorderColor;
                uwfBorderHoverColor = style.BorderHoverColor;
                uwfBorderSelectColor = style.BorderSelectColor;
                Padding = new Padding(8, 0, 8, 0);
                ResizeWidth = 8;
                Size = new Size(t.ColumnsDefaultWidth, 20);
                TabStop = false;
                TextAlign = ContentAlignment.MiddleLeft;
            }

            internal enum resizeTypes
            {
                None,
                Down,
                Left,
                Right,
                Up
            }

            public bool EnableHorizontalResizing { get; set; }
            public int ResizeWidth { get; set; }

            public ControlResizeTypes GetResizeAt(Point mclient)
            {
                if (EnableHorizontalResizing)
                {
                    if (mclient.X < ResizeWidth)
                        return ControlResizeTypes.Left;
                    else if (mclient.X > Width - ResizeWidth)
                        return ControlResizeTypes.Right;
                }

                return ControlResizeTypes.None;
            }

            protected override void OnMouseDown(MouseEventArgs e)
            {
                base.OnMouseDown(e);

                switch (e.Button)
                {
                    case MouseButtons.Left:
                        if (resizeType != resizeTypes.None)
                        {
                            resizing = true;
                            resizeStartMouseLocation = PointToScreen(e.Location);
                            resizeStartLocation = Location;
                            resizeStartWidth = Width;

                            // Find prev button.
                            var table = Parent as TableView;
                            var button = table.topLeftButton;
                            if (column.Index > 0)
                                button = table.Columns[column.Index - 1].control as TableColumnButton;
                            prevButton = button;
                        }
                        break;
                }
            }
            protected override void OnMouseHover(EventArgs e)
            {
                base.OnMouseHover(e);

                var mclient = PointToClient(MousePosition);
                if (EnableHorizontalResizing)
                {
                    if (mclient.X < ResizeWidth)
                        resizeType = resizeTypes.Left;
                    else if (mclient.X > Width - ResizeWidth)
                        resizeType = resizeTypes.Right;
                    else
                        resizeType = resizeTypes.None;
                }
            }
            protected override void OnMouseLeave(EventArgs e)
            {
                base.OnMouseLeave(e);

                if (resizing == false)
                    resizeType = resizeTypes.None;
            }
            protected override void OnMouseMove(MouseEventArgs e)
            {
                if (resizing)
                {
                    var dif = PointToScreen(e.Location).Subtract(resizeStartMouseLocation);
                    switch (resizeType)
                    {
                        case resizeTypes.Left:
                            if (prevButton != null)
                            {
                                var newX = resizeStartLocation.X + dif.X;
                                Location = new Point(newX, Location.Y);
                                prevButton.Width = Location.X - prevButton.Location.X - (Parent as TableView).CellPadding;
                                (Parent as TableView).AlignColumns();
                                (Parent as TableView).AlignRows();
                            }
                            break;
                        case resizeTypes.Right:
                            Width = resizeStartWidth + dif.X;
                            (Parent as TableView).AlignColumns();
                            (Parent as TableView).AlignRows();
                            break;
                    }
                }
            }
            protected override void OnMouseUp(MouseEventArgs e)
            {
                base.OnMouseUp(e);

                if (resizeType != resizeTypes.None) return;
                if (table == null) return;

                switch (e.Button)
                {
                    case MouseButtons.Left:
                        // Sort.
                        lastSortDirection = GetNextSortDirection();
                        table.Sort(column, lastSortDirection);
                        break;
                    case MouseButtons.Right:
                        // Create context menu.
                        ContextMenuStrip contextMenu = new ContextMenuStrip();

                        var itemSort = new ToolStripMenuItem("Sort");
                        contextMenu.Items.Add(itemSort);

                        var itemSortAsc = new ToolStripMenuItem("Ascending");
                        itemSortAsc.Click += (s, a) =>
                        {
                            lastSortDirection = ListSortDirection.Ascending;
                            table.Sort(column, lastSortDirection);
                        };
                        var itemSortDesc = new ToolStripMenuItem("Descending");
                        itemSortDesc.Click += (s, a) =>
                        {
                            lastSortDirection = ListSortDirection.Descending;
                            table.Sort(column, lastSortDirection);
                        };

                        itemSort.DropDownItems.Add(itemSortAsc);
                        itemSort.DropDownItems.Add(itemSortDesc);

                        contextMenu.Show(null, MousePosition);
                        break;

                }
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);

                if (table != null)
                    if (column == table.lastSortedColumn)
                    {
                        switch (lastSortDirection)
                        {
                            case ListSortDirection.Ascending:
                                e.Graphics.uwfDrawImage(uwfAppOwner.Resources.ArrowUp, Color.Gray, 8, Height / 2 - 4, 8, 8);
                                break;
                            case ListSortDirection.Descending:
                                e.Graphics.uwfDrawImage(uwfAppOwner.Resources.ArrowDown, Color.Gray, 8, Height / 2 - 4, 8, 8);
                                break;
                        }
                    }
            }

            private ListSortDirection GetNextSortDirection()
            {
                if (lastSortDirection == ListSortDirection.Ascending)
                    return ListSortDirection.Descending;
                return ListSortDirection.Ascending;
            }
        }
        internal class TableRowButton : Button
        {
            internal TableRow row;

            public TableRowButton(TableButtonStyle style)
            {
                BackColor = style.BackColor;
                uwfHoverColor = style.HoverColor;
                uwfBorderColor = style.BorderColor;
                uwfBorderHoverColor = style.BorderHoverColor;
                uwfBorderSelectColor = style.BorderSelectColor;
                Padding = new Padding(8, 0, 8, 0);
                Size = new Size(100, 20);
                TabStop = false;
                TextAlign = ContentAlignment.MiddleRight;
            }

            protected override void OnMouseClick(MouseEventArgs e)
            {
                base.OnMouseClick(e);

                var ne = new MouseEventArgs(e.Button, e.Clicks, e.X + Location.X, e.Y + Location.Y, e.Delta);

                var table = Parent as TableView;
                table.RaiseOnRowClick(row, ne);
            }
        }
    }

    public class TableRow
    {
        internal Button control;
        internal TableRowCollection rowCollection;

        public string CustomHeaderText { get; set; }
        public int Index { get { return rowCollection.FindIndex(this); } }
        public object[] Items { get; internal set; }
        public TableRowControlsCollection ItemsControls { get; internal set; }
        public int Height { get; set; }

        public object this[int column]
        {
            get { return Items[column]; }
            set { Items[column] = value; }
        }

        public TableRow(TableRowCollection owner)
        {
            rowCollection = owner;

            ItemsControls = new TableRowControlsCollection(this, 0);
            Height = 22;
        }

        internal void AddjustItemsCountTo(int n)
        {
            if (Items == null)
                Items = new object[n];
            else if (Items.Length != n)
            {
                var newItems = new object[n];
                if (Items.Length > n)
                    Array.Copy(Items, 0, newItems, 0, newItems.Length);
                else
                    Array.Copy(Items, 0, newItems, 0, Items.Length);
                Items = newItems;
            }
        }
        internal string GetHeaderText()
        {
            if (string.IsNullOrEmpty(CustomHeaderText) == false) return CustomHeaderText;
            if (control == null) return null;

            return (Index + 1).ToString();
        }
        internal void UpdateHeaderText()
        {
            if (control == null) return;
            control.Text = GetHeaderText();
        }

        public class TableRowControlsCollection
        {
            private readonly TableRow row;
            internal Control[] items;

            public delegate Control GetControl(int columnIndex, int rowIndex);
            
            /// <summary>
            /// Sets control when it's became visible.
            /// </summary>
            public GetControl CreateControlOnCellVisible { get; set; }
            public int Length { get { return items.Length; } }

            public Control this[int index]
            {
                get
                {
                    return items[index];
                }
                set
                {
                    if (items[index] != null && items[index].Disposing == false)
                        items[index].Dispose();
                    items[index] = value;
                    
                    row.rowCollection.table.Controls.Add(value);
                    row.rowCollection.table.UpdateRow(row);
                }
            }

            public TableRowControlsCollection(TableRow row, int count)
            {
                this.row = row;
                items = new Control[count];
            }
        }
    }
    public class TableRowCollection
    {
        internal TableView table;

        private readonly List<TableRow> items = new List<TableRow>();

        public TableRowCollection(TableView table)
        {
            this.table = table;
        }

        public int Count { get { return items.Count; } }

        public TableRow this[int index]
        {
            get { return items[index]; }
        }

        public virtual int Add()
        {
            TableRow row = new TableRow(this);
            row.Items = new object[table.Columns.Count];
            return Add(row);
        }
        public virtual int Add(TableRow row)
        {
            items.Add(row);
            table.UpdateRow(row);
            return items.Count - 1;
        }
        public virtual int Add(int count)
        {
            for (int i = 0; i < count; i++)
                Add();
            return items.Count - 1;
        }
        public virtual int Add(params object[] values)
        {
            TableRow row = new TableRow(this);
            row.Items = values;
            return Add(row);
        }
        public void Clear()
        {
            for (; items.Count > 0;)
                RemoveInternal(items[0]);
            
            table.UpdateRows();
        }
        public int FindIndex(TableRow row)
        {
            return items.FindIndex(x => x == row);
        }
        public int Insert(int rowIndex, params object[] values)
        {
            var row = new TableRow(this);
            row.Items = values;

            items.Insert(rowIndex, row);
            table.UpdateRow(row);
            return rowIndex;
        }
        public TableRow Last()
        {
            return items.Last();
        }
        public void Remove(TableRow row)
        {
            RemoveInternal(row);
            table.UpdateRows();
        }

        internal void ClearList()
        {
            items.Clear();
        }
        
        private void RemoveInternal(TableRow row)
        {
            if (row.control != null)
                row.control.Dispose();
            
            if (row.ItemsControls != null)
                for (int i = 0; i < row.ItemsControls.Length; i++)
                {
                    var rowIC = row.ItemsControls[i];
                    if (rowIC != null) rowIC.Dispose();
                }

            items.Remove(row);
        }
    }
    public class TableColumn
    {
        internal TableView.TableColumnButton control;
        private TableColumnCollection owner;

        public int Index { get { return owner.FindIndex(this); } }
        public string HeaderText { get; set; }
        public string Name { get; set; }
        public int Width
        {
            get
            {
                if (control != null)
                    return control.Width;
                return owner.owner.ColumnsDefaultWidth;
            }
            set
            {
                if (control != null)
                {
                    control.Width = value;
                    owner.owner.UpdateColumn(this);
                }
            }
        }

        public TableColumn(TableColumnCollection o)
        {
            owner = o;
        }
    }
    public class TableColumnCollection
    {
        private List<TableColumn> items = new List<TableColumn>();
        internal TableView owner;

        public int Count { get { return items.Count; } }

        public TableColumn this[int index]
        {
            get { return items[index]; }
        }

        public TableColumnCollection(TableView table)
        {
            owner = table;
        }

        public void Add(TableColumn column)
        {
            items.Add(column);
        }
        public void Add(string columnName, string headerText)
        {
            TableColumn column = new TableColumn(this);
            column.Name = columnName;
            column.HeaderText = headerText;
            Add(column);

            owner.UpdateColumn(column);
        }
        public void Clear()
        {
            for (; items.Count > 0;)
                RemoveInternal(items[0]);
            
            owner.UpdateColumns();
        }
        public int FindIndex(TableColumn column)
        {
            return items.FindIndex(x => x == column);
        }
        public TableColumn Last()
        {
            return items.Last();
        }
        public void Remove(TableColumn column)
        {
            RemoveInternal(column);

            owner.UpdateColumns();
        }

        private void RemoveInternal(TableColumn column)
        {
            if (column.control != null)
                column.control.Dispose();
            items.Remove(column);
        }
    }
    public class TableButtonStyle
    {
        public Color BackColor { get; set; }
        public Color BorderColor { get; set; }
        public Color BorderHoverColor { get; set; }
        public Color BorderSelectColor { get; set; }
        public Color HoverColor { get; set; }

        public TableButtonStyle()
        {
            BackColor = Color.FromArgb(252, 252, 252);
            BorderColor = Color.FromArgb(232, 241, 251);
            BorderHoverColor = Color.FromArgb(252, 253, 254);
            BorderSelectColor = BorderHoverColor;
            HoverColor = Color.FromArgb(243, 248, 254);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/LinkLabelLinkClickedEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class LinkLabelLinkClickedEventArgs : EventArgs
    {
        public LinkLabelLinkClickedEventArgs(LinkLabel.Link link)
        {
            Link = link;
            Button = MouseButtons.Left;
        }
        public LinkLabelLinkClickedEventArgs(LinkLabel.Link link, MouseButtons button) : this(link)
        {
            Button = button;
        }

        public MouseButtons Button { get; private set; }
        public LinkLabel.Link Link { get; private set; }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelCheckBox.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelCheckBox : BaseExamplePanel
    {
        public override void Initialize()
        {
            this.Create<Label>("Normal:");
            this.Create<CheckBox>("Text");
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/Control.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    public class Control : Component, IDropTarget
    {
        internal static readonly Color defaultShadowColor = Color.FromArgb(12, 0, 0, 0);
        internal static readonly Color defaultForeColor = SystemColors.uwfControlText;
        internal static Control lastSelected;

        internal bool selected;
        internal bool hovered;
        internal bool mouseEntered;
        internal bool shouldFocus;

        internal Application uwfAppOwner;
        internal bool uwfAutoGroup; // Used by GUI.BeginGroup & GUI.EndGroup. Allows to paint controls using their relevant position Rect(0, 0, Width, Height).
        internal bool uwfCanDrawTabDots = true; // Means that Control will draw dots on Tab focus if possible.
        internal bool uwfDrawTabDots; // If 'Tab' key was pressed on any form, Control should be marked to draw dots. Work in progress.
        internal readonly Pen uwfTabPen = new Pen(Color.Black) { DashStyle = DashStyle.Dot };
        internal bool uwfShadowBox;
        internal DrawHandler uwfShadowHandler;
        internal Point uwfOffset; // Position for scrolling. Affects rendering.
        internal bool uwfSystem; // Indicates that Control can be handled by OS (like scrollbars).
        
        private AnchorStyles anchor = AnchorStyles.Top | AnchorStyles.Left;
        private Color backColor = SystemColors.Control;
        private int clientHeight;
        private int clientWidth;
        private ControlCollection controls;
        private ControlStyles controlStyle;
        private CreateParams createParams;
        private bool enabled;
        private Font font = SystemFonts.uwfArial_12;
        private Color foreColor = defaultForeColor;
        private int height;
        private bool fuwfContext;
        private Control parent;
        private string text;
        private bool visible;
        private int width;
        private int x, y;

        public Control()
        {
            if (parent != null && parent.uwfAppOwner != null)
                parent.uwfAppOwner.Run(this);
            else if (uwfDefaultController != null)
                uwfDefaultController.Run(this);

            uwfAutoGroup = true;

            Enabled = true;
            Padding = DefaultPadding;
            TabIndex = -1;
            TabStop = true;
            Visible = true;

            SetStyle(
                ControlStyles.UserPaint |
                ControlStyles.StandardClick | ControlStyles.Selectable | ControlStyles.StandardDoubleClick |
                ControlStyles.AllPaintingInWmPaint | ControlStyles.UseTextForAccessibility,
                true);

            var defaultSize = DefaultSize;
            width = defaultSize.Width;
            height = defaultSize.Height;
            clientWidth = width;
            clientHeight = height;
        }

        public delegate void DrawHandler(PaintEventArgs e);
        public delegate void ResizeHandler(Point delta);

        public event EventHandler AutoSizeChanged;
        public event EventHandler BackColorChanged;
        public event EventHandler Click;
        public event EventHandler ClientSizeChanged;
        public event ControlEventHandler ControlAdded;
        public event ControlEventHandler ControlRemoved;
        public event EventHandler DoubleClick;
        public event DragEventHandler DragDrop;
        public event DragEventHandler DragEnter;
        public event EventHandler DragLeave;
        public event EventHandler EnabledChanged;
        public event EventHandler ForeColorChanged;
        public event EventHandler GotFocus;
        public event KeyEventHandler KeyDown;
        public event KeyPressEventHandler KeyPress;
        public event KeyEventHandler KeyUp;
        public event LayoutEventHandler Layout;
        public event EventHandler LocationChanged;
        public event EventHandler LostFocus;
        public event MouseEventHandler MouseClick;
        public event MouseEventHandler MouseDoubleClick;
        public event MouseEventHandler MouseDown;
        public event EventHandler MouseEnter;
        public event EventHandler MouseHover;
        public event EventHandler MouseLeave;
        public event MouseEventHandler MouseMove;
        public event MouseEventHandler MouseUp;
        public event EventHandler ParentChanged;
        public event EventHandler Resize;
        public event EventHandler SizeChanged;
        public event EventHandler TextChanged;
        public event EventHandler VisibleChanged;

        public static Color DefaultBackColor
        {
            get { return SystemColors.Control; }
        }
        public static Point MousePosition
        {
            get { return ApiHolder.System.MousePosition; }
        }

        public virtual bool AllowDrop { get; set; }
        public bool AlwaysFocused { get; set; }
        public virtual AnchorStyles Anchor
        {
            get { return anchor; }
            set { anchor = value; }
        }
        public virtual bool AutoSize { get; set; }
        public virtual Color BackColor
        {
            get { return backColor; }
            set
            {
                if (backColor == value)
                    return;
                
                backColor = value;
                OnBackColorChanged(EventArgs.Empty);
            }
        }
        public virtual Image BackgroundImage { get; set; }
        public virtual ImageLayout BackgroundImageLayout { get; set; }
        public Rectangle Bounds
        {
            get { return new Rectangle(Location.X, Location.Y, Width, Height); }
            set
            {
                Location = new Point(value.X, value.Y);
                Size = new Size(value.Width, value.Height);
            }
        }
        public bool CanSelect
        {
            get { return CanSelectCore(); }
        }
        public Rectangle ClientRectangle { get { return new Rectangle(0, 0, clientWidth, clientHeight); } }
        public Size ClientSize
        {
            get { return new Size(clientWidth, clientHeight); }
            set { Size = value; }
        }
        public ControlCollection Controls
        {
            get
            {
                if (controls == null)
                    controls = CreateControlsInstance();

                return controls;
            }
        }
        public virtual Rectangle DisplayRectangle { get { return ClientRectangle; } }
        public bool Disposing { get; private set; }
        public bool Enabled
        {
            get { return enabled; }
            set
            {
                if (enabled == value)
                    return;

                enabled = value;

                OnEnabledChanged(EventArgs.Empty);
            }
        }
        public bool Focused { get { return selected; } }
        public virtual Font Font
        {
            get { return font; }
            set { font = value; }
        }
        public virtual Color ForeColor
        {
            get { return foreColor; }
            set
            {
                if (foreColor == value)
                    return;
                
                foreColor = value;
                OnForeColorChanged(EventArgs.Empty);
            }
        }
        public int Height
        {
            get { return height; }
            set { SetBounds(x, y, width, value, BoundsSpecified.Height); }
        }
        public bool IsDisposed { get; private set; }
        public int Left
        {
            get { return Location.X; }
            set { Location = new Point(value, Location.Y); }
        }
        public Point Location
        {
            get { return new Point(x, y); }
            set { SetBounds(value.X, value.Y, width, height, BoundsSpecified.Location); }
        }
        public virtual Size MaximumSize { get; set; }
        public virtual Size MinimumSize { get; set; }
        public string Name { get; set; }
        public Padding Padding { get; set; }
        public Control Parent
        {
            get { return parent; }
            set
            {
                if (parent == value)
                    return;

                if (value != null)
                    value.Controls.Add(this);
                else
                    parent.Controls.Remove(this);
            }
        }
        public Size Size
        {
            get { return new Size(Width, Height); }
            set { SetBounds(x, y, value.Width, value.Height, BoundsSpecified.Size); }
        }
        public int TabIndex { get; set; }
        public bool TabStop { get; set; }
        public object Tag { get; set; }
        public virtual string Text
        {
            get { return text; }
            set
            {
                if (text == value)
                    return;

                text = value;
                OnTextChanged(EventArgs.Empty);
            }
        }
        public int Top
        {
            get { return Location.Y; }
            set { Location = new Point(Location.X, value); }
        }
        public bool Visible
        {
            get { return visible; }
            set { SetVisibleCore(value); }
        }
        public int Width
        {
            get { return width; }
            set { SetBounds(x, y, value, height, BoundsSpecified.Width); }
        }

        internal static Application uwfDefaultController { get; set; }
        internal virtual bool uwfContext // Close on click control.
        {
            get { return fuwfContext; }
            set
            {
                if (fuwfContext == value) return;
                
                fuwfContext = value;
                
                if (fuwfContext)
                    uwfAppOwner.Contexts.Add(this);
                else
                    uwfAppOwner.Contexts.Remove(this);
            }
        }
        internal bool uwfHovered { get { return hovered; } }

        protected virtual CreateParams CreateParams
        {
            get
            {
                if (createParams == null)
                    createParams = new CreateParams();

                createParams.Caption = text;
                createParams.X = x;
                createParams.Y = y;
                createParams.Width = width;
                createParams.Height = height;

                return createParams;
            }
        }
        protected virtual Size DefaultSize
        {
            get { return Size.Empty; }
        }
        protected virtual Padding DefaultPadding
        {
            get { return Padding.Empty; }
        }

        public void BringToFront()
        {
            if (AlwaysFocused) return;

            if (parent != null && 
                parent.controls.Count > 0 && 
                parent.controls[parent.controls.Count - 1] != this)
            {
                var parentControls = parent.controls;
                parentControls.Remove(this);
                parentControls.Add(this);
            }

            var form = this as Form ?? Application.GetRootControl(this) as Form;
            if (form != null)
            {
                Form.ActiveForm = form;
                
                var forms = uwfAppOwner.Forms;
                if (forms.Contains(form))
                {
                    if (forms.Remove(form))
                        forms.Add(form);
                }
                else if (form.IsModal)
                {
                    var modalForms = uwfAppOwner.ModalForms;
                    if (modalForms.Remove(form))
                        modalForms.Add(form);
                }
            }
        }
        public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects)
        {
            Application.DoDragDrop(data, allowedEffects);
            return allowedEffects; // TODO: ?
        }
        public bool Focus()
        {
            return FocusInternal();
        }
        public void Hide()
        {
            Visible = false;
        }
        public virtual void Invalidate()
        {
        }
        public virtual void Invalidate(Rectangle rc)
        {
        }
        public virtual void Invalidate(Rectangle rc, bool invalidateChildren)
        {
        }
        public void PerformLayout()
        {
            OnLayout(null);
        }
        public Point PointToClient(Point p)
        {
            if (parent != null)
                p = parent.PointToClient(p);

            var localuwfOffset = uwfOffset;

            p.Offset(-x - localuwfOffset.X, -y - localuwfOffset.Y);
            return p;
        }
        public Point PointToScreen(Point p)
        {
            if (parent != null)
                p = parent.PointToScreen(p);

            var localuwfOffset = uwfOffset;

            p.Offset(x + localuwfOffset.X, y + localuwfOffset.Y);
            return p;
        }
        public virtual void Refresh()
        {
        }
        public void ResumeLayout()
        {
        }
        public void ResumeLayout(bool performLayout)
        {
        }
        public void Select()
        {
            if (CanSelect == false || lastSelected == this) return;

            if (lastSelected != null && lastSelected.AlwaysFocused == false)
            {
                lastSelected.selected = false;
                lastSelected.InvokeLostFocus(lastSelected, EventArgs.Empty);
            }

            selected = true;
            lastSelected = this;
        }
        public void SendToBack()
        {
            if (parent != null)
                parent.Controls.SetChildIndex(this, 0);
        }
        public void SetBounds(int argX, int argY, int argWidth, int argHeight)
        {
            if (x != argX || y != argY || (width != argWidth || height != argHeight))
                SetBoundsCore(argX, argY, argWidth, argHeight, BoundsSpecified.All);
        }
        public void SetBounds(int argX, int argY, int argWidth, int argHeight, BoundsSpecified specified)
        {
            if ((specified & BoundsSpecified.X) == BoundsSpecified.None)
                argX = x;
            if ((specified & BoundsSpecified.Y) == BoundsSpecified.None)
                argY = y;
            if ((specified & BoundsSpecified.Width) == BoundsSpecified.None)
                argWidth = width;
            if ((specified & BoundsSpecified.Height) == BoundsSpecified.None)
                argHeight = height;
            if (x != argX || y != argY || (width != argWidth || height != argHeight))
                SetBoundsCore(argX, argY, argWidth, argHeight, specified);
        }
        public void Show()
        {
            Visible = true;
        }
        public void SuspendLayout()
        {
            // dunno.
        }

        void IDropTarget.OnDragEnter(DragEventArgs e)
        {
            OnDragEnter(e);
        }
        void IDropTarget.OnDragDrop(DragEventArgs e)
        {
            OnDragDrop(e);
        }
        void IDropTarget.OnDragLeave(EventArgs e)
        {
            OnDragLeave(e);
        }
        void IDropTarget.OnDragOver(DragEventArgs e)
        {
            OnDragOver(e);
        }

        internal virtual void AssignParent(Control value)
        {
            parent = value;
            OnParentChanged(EventArgs.Empty);
        }
        internal virtual bool CanSelectCore()
        {
            if ((controlStyle & ControlStyles.Selectable) != ControlStyles.Selectable)
                return false;
            for (Control control = this; control != null; control = control.parent)
            {
                if (!control.Enabled || !control.Visible)
                    return false;
            }
            return true;
        }
        internal DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects, DragDropRenderHandler render)
        {
            Application.DoDragDrop(data, allowedEffects, render);
            return allowedEffects; // TODO: ?
        }
        internal Form FindFormInternal()
        {
            Control cur = this;
            while (cur != null && !(cur is Form))
                cur = cur.parent;

            return (Form)cur;
        }
        internal virtual bool FocusInternal()
        {
            Select();

            var form = this as Form ?? Application.GetRootControl(this) as Form;
            if (form != null) form.BringToFront();

            shouldFocus = true;

            OnGotFocus(EventArgs.Empty);
            return true; // TODO: CanFocus.
        }
        internal void PaintBackground(PaintEventArgs e, Rectangle rectangle)
        {
            PaintBackground(e, rectangle, this.BackColor, Point.Empty);
        }
        internal void PaintBackground(PaintEventArgs e, Rectangle rectangle, Color backColor, Point scrollOffset)
        {
            var bImage = BackgroundImage;
            if (bImage != null) // Fill back & draw image.
                ControlPaint.DrawBackgroundImage(e.Graphics, bImage, backColor, BackgroundImageLayout, ClientRectangle, rectangle);
            else if (backColor.A > 0) // Fill back.
                PaintBackColor(e, rectangle, backColor);
        }
        internal void PerformLayout(Control affectedControl, string affectedProperty)
        {
            OnLayout(new LayoutEventArgs(affectedControl, affectedProperty));
        }
        internal virtual void RaiseOnDragDrop(DragEventArgs drgevent)
        {
            OnDragDrop(drgevent);
        }
        internal virtual void RaiseOnDragEnter(DragEventArgs drgevent)
        {
            OnDragEnter(drgevent);
        }
        internal virtual void RaiseOnDragLeave(EventArgs e)
        {
            OnDragLeave(e);
        }
        internal virtual void RaiseOnLostFocus(EventArgs e)
        {
            OnLostFocus(e);
        }
        internal virtual void RaiseOnMouseClick(MouseEventArgs e)
        {
            OnMouseClick(e);
            OnClick(e);
        }
        internal virtual void RaiseOnMouseDoubleClick(MouseEventArgs e)
        {
            OnMouseDoubleClick(e);
            OnDoubleClick(e);
        }
        internal virtual void RaiseOnMouseDown(MouseEventArgs e)
        {
            OnMouseDown(e);
        }
        internal virtual void RaiseOnMouseEnter(EventArgs e)
        {
            OnMouseEnter(e);
        }
        internal virtual void RaiseOnMouseHover(EventArgs e)
        {
            OnMouseHover(e);
        }
        internal virtual void RaiseOnMouseLeave(EventArgs e)
        {
            OnMouseLeave(e);
        }
        internal virtual void RaiseOnMouseMove(MouseEventArgs e)
        {
            OnMouseMove(e);
        }
        internal virtual void RaiseOnMouseUp(MouseEventArgs e)
        {
            OnMouseUp(e);
        }
        internal virtual void RaiseOnMouseWheel(MouseEventArgs e)
        {
            OnMouseWheel(e);
        }
        internal virtual void RaiseOnKeyDown(KeyEventArgs e)
        {
            OnKeyDown(e);
        }
        internal virtual void RaiseOnKeyPress(KeyPressEventArgs e)
        {
            OnKeyPress(e);
        }
        internal virtual void RaiseOnKeyUp(KeyEventArgs e)
        {
            OnKeyUp(e);
        }
        internal virtual void RaiseOnPaint(PaintEventArgs e)
        {
            if (uwfShadowBox)
            {
                if (uwfShadowHandler == null)
                    PaintShadow(e, this);
                else
                    uwfShadowHandler(e);
            }

            if (uwfAutoGroup)
                e.Graphics.GroupBegin(this);

            OnPaintBackground(e);
            OnPaint(e);

            if (controls != null)
            {
                for (int i = 0; i < controls.Count; i++)
                {
                    var childControl = controls[i];
                    if (Application.ControlIsVisible(childControl) == false) continue;

                    var currentAbspos = childControl.PointToScreen(Point.Empty);
                    var currentAbsposX = currentAbspos.X;
                    var currentAbsposY = currentAbspos.Y;

                    if (currentAbsposX + childControl.width < 0 ||
                        currentAbsposX > Screen.width ||
                        currentAbsposY + childControl.height < 0 ||
                        currentAbsposY > Screen.height)
                        continue;

                    childControl.RaiseOnPaint(e);
                }
            }

            uwfOnLatePaint(e);

            if (uwfAutoGroup)
                e.Graphics.GroupEnd();
        }
        internal virtual Size SizeFromClientSize(int argWidth, int argHeight)
        {
            return new Size(argWidth, argHeight);
        }
        internal virtual void uwfAdjustSizeToScreen(Size delta)
        {
            ParentResized(new Point(delta.Width, delta.Height));
        }

        protected internal virtual void uwfChildGotFocus(Control child)
        {
            if (parent == null) return;

            parent.uwfChildGotFocus(child);
        }
        protected internal virtual void uwfOnLatePaint(PaintEventArgs e)
        {
        }
        protected internal virtual Point uwfShadowPointToScreen(Point p)
        {
            // See Form.
            if (parent != null)
                p = parent.uwfShadowPointToScreen(p);

            var localuwfOffset = uwfOffset;

            p.Offset(x + localuwfOffset.X, y + localuwfOffset.Y);
            return p;
        }

        protected virtual ControlCollection CreateControlsInstance()
        {
            return new ControlCollection(this);
        }
        protected override void Dispose(bool release_all)
        {
            if (IsDisposed) return;

            Disposing = true;

            if (release_all && !Controls.IsReadOnly)
            {
                var tempControls = new Control[Controls.Count];
                
                Controls.CopyTo(tempControls, 0);

                foreach (var control in tempControls) 
                    control.Dispose();
                
                Controls.Clear();
            }

            if (parent != null)
            {
                int self = parent.Controls.FindIndex(control => control == this);
                if (self > -1)
                    parent.Controls.RemoveAt(self);
            }

            if (uwfContext)
                uwfAppOwner.Contexts.Remove(this);

            IsDisposed = true;

            base.Dispose(release_all);
        }
        protected void InvokeGotFocus(Control toInvoke, EventArgs e)
        {
            if (toInvoke == null) return;
            toInvoke.OnGotFocus(e);
        }
        protected void InvokeLostFocus(Control toInvoke, EventArgs e)
        {
            if (toInvoke == null)
                return;
            toInvoke.OnLostFocus(e);
        }
        protected virtual void OnAutoSizeChanged(EventArgs e)
        {
            var autoSizeChanged = AutoSizeChanged;
            if (autoSizeChanged != null)
                autoSizeChanged(this, e);
        }
        protected virtual void OnBackColorChanged(EventArgs e)
        {
            var handler = BackColorChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnClick(EventArgs e)
        {
            var click = Click;
            if (click != null)
                click(this, e);
        }
        protected virtual void OnClientSizeChanged(EventArgs e)
        {
            var clientSizeChanged = ClientSizeChanged;
            if (clientSizeChanged != null)
                clientSizeChanged(this, e);
        }
        protected virtual void OnControlAdded(ControlEventArgs e)
        {
            var handler = ControlAdded;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnControlRemoved(ControlEventArgs e)
        {
            var handler = ControlRemoved;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnDoubleClick(EventArgs e)
        {
            var doubleClick = DoubleClick;
            if (doubleClick != null)
                doubleClick(this, e);
        }
        protected virtual void OnDragDrop(DragEventArgs drgevent)
        {
            var dragDrop = DragDrop;
            if (dragDrop != null)
                dragDrop(this, drgevent);
        }
        protected virtual void OnDragEnter(DragEventArgs drgevent)
        {
            var dragEnter = DragEnter;
            if (dragEnter != null)
                dragEnter(this, drgevent);
        }
        protected virtual void OnDragLeave(EventArgs e)
        {
            var dragLeave = DragLeave;
            if (dragLeave != null)
                dragLeave(this, e);
        }
        protected virtual void OnDragOver(DragEventArgs drgevent)
        {
            throw new NotImplementedException();
        }
        protected virtual void OnEnabledChanged(EventArgs e)
        {
            var handler = EnabledChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnForeColorChanged(EventArgs e)
        {
            var handler = ForeColorChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnGotFocus(EventArgs e)
        {
            if (parent != null)
                parent.uwfChildGotFocus(this);

            var gotFocus = GotFocus;
            if (gotFocus != null)
                gotFocus(this, e);
        }
        protected virtual void OnKeyDown(KeyEventArgs e)
        {
            var keyDown = KeyDown;
            if (keyDown != null)
                keyDown(this, e);
        }
        protected virtual void OnKeyPress(KeyPressEventArgs e)
        {
            var keyPress = KeyPress;
            if (keyPress != null)
                keyPress(this, e);
        }
        protected virtual void OnKeyUp(KeyEventArgs e)
        {
            var keyUp = KeyUp;
            if (keyUp != null)
                keyUp(this, e);
        }
        protected virtual void OnLayout(LayoutEventArgs e)
        {
            var handler = Layout;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnLocationChanged(EventArgs e)
        {
            var locationChanged = LocationChanged;
            if (locationChanged != null)
                locationChanged(this, EventArgs.Empty);
            
            var scrollableParent = parent as ScrollableControl;
            if (scrollableParent != null)
                scrollableParent.UpdateScrolls();
        }
        protected virtual void OnLostFocus(EventArgs e)
        {
            var lostFocus = LostFocus;
            if (lostFocus != null)
                lostFocus(this, e);
        }
        protected virtual void OnMouseClick(MouseEventArgs e)
        {
            var mouseClick = MouseClick;
            if (mouseClick != null)
                mouseClick(this, e);
        }
        protected virtual void OnMouseDoubleClick(MouseEventArgs e)
        {
            var mouseDoubleClick = MouseDoubleClick;
            if (mouseDoubleClick != null)
                mouseDoubleClick(this, e);
        }
        protected virtual void OnMouseDown(MouseEventArgs e)
        {
            Focus();

            var mouseDown = MouseDown;
            if (mouseDown != null)
                mouseDown(this, e);
        }
        protected virtual void OnMouseEnter(EventArgs e)
        {
            var mouseEnter = MouseEnter;
            if (mouseEnter != null)
                mouseEnter(this, e);

            if (Enabled)
                hovered = true;
        }
        protected virtual void OnMouseHover(EventArgs e)
        {
            var mouseHover = MouseHover;
            if (mouseHover != null)
                mouseHover(this, e);
        }
        protected virtual void OnMouseLeave(EventArgs e)
        {
            var mouseLeave = MouseLeave;
            if (mouseLeave != null)
                mouseLeave(this, e);

            hovered = false;
        }
        protected virtual void OnMouseMove(MouseEventArgs e)
        {
            var handler = MouseMove;
            if (handler != null) handler(this, e);
        }
        protected virtual void OnMouseUp(MouseEventArgs e)
        {
            var mouseUp = MouseUp;
            if (mouseUp != null)
                mouseUp(this, e);
        }
        protected virtual void OnMouseWheel(MouseEventArgs e)
        {
            // TODO: should I raise in parent?
            // remove base call if you have stack overflow.
            if (parent != null)
                parent.RaiseOnMouseWheel(e);
        }
        protected virtual void OnPaint(PaintEventArgs e)
        {
        }
        protected virtual void OnPaintBackground(PaintEventArgs e)
        {
            PaintBackground(e, ClientRectangle);
        }
        protected virtual void OnParentChanged(EventArgs e)
        {
            var handler = ParentChanged;
            if (handler != null)
                handler(this, e);
        }
        protected virtual void OnResize(EventArgs e)
        {
            var resize = Resize;
            if (resize != null)
                resize(this, e);

            PerformLayout();
        }
        protected virtual void OnSizeChanged(EventArgs e)
        {
            OnResize(EventArgs.Empty);

            var scrollableParent = parent as ScrollableControl;
            if (scrollableParent != null)
                scrollableParent.UpdateScrolls();

            var sizeChanged = SizeChanged;
            if (sizeChanged != null)
                sizeChanged(this, e);
        }
        protected virtual void OnTextChanged(EventArgs e)
        {
            var textChanged = TextChanged;
            if (textChanged != null)
                textChanged(this, e);
        }
        protected virtual void OnVisibleChanged(EventArgs e)
        {
            var visibleChanged = VisibleChanged;
            if (visibleChanged != null)
                visibleChanged(this, e);
        }
        protected virtual void SetBoundsCore(int argX, int argY, int argWidth, int argHeight, BoundsSpecified specified)
        {
            // Maximum size.
            if (MaximumSize.Width > 0 && argWidth > MaximumSize.Width)
                argWidth = MaximumSize.Width;

            if (MaximumSize.Height > 0 && argHeight > MaximumSize.Height)
                argHeight = MaximumSize.Height;

            // Minimum size.
            if (MinimumSize.Width > 0 && argWidth < MinimumSize.Width)
                argWidth = MinimumSize.Width;

            if (MinimumSize.Height > 0 && argHeight < MinimumSize.Height)
                argHeight = MinimumSize.Height;
            
            if (x == argX && y == argY && width == argWidth && height == argHeight)
                return;

            if (parent != null)
                parent.SuspendLayout();

            UpdateBounds(argX, argY, argWidth, argHeight);

            if (parent != null)
                parent.ResumeLayout(true);
        }
        protected virtual void SetClientSizeCore(int argX, int argY)
        {
            Size = SizeFromClientSize(argX, argY);
            clientWidth = argX;
            clientHeight = argY;
            OnClientSizeChanged(EventArgs.Empty);
        }
        protected void SetStyle(ControlStyles flag, bool value)
        {
            controlStyle = value ? controlStyle | flag : controlStyle & ~flag;
        }
        protected virtual void SetVisibleCore(bool value)
        {
            if (visible == value)
                return;

            visible = value;
            OnVisibleChanged(EventArgs.Empty);
        }
        protected virtual Size SizeFromClientSize(Size clientSize)
        {
            return SizeFromClientSize(clientSize.Width, clientSize.Height);
        }
        protected void UpdateBounds(int argX, int argY, int argWidth, int argHeight)
        {
            int cWidth = argWidth;
            int cHeight = argHeight;
            
            UpdateBounds(argX, argY, argWidth, argHeight, cWidth, cHeight);
        }
        protected void UpdateBounds(int argX, int argY, int argWidth, int argHeight, int argClientWidth, int argClientHeight)
        {
            int widthBuffer = width;
            int heightBuffer = height;

            bool locationFlag = x != argX || y != argY;
            bool sizeFlag = Width != argWidth || Height != argHeight || clientWidth != argClientWidth || clientHeight != argClientHeight;

            x = argX;
            y = argY;
            width = argWidth;
            height = argHeight;
            clientWidth = argClientWidth;
            clientHeight = argClientHeight;

            if (locationFlag)
                OnLocationChanged(EventArgs.Empty);
            if (!sizeFlag)
                return;

            var delta = new Point(widthBuffer - argWidth, heightBuffer - argHeight);
            ResizeChilds(delta);

            OnSizeChanged(EventArgs.Empty);
            OnClientSizeChanged(EventArgs.Empty);

            PerformLayout();
        }

        private static void PaintBackColor(PaintEventArgs e, Rectangle rectangle, Color backColor)
        {
            e.Graphics.uwfFillRectangle(backColor, rectangle);
        }
        private static void PaintShadow(PaintEventArgs pArgs, Control c)
        {
            var psLoc = c.uwfShadowPointToScreen(Point.Empty);
            int shX = psLoc.X + 6;
            int shY = psLoc.Y + 6;
            var shadowColor = defaultShadowColor;
            var localWidth = c.Width;
            var localHeight = c.Height;
            var graphics = pArgs.Graphics;
            graphics.uwfFillRectangle(shadowColor, shX + 6, shY + 6, localWidth - 12, localHeight - 12);
            graphics.uwfFillRectangle(shadowColor, shX + 5, shY + 5, localWidth - 10, localHeight - 10);
            graphics.uwfFillRectangle(shadowColor, shX + 4, shY + 4, localWidth - 8, localHeight - 8);
            graphics.uwfFillRectangle(shadowColor, shX + 3, shY + 3, localWidth - 6, localHeight - 6);
            graphics.uwfFillRectangle(shadowColor, shX + 2, shY + 2, localWidth - 4, localHeight - 4);
        }

        private void ParentResized(Point delta)
        {
            if (Anchor == AnchorStyles.None) return;

            bool an_right = (Anchor & AnchorStyles.Right) == AnchorStyles.Right;
            bool an_bottom = (Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom;
            bool an_left = (Anchor & AnchorStyles.Left) == AnchorStyles.Left;
            bool an_top = (Anchor & AnchorStyles.Top) == AnchorStyles.Top;

            int nextX = x;
            int nextY = y;
            int nextWidth = width;
            int nextHeight = height;

            if (an_right)
                nextX -= delta.X;
            else
                delta = new Point(0, delta.Y);

            if (an_bottom)
                nextY -= delta.Y;
            else
                delta = new Point(delta.X, 0);

            if (an_left)
            {
                if (an_right)
                {
                    nextX += delta.X;
                    nextWidth -= delta.X;
                }
            }
            if (an_top)
            {
                if (an_bottom)
                {
                    nextY += delta.Y;
                    nextHeight -= delta.Y;
                }
            }

            UpdateBounds(nextX, nextY, nextWidth, nextHeight);
        }
        private void ResizeChilds(Point delta)
        {
            if (delta == Point.Empty) return;
            if (Controls == null) return;

            for (int i = 0; i < Controls.Count; i++)
                Controls[i].ParentResized(delta);
        }

        public class ControlCollection : IList, ICloneable
        {
            private readonly List<Control> items = new List<Control>();
            private readonly Control owner;

            private int lastAccessedIndex = -1;
            private object syncRoot;

            public ControlCollection(Control owner)
            {
                this.owner = owner;
            }

            public Control Current
            {
                get { return items.GetEnumerator().Current; }
            }
            public int Count { get { return items.Count; } }
            public Control Owner { get { return owner; } }
            bool IList.IsFixedSize
            {
                get
                {
                    return false;
                }
            }
            public virtual bool IsReadOnly { get { return false; } }
            bool IList.IsReadOnly
            {
                get
                {
                    return IsReadOnly;
                }
            }
            bool ICollection.IsSynchronized
            {
                get
                {
                    return false;
                }
            }
            object ICollection.SyncRoot
            {
                get
                {
                    if (syncRoot == null)
                        syncRoot = new object();

                    return syncRoot;
                }
            }

            object IList.this[int index]
            {
                get
                {
                    return items[index];
                }
                set
                {
                    if (value is Control)
                        items[index] = (Control)value;
                }
            }
            public virtual Control this[int index] { get { return items[index]; } }

            IEnumerator IEnumerable.GetEnumerator()
            {
                return items.GetEnumerator();
            }
            public virtual void Add(Control value)
            {
                if (value == null)
                    return;

                items.Add(value);
                value.AssignParent(owner);

                owner.PerformLayout();
                owner.OnControlAdded(new ControlEventArgs(value));
            }
            public virtual void AddRange(Control[] controls)
            {
                foreach (var c in controls)
                    Add(c);
            }
            public virtual void Clear()
            {
                var tItems = new List<Control>(items);
                
                items.Clear();
            
                owner.PerformLayout();
                
                for (int i = 0; i < tItems.Count; i++)
                    owner.OnControlRemoved(new ControlEventArgs(tItems[i]));
            }
            public bool Contains(Control control)
            {
                return items.Contains(control);
            }
            public void CopyTo(Array array, int index)
            {
                var controls = array as Control[];
                if (controls != null)
                    items.CopyTo(controls, index);
            }
            public Control Find(Predicate<Control> match)
            {
                return items.Find(match);
            }
            public List<Control> FindAll(Predicate<Control> match)
            {
                return items.FindAll(match);
            }
            public int FindIndex(Predicate<Control> match)
            {
                return items.FindIndex(match);
            }
            public int GetChildIndex(Control child)
            {
                return GetChildIndex(child, true);
            }
            public virtual int GetChildIndex(Control child, bool throwException)
            {
                var index = IndexOf(child);
                if (index == -1 && throwException)
                    throw new ArgumentException("child");
                return index;
            }
            public IEnumerator<Control> GetEnumerator()
            {
                return items.GetEnumerator();
            }
            public int IndexOf(Control control)
            {
                return items.IndexOf(control);
            }
            public virtual int IndexOfKey(string key)
            {
                if (string.IsNullOrEmpty(key))
                    return -1;

                if (IsValidIndex(lastAccessedIndex))
                    if (WindowsFormsUtils.SafeCompareStrings(this[lastAccessedIndex].Name, key, true))
                        return lastAccessedIndex;

                for (int i = 0; i < Count; i++)
                {
                    if (!WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, true)) continue;

                    lastAccessedIndex = i;
                    return i;
                }

                lastAccessedIndex = -1;
                return -1;
            }
            public void Insert(int index, Control value)
            {
                items.Insert(index, value);

                owner.PerformLayout();
                owner.OnControlAdded(new ControlEventArgs(value));
            }
            public virtual void Remove(Control item)
            {
                if (item == null)
                    return;

                items.Remove(item);
                owner.PerformLayout();
                owner.OnControlRemoved(new ControlEventArgs(item));
            }
            public void RemoveAt(int index)
            {
                Remove(this[index]);
            }
            public virtual void RemoveByKey(string key)
            {
                int index = IndexOfKey(key);
                if (IsValidIndex(index))
                    RemoveAt(index);
            }
            public void Reset()
            {
            }
            public virtual void SetChildIndex(Control child, int newIndex)
            {
                SetChildIndexInternal(child, newIndex);
            }

            internal virtual void SetChildIndexInternal(Control child, int newIndex)
            {
                if (child == null)
                    throw new ArgumentNullException("child");

                items.Remove(child);
                items.Insert(newIndex, child);
            }

            int IList.Add(object value)
            {
                var control = value as Control;
                if (control != null)
                {
                    Add(control);
                    return items.Count - 1;
                }
                return -1;
            }
            bool IList.Contains(object value)
            {
                var control = value as Control;
                if (control != null)
                    return items.Contains(control);
                return false;
            }
            int IList.IndexOf(object value)
            {
                var control = value as Control;
                if (control != null)
                    return items.IndexOf(control);
                return -1;
            }
            void IList.Insert(int index, object value)
            {
                var control = value as Control;
                if (control != null)
                    items.Insert(index, control);
            }
            void IList.Remove(object value)
            {
                var control = value as Control;
                if (control != null)
                    items.Remove(control);
            }
            object ICloneable.Clone()
            {
                var cc = new ControlCollection(owner);

                cc.items.AddRange(items);
                return cc;
            }

            private bool IsValidIndex(int index)
            {
                return index >= 0 && index < Count;
            }
        }
    }
}

<|start_filename|>Assets/Controls/Highcharts/SeriesAreaSolidOutline.cs<|end_filename|>
namespace Highcharts
{
    using System.Drawing;
    
    public class SeriesAreaSolidOutline : Series
    {
        public SeriesAreaSolidOutline() : this("")
        { }
        
        public SeriesAreaSolidOutline(string name) : base(name)
        { }
        
        protected override void OnPaint(Graphics g, Rectangle clipRectangle)
        {
            if (data.Count == 1)
            {
                SeriesPaint.PaintPoint(this, g, clipRectangle, 0);
                return;
            }
            
            var valueRange = GetValueRange();
            var xStep = GetXStep();
            var areaColorAlpha = collection.GetColorAlpha();
            var areaColor = Color.FromArgb(areaColorAlpha, color);
            
            var prevValue = data[0];
            var prevValueX = GetXFromIndex(0, xStep, clipRectangle);
            var prevValueY = GetYFromValue(prevValue, valueRange, clipRectangle);
           
            for (float dataIterator = pointInterval; dataIterator < data.Count; dataIterator += pointInterval)
            {
                double currentValue = data[(int) dataIterator];

                float currentValueX = GetXFromIndex(dataIterator, xStep, clipRectangle);
                float currentValueY = GetYFromValue(currentValue, valueRange, clipRectangle);

                float width = currentValueX - prevValueX;
                bool last = dataIterator + pointInterval >= data.Count;

                if (!collection.chart.plotOptions.linearGradient)
                {
                    g.uwfFillRectangle(areaColor, prevValueX, prevValueY, currentValueX - prevValueX, clipRectangle.Bottom - prevValueY);

                    if (last)
                        g.uwfFillRectangle(areaColor, currentValueX, currentValueY, xStep, clipRectangle.Bottom - currentValueY);
                }
                else if (collection.chart.plotOptions.linearGradientMaterial != null)
                {
                    float clipH = clipRectangle.Height;
                    
                    int parentHeight = 0;
                    int parentWidth = 0;
            
                    if (collection.chart.Parent != null)
                    {
                        parentHeight = collection.chart.Parent.Height;
                        parentWidth = collection.chart.Parent.Width;
                    }
                    
                    // Horizontal clipping (not really working).
                    if (parentWidth != 0 && parentHeight != 0)
                    {
                        if (collection.chart.Location.X + currentValueX < -collection.chart.uwfOffset.X) // Left side.
                            continue;
                        if (collection.chart.Location.X + currentValueX + collection.chart.uwfOffset.X > parentWidth) // Right side.
                            continue;
                    }

#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_ANDROID || UNITY_WEBGL

                    float clipY = prevValueY;
                    
                    // Vertical clipping.
                    if (collection.chart.Location.Y + currentValueY < -collection.chart.uwfOffset.Y)
                        clipY = -collection.chart.uwfOffset.Y - collection.chart.Location.Y;
                    if (collection.chart.Location.Y + clipRectangle.Top + clipH + collection.chart.uwfOffset.Y > parentHeight)
                        clipH = parentHeight - collection.chart.uwfOffset.Y - collection.chart.Location.Y - clipRectangle.Top;

                    var unityMaterial = collection.chart.plotOptions.linearGradientMaterial as UnityEngine.Material;
                    if (unityMaterial != null)
                        unityMaterial.SetFloat("_Y", 1 - (clipY - clipRectangle.Top) / clipH);

#endif
                    g.uwfFillRectangle(areaColor, prevValueX, clipRectangle.Top, width, clipH,
                        collection.chart.plotOptions.linearGradientMaterial);
                    
                    if (last)
                        g.uwfFillRectangle(areaColor, currentValueX, clipRectangle.Top, xStep, clipH,
                            collection.chart.plotOptions.linearGradientMaterial);
                }

                g.DrawLine(pen, prevValueX, prevValueY, currentValueX + 1, prevValueY);
                g.DrawLine(pen, currentValueX, prevValueY, currentValueX, currentValueY);

                prevValueX = currentValueX;
                prevValueY = currentValueY;
                
                SeriesPaint.PaintHoveredValueRect(this, g, currentValueX, currentValueY, xStep);
            }
        }
        
        protected override void OnPaintIcon(Graphics g, Rectangle clipRectangle)
        {
            g.uwfFillRectangle(color, clipRectangle.Left + 4, clipRectangle.Top + 8, 8, 8);
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/ScrollEventType.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum ScrollEventType
    {
        SmallDecrement = 0,
        SmallIncrement = 1,
        LargeDecrement = 2,
        LargeIncrement = 3,
        ThumbPosition = 4,
        ThumbTrack = 5,
        First = 6,
        Last = 7,
        EndScroll = 8,
    }
}


<|start_filename|>Assets/Controls/Highcharts/XAxis.cs<|end_filename|>
﻿namespace Highcharts
{
    using System.Drawing;

    public class XAxis : Axis
    {
        public XAxis() : base(true)
        {
            gridLineColor = Color.FromArgb(0xE6, 0xE6, 0xE6);
            gridLineWidth = 0;
            lineColor = Color.FromArgb(0xCC, 0xD6, 0xEB);
            lineWidth = 1;
            tickColor = Color.FromArgb(0xCC, 0xD6, 0xEB);
            tickWidth = 1;
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelLabel.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public class PanelLabel : BaseExamplePanel
    {
        public override void Initialize()
        {
            // AutoSize.
            this.Create<Label>("AutoSize:");
            var textboxAutoSize = this.Create<TextBox>("write here");
            var labelAutosize = this.Create<Label>("", true);

            textboxAutoSize.Height = 20;
            textboxAutoSize.TextChanged += (sender, args) => labelAutosize.Text = textboxAutoSize.Text;
            labelAutosize.Text = textboxAutoSize.Text;
            labelAutosize.BorderStyle = BorderStyle.FixedSingle;

            // BackColor.
            this.Create<Label>("Background color:", false, 8, lineOffset);
            var colorPickerBack = this.Create<ColorPicker>();
            var labelBack = this.Create<Label>("label", true);

            colorPickerBack.Color = Color.CornflowerBlue;
            colorPickerBack.ColorChanged += (sender, args) => labelBack.BackColor = colorPickerBack.Color;
            labelBack.BackColor = colorPickerBack.Color;

            // Border style.
            var borderStyles = Enum.GetNames(typeof(BorderStyle));

            this.Create<Label>("Border style:", false, 8, lineOffset);
            var comboBorderStyle = this.Create<ComboBox>();
            var labelBorderStyle = this.Create<Label>("label", true);

            comboBorderStyle.Items.AddRange(borderStyles);
            comboBorderStyle.SelectedIndexChanged += (sender, args) =>
            {
                var selectedItem = comboBorderStyle.SelectedItem.ToString();
                labelBorderStyle.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), selectedItem);
            };

            // Text align.
            var contentAlign = Enum.GetNames(typeof(ContentAlignment));

            this.Create<Label>("Text align:", false, 8, lineOffset);
            var comboTextAlign = this.Create<ComboBox>();
            var labelTextAlign = this.Create<Label>("label", true);

            comboTextAlign.Items.AddRange(contentAlign);
            comboTextAlign.SelectedIndex = 0;
            comboTextAlign.SelectedIndexChanged += (sender, args) =>
            {
                var selectedItem = comboTextAlign.SelectedItem.ToString();
                labelTextAlign.TextAlign = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), selectedItem);
            };
            labelTextAlign.AutoSize = false;
            labelTextAlign.BorderStyle = BorderStyle.Fixed3D;
            labelTextAlign.Height += 8;
            labelTextAlign.Width += 96;

            // Unity Markup format.
            this.Create<Label>("Unity Markup format:", false, 8, lineOffset + 8);
            this.Create<Label>("<color=#FF7043><b>Unity</b></color> <i>Markup <color=#26A69A>format</color></i>");
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/Orientation.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum Orientation
    {
        Horizontal = 0,
        Vertical = 1,
    }
}


<|start_filename|>Assets/Unity/UnityKeyTranslator.cs<|end_filename|>
﻿#define ALLOW_SPECIAL_KEYS

namespace Unity
{
    using System.Windows.Forms;

    using UE = UnityEngine;

    public static class UnityKeyTranslator
    {
        public static Keys ToKeyData(UE.EventModifiers umods, UE.KeyCode ukey)
        {
            Keys key;

            switch (ukey)
            {
                // oem + shift
#if ALLOW_SPECIAL_KEYS
                case UE.KeyCode.Ampersand: key = Keys.Shift | Keys.D7; break;
                case UE.KeyCode.At: key = Keys.Shift | Keys.D2; break;
                case UE.KeyCode.Asterisk: key = Keys.Shift | Keys.D8; break;
                case UE.KeyCode.Caret: key = Keys.Shift | Keys.D6; break;
                case UE.KeyCode.Colon: key = Keys.Shift | Keys.OemSemicolon; break;
                case UE.KeyCode.Dollar: key = Keys.Shift | Keys.D4; break;
                case UE.KeyCode.DoubleQuote: key = Keys.Shift | Keys.OemQuotes; break;
                case UE.KeyCode.Exclaim: key = Keys.Shift | Keys.D1; break;
                case UE.KeyCode.Greater: key = Keys.Shift | Keys.OemPeriod; break;
                case UE.KeyCode.Hash: key = Keys.Shift | Keys.D3; break;
                case UE.KeyCode.LeftParen: key = Keys.Shift | Keys.D9; break;
                case UE.KeyCode.Less: key = Keys.Shift | Keys.Oemcomma; break;
                case UE.KeyCode.Plus: key = Keys.Shift | Keys.Oemplus; break;
                case UE.KeyCode.Question: key = Keys.Shift | Keys.OemQuestion; break;
                case UE.KeyCode.RightParen: key = Keys.Shift | Keys.D0; break;
                case UE.KeyCode.Underscore: key = Keys.Shift | Keys.OemMinus; break;
#endif

                // oem
                case UE.KeyCode.BackQuote: key = Keys.Oemtilde; break;
                case UE.KeyCode.Backslash: key = Keys.OemPipe; break;
                case UE.KeyCode.Comma: key = Keys.Oemcomma; break;
                case UE.KeyCode.Equals: key = Keys.Oemplus; break;
                case UE.KeyCode.LeftBracket: key = Keys.OemOpenBrackets; break;
                case UE.KeyCode.Minus: key = Keys.OemMinus; break;
                case UE.KeyCode.Period: key = Keys.OemPeriod; break;
                case UE.KeyCode.Quote: key = Keys.OemQuotes; break;
                case UE.KeyCode.RightBracket: key = Keys.OemCloseBrackets; break;
                case UE.KeyCode.Semicolon: key = Keys.OemSemicolon; break;
                case UE.KeyCode.Slash: key = Keys.OemQuestion; break;

                // other
                case UE.KeyCode.CapsLock: key = Keys.CapsLock; break;
                case UE.KeyCode.DownArrow: key = Keys.Down; break;
                case UE.KeyCode.Delete: key = Keys.Delete; break;
                case UE.KeyCode.End: key = Keys.End; break;
                case UE.KeyCode.Help: key = Keys.Help; break;
                case UE.KeyCode.Home: key = Keys.Home; break;
                case UE.KeyCode.Insert: key = Keys.Insert; break;
                case UE.KeyCode.LeftArrow: key = Keys.Left; break;
                case UE.KeyCode.Numlock: key = Keys.NumLock; break;
                case UE.KeyCode.PageDown: key = Keys.PageDown; break;
                case UE.KeyCode.PageUp: key = Keys.PageUp; break;
                case UE.KeyCode.Print: key = Keys.Print; break;
                case UE.KeyCode.RightArrow: key = Keys.Right; break;
                case UE.KeyCode.ScrollLock: key = Keys.Scroll; break;
                case UE.KeyCode.Space: key = Keys.Space; break;
                case UE.KeyCode.UpArrow: key = Keys.Up; break;

                // keypad (numpad)
                case UE.KeyCode.Keypad0: key = Keys.NumPad0; break;
                case UE.KeyCode.Keypad1: key = Keys.NumPad1; break;
                case UE.KeyCode.Keypad2: key = Keys.NumPad2; break;
                case UE.KeyCode.Keypad3: key = Keys.NumPad3; break;
                case UE.KeyCode.Keypad4: key = Keys.NumPad4; break;
                case UE.KeyCode.Keypad5: key = Keys.NumPad5; break;
                case UE.KeyCode.Keypad6: key = Keys.NumPad6; break;
                case UE.KeyCode.Keypad7: key = Keys.NumPad7; break;
                case UE.KeyCode.Keypad8: key = Keys.NumPad8; break;
                case UE.KeyCode.Keypad9: key = Keys.NumPad9; break;
                case UE.KeyCode.KeypadPeriod: key = Keys.Decimal; break;
                case UE.KeyCode.KeypadDivide: key = Keys.Divide; break;
                case UE.KeyCode.KeypadMultiply: key = Keys.Multiply; break;
                case UE.KeyCode.KeypadMinus: key = Keys.Subtract; break;
                case UE.KeyCode.KeypadPlus: key = Keys.Add; break;
                case UE.KeyCode.KeypadEnter: key = Keys.Return; break;
                // KeyCode.KeypadEquals?

                // mods
                case UE.KeyCode.LeftAlt:
                case UE.KeyCode.RightAlt:
                    return Keys.Menu | Keys.Alt;
                case UE.KeyCode.LeftControl:
                case UE.KeyCode.RightControl:
                    return Keys.ControlKey | Keys.Control;
                case UE.KeyCode.LeftShift:
                case UE.KeyCode.RightShift:
                    return Keys.ShiftKey | Keys.Shift; // GetAsyncKeyState?

                // functional
                case UE.KeyCode.F1:
                case UE.KeyCode.F2:
                case UE.KeyCode.F3:
                case UE.KeyCode.F4:
                case UE.KeyCode.F5:
                case UE.KeyCode.F6:
                case UE.KeyCode.F7:
                case UE.KeyCode.F8:
                case UE.KeyCode.F9:
                case UE.KeyCode.F10:
                case UE.KeyCode.F11:
                case UE.KeyCode.F12:
                case UE.KeyCode.F13:
                case UE.KeyCode.F14:
                case UE.KeyCode.F15:
                    key = (Keys)(ukey - 170);
                    break;

                // leters
                case UE.KeyCode.A:
                case UE.KeyCode.B:
                case UE.KeyCode.C:
                case UE.KeyCode.D:
                case UE.KeyCode.E:
                case UE.KeyCode.F:
                case UE.KeyCode.G:
                case UE.KeyCode.H:
                case UE.KeyCode.I:
                case UE.KeyCode.J:
                case UE.KeyCode.K:
                case UE.KeyCode.L:
                case UE.KeyCode.M:
                case UE.KeyCode.N:
                case UE.KeyCode.O:
                case UE.KeyCode.P:
                case UE.KeyCode.Q:
                case UE.KeyCode.R:
                case UE.KeyCode.S:
                case UE.KeyCode.T:
                case UE.KeyCode.U:
                case UE.KeyCode.V:
                case UE.KeyCode.W:
                case UE.KeyCode.X:
                case UE.KeyCode.Y:
                case UE.KeyCode.Z:
                    key = (Keys)(ukey - 32);
                    break;

                default: // numbers, mouse, joystick, other. Modifiers can be fucked up.
                    key = (Keys)ukey;
                    break;
            }

            // Add mods.
            if ((umods & UE.EventModifiers.Alt) != 0) key |= Keys.Alt;
            if ((umods & UE.EventModifiers.Control) != 0) key |= Keys.Control;
            if ((umods & UE.EventModifiers.Shift) != 0) key |= Keys.Shift;
            //if ((umods & UE.EventModifiers.Command) != 0) key |= (Keys)UE.EventModifiers.Command;
            //if ((umods & UE.EventModifiers.Numeric) != 0) key |= (Keys)UE.EventModifiers.Numeric;
            //if ((umods & UE.EventModifiers.CapsLock) != 0) key |= (Keys)UE.EventModifiers.CapsLock;
            //if ((umods & UE.EventModifiers.FunctionKey) != 0) key |= (Keys)UE.EventModifiers.FunctionKey;

            return key;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ControlPaint.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;
    using System.Drawing.Drawing2D;

    public static class ControlPaint
    {
        // It's fine to have a single pen for all borders, because it's single-threading application.
        private static readonly Pen borderPen1 = new Pen(Color.Transparent);
        private static readonly Pen borderPen2 = new Pen(Color.Transparent);
        private static readonly Pen borderPen3 = new Pen(Color.Transparent);
        private static readonly Pen borderPen4 = new Pen(Color.Transparent);

        public static Color Dark(Color baseColor)
        {
            return new HLSColor(baseColor).Darker(0.5f);
        }
        public static Color Dark(Color baseColor, float percOfDarkDark)
        {
            return new HLSColor(baseColor).Darker(percOfDarkDark);
        }
        public static Color DarkDark(Color baseColor)
        {
            return new HLSColor(baseColor).Darker(1.0f);
        }
        public static void DrawBorder(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style)
        {
            switch (style)
            {
                case ButtonBorderStyle.None:
                    break;

                case ButtonBorderStyle.Dotted:
                case ButtonBorderStyle.Dashed:
                case ButtonBorderStyle.Solid:
                    DrawBorderSimple(graphics, bounds, color, style);
                    break;

                case ButtonBorderStyle.Inset:
                case ButtonBorderStyle.Outset:
                    DrawBorderComplex(graphics, bounds, color, style);
                    break;
            }
        }
        public static void DrawBorder3D(Graphics graphics, Rectangle rectangle)
        {
            DrawBorder3D(
                graphics,
                rectangle.X,
                rectangle.Y,
                rectangle.Width,
                rectangle.Height,
                Border3DStyle.Etched,
                Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
        }
        public static void DrawBorder3D(Graphics graphics, Rectangle rectangle, Border3DStyle style)
        {
            DrawBorder3D(
                graphics,
                rectangle.X,
                rectangle.Y,
                rectangle.Width,
                rectangle.Height,
                style,
                Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
        }
        public static void DrawBorder3D(Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides)
        {
            DrawBorder3D(graphics, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, style, sides);
        }
        public static void DrawBorder3D(Graphics graphics, int x, int y, int width, int height)
        {
            DrawBorder3D(
                graphics,
                x,
                y,
                width,
                height,
                Border3DStyle.Etched,
                Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
        }
        public static void DrawBorder3D(Graphics graphics, int x, int y, int width, int height, Border3DStyle style)
        {
            DrawBorder3D(graphics, x, y, width, height, style, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom);
        }
        public static void DrawBorder3D(Graphics graphics, int x, int y, int width, int height, Border3DStyle style, Border3DSide sides)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");

            if ((style & Border3DStyle.Adjust) == Border3DStyle.Adjust)
            {
                var sz = SystemInformation.Border3DSize;
                x -= sz.Width;
                y -= sz.Height;
                width += sz.Width;
                height += sz.Height;
                style &= ~Border3DStyle.Adjust;
            }

            switch (style)
            {
                case Border3DStyle.Bump:
                    DrawBorderStyleBump(graphics, x, y, width, height, sides);
                    break;
                case Border3DStyle.Etched:
                    DrawBorderStyleEtched(graphics, x, y, width, height, sides);
                    break;
                case Border3DStyle.Flat:
                    DrawBorderStyleFlat(graphics, x, y, width, height, sides);
                    break;
                case Border3DStyle.Raised:
                    DrawBorderStyleRaised(graphics, x, y, width, height, sides, true, true);
                    break;
                case Border3DStyle.RaisedInner:
                    DrawBorderStyleRaised(graphics, x, y, width, height, sides, true, false);
                    break;
                case Border3DStyle.RaisedOuter:
                    DrawBorderStyleRaised(graphics, x, y, width, height, sides, false, true);
                    break;
                case Border3DStyle.Sunken:
                    DrawBorderStyleSunken(graphics, x, y, width, height, sides, true, true);
                    break;
                case Border3DStyle.SunkenInner:
                    DrawBorderStyleSunken(graphics, x, y, width, height, sides, true, false);
                    break;
                case Border3DStyle.SunkenOuter:
                    DrawBorderStyleSunken(graphics, x, y, width, height, sides, false, true);
                    break;
            }
        }

        public static Color Light(Color baseColor)
        {
            return new HLSColor(baseColor).Lighter(0.5f);
        }
        public static Color Light(Color baseColor, float percOfLightLight)
        {
            return new HLSColor(baseColor).Lighter(percOfLightLight);
        }
        public static Color LightLight(Color baseColor)
        {
            return new HLSColor(baseColor).Lighter(1.0f);
        }

        internal static Rectangle CalculateBackgroundImageRectangle(Rectangle bounds, Image backgroundImage, ImageLayout imageLayout)
        {
            var result = bounds;
            if (backgroundImage == null)
                return result;

            switch (imageLayout)
            {
                case ImageLayout.Stretch:
                    result.Size = bounds.Size;
                    break;

                case ImageLayout.None:
                    result.Size = backgroundImage.Size;
                    break;

                case ImageLayout.Center:
                    result.Size = backgroundImage.Size;
                    var szCtl = bounds.Size;

                    if (szCtl.Width > result.Width)
                        result.X = (szCtl.Width - result.Width) / 2;
                    if (szCtl.Height > result.Height)
                        result.Y = (szCtl.Height - result.Height) / 2;
                    break;

                case ImageLayout.Zoom:
                    var imageSize = backgroundImage.Size;
                    float xRatio = (float)bounds.Width / imageSize.Width;
                    float yRatio = (float)bounds.Height / imageSize.Height;
                    if (xRatio < yRatio)
                    {
                        result.Width = bounds.Width;
                        result.Height = (int)(imageSize.Height * xRatio + .5f);
                        if (bounds.Y >= 0)
                            result.Y = (bounds.Height - result.Height) / 2;
                    }
                    else
                    {
                        result.Height = bounds.Height;
                        result.Width = (int)(imageSize.Width * yRatio + .5f);
                        if (bounds.X >= 0)
                            result.X = (bounds.Width - result.Width) / 2;
                    }
                    break;
            }
            return result;
        }
        internal static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect)
        {
            DrawBackgroundImage(g, backgroundImage, backColor, backgroundImageLayout, bounds, clipRect, Point.Empty, RightToLeft.No);
        }
        internal static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset)
        {
            DrawBackgroundImage(g, backgroundImage, backColor, backgroundImageLayout, bounds, clipRect, scrollOffset, RightToLeft.No);
        }
        internal static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
        {
            if (g == null)
                throw new ArgumentNullException("g");

            if (backgroundImageLayout == ImageLayout.Tile)
            {
                var imageWidth = backgroundImage.Width;
                var imageHeight = backgroundImage.Height;

                // TODO: better to use shader.
                for (int y = 0; y < bounds.Height; y += imageHeight)
                    for (int x = 0; x < bounds.Width; x += imageWidth)
                        g.DrawImage(backgroundImage, x, y, imageWidth, imageHeight);
            }
            else
            {
                var imageRectangle = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);
                if (rightToLeft == RightToLeft.Yes && backgroundImageLayout == ImageLayout.None)
                    imageRectangle.X += clipRect.Width - imageRectangle.Width;

                g.uwfFillRectangle(backColor, clipRect);

                if (clipRect.Contains(imageRectangle) == false)
                {
                    switch (backgroundImageLayout)
                    {
                        case ImageLayout.Stretch:
                        case ImageLayout.Zoom:
                            imageRectangle.Intersect(clipRect);
                            g.DrawImage(backgroundImage, imageRectangle);
                            break;
                        default:
                            {
                                imageRectangle.Offset(clipRect.Location);
                                var imageRect = imageRectangle;
                                imageRect.Intersect(clipRect);
                                g.DrawImage(backgroundImage, imageRect);
                            }
                            break;
                    }
                }
                else
                    g.DrawImage(backgroundImage, imageRectangle);
            }
        }
        internal static bool IsDarker(Color c1, Color c2)
        {
            var hc1 = new HLSColor(c1);
            var hc2 = new HLSColor(c2);
            return hc1.Luminosity < hc2.Luminosity;
        }
        internal static void PrintBorder(Graphics graphics, Rectangle bounds, BorderStyle style, Border3DStyle b3dStyle)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");

            switch (style)
            {
                case BorderStyle.FixedSingle:
                    DrawBorder(graphics, bounds, SystemColors.WindowFrame, ButtonBorderStyle.Solid);
                    break;
                case BorderStyle.Fixed3D:
                    DrawBorder3D(graphics, bounds, b3dStyle);
                    break;
                case BorderStyle.None:
                    break;
            }
        }

        private static DashStyle BorderStyleToDashStyle(ButtonBorderStyle borderStyle)
        {
            switch (borderStyle)
            {
                case ButtonBorderStyle.Dotted: return DashStyle.Dot;
                case ButtonBorderStyle.Dashed: return DashStyle.Dash;
                case ButtonBorderStyle.Solid: return DashStyle.Solid;
                default:
                    return DashStyle.Solid;
            }
        }
        private static void DrawBorderComplex(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");

            borderPen1.DashStyle = DashStyle.Solid;

            if (style == ButtonBorderStyle.Inset)
            { // button being pushed
                var hls = new HLSColor(color);

                // top + left
                borderPen1.Color = hls.Darker(1.0f);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);

                // bottom + right
                borderPen1.Color = hls.Lighter(1.0f);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y + bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                graphics.DrawLine(borderPen1, bounds.X + bounds.Width - 1, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);

                // Top + left inset
                borderPen1.Color = hls.Lighter(0.5f);
                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + 1, bounds.X + bounds.Width - 2, bounds.Y + 1);
                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + 1, bounds.X + 1, bounds.Y + bounds.Height - 2);

                // bottom + right inset
                if (color == SystemColors.Control)
                {
                    borderPen1.Color = SystemColors.ControlLight;
                    graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + bounds.Height - 2, bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                    graphics.DrawLine(borderPen1, bounds.X + bounds.Width - 2, bounds.Y + 1, bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                }
            }
            else
            {
                // Standard button
                bool stockColor = color == SystemColors.Control;
                var hls = new HLSColor(color);

                // top + left
                borderPen1.Color = stockColor ? SystemColors.ControlLightLight : hls.Lighter(1.0f);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);

                // bottom + right
                borderPen1.Color = stockColor ? SystemColors.ControlDarkDark : hls.Darker(1.0f);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y + bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                graphics.DrawLine(borderPen1, bounds.X + bounds.Width - 1, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);

                // top + left inset
                if (stockColor)
                    borderPen1.Color = SystemInformation.HighContrast ? SystemColors.ControlLight : SystemColors.Control;
                else
                    borderPen1.Color = color;

                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + 1, bounds.X + bounds.Width - 2, bounds.Y + 1);
                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + 1, bounds.X + 1, bounds.Y + bounds.Height - 2);

                // Bottom + right inset                        
                borderPen1.Color = stockColor ? SystemColors.ControlDark : hls.Darker(0.5f);
                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + bounds.Height - 2, bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                graphics.DrawLine(borderPen1, bounds.X + bounds.Width - 2, bounds.Y + 1, bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
            }
        }
        private static void DrawBorderSimple(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");

            borderPen1.Color = color;
            borderPen1.DashStyle = style != ButtonBorderStyle.Solid ? BorderStyleToDashStyle(style) : DashStyle.Solid;

            graphics.DrawRectangle(borderPen1, bounds.X, bounds.Y, bounds.Width, bounds.Height);
        }
        private static void DrawBorderStyleBump(Graphics graphics, int x, int y, int width, int height, Border3DSide sides)
        {
            var left = (sides & Border3DSide.Left) != 0;
            var top = (sides & Border3DSide.Top) != 0;
            var right = (sides & Border3DSide.Right) != 0;
            var bottom = (sides & Border3DSide.Bottom) != 0;

            borderPen1.DashStyle = DashStyle.Solid;
            borderPen2.DashStyle = DashStyle.Solid;
            borderPen1.Color = SystemColors.ControlLight;
            borderPen2.Color = SystemColors.ControlDarkDark;

            if (left)
            {
                graphics.DrawLine(borderPen1, x, y, x, y + height);
                graphics.DrawLine(borderPen2, x + 1, y, x + 1, y + height);
            }
            if (top)
            {
                var top2x1 = left ? x + 1 : x;
                var top2x2 = right ? x + width - 2 : x + width;
                graphics.DrawLine(borderPen1, x, y, x + width, y);
                graphics.DrawLine(borderPen2, top2x1, y + 1, top2x2, y + 1);
            }
            if (right)
            {
                var right1y2 = bottom ? y + height - 1 : y + height;
                graphics.DrawLine(borderPen1, x + width - 2, y, x + width - 2, right1y2);
                graphics.DrawLine(borderPen2, x + width - 1, y, x + width - 1, y + height);
            }
            if (bottom)
            {
                var bottom1x2 = right ? x + width - 1 : x + width;
                graphics.DrawLine(borderPen1, x, y + height - 2, bottom1x2, y + height - 2);
                graphics.DrawLine(borderPen2, x, y + height - 1, x + width, y + height - 1);
            }
        }
        private static void DrawBorderStyleEtched(Graphics graphics, int x, int y, int width, int height, Border3DSide sides)
        {
            var left = (sides & Border3DSide.Left) != 0;
            var top = (sides & Border3DSide.Top) != 0;
            var right = (sides & Border3DSide.Right) != 0;
            var bottom = (sides & Border3DSide.Bottom) != 0;

            borderPen1.DashStyle = DashStyle.Solid;
            borderPen2.DashStyle = DashStyle.Solid;
            borderPen1.Color = SystemColors.ControlDark;
            borderPen2.Color = Color.White;

            if (left)
            {
                graphics.DrawLine(borderPen1, x, y, x, y + height);
                graphics.DrawLine(borderPen2, x + 1, y, x + 1, y + height);
            }
            if (top)
            {
                var top2x1 = left ? x + 1 : x;
                var top2x2 = right ? x + width - 1 : x + width;
                graphics.DrawLine(borderPen1, x, y, x + width, y);
                graphics.DrawLine(borderPen2, top2x1, y + 1, top2x2, y + 1);
            }
            if (right)
                graphics.DrawLine(borderPen1, x + width - 1, y, x + width - 1, y + height);
            if (bottom)
                graphics.DrawLine(borderPen1, x, y + height - 1, y + width, y + height - 1);
        }
        private static void DrawBorderStyleFlat(Graphics graphics, int x, int y, int width, int height, Border3DSide sides)
        {
            var left = (sides & Border3DSide.Left) != 0;
            var top = (sides & Border3DSide.Top) != 0;
            var right = (sides & Border3DSide.Right) != 0;
            var bottom = (sides & Border3DSide.Bottom) != 0;

            borderPen1.DashStyle = DashStyle.Solid;
            borderPen2.DashStyle = DashStyle.Solid;
            borderPen1.Color = SystemColors.ControlDark;
            borderPen2.Color = SystemColors.Control;

            if (left)
            {
                graphics.DrawLine(borderPen1, x, y, x, y + height);
                graphics.DrawLine(borderPen2, x + 1, y, x + 1, y + height);
            }
            if (top)
            {
                var top2x1 = left ? x + 1 : x;
                var top2x2 = right ? x + width - 2 : x + width;
                graphics.DrawLine(borderPen1, x, y, x + width, y);
                graphics.DrawLine(borderPen2, top2x1, y + 1, top2x2, y + 1);
            }
            if (right)
            {
                var right1y1 = top ? y + 1 : y;
                var right1y2 = bottom ? y + height - 1 : y + height;
                graphics.DrawLine(borderPen2, x + width - 2, right1y1, x + width - 2, right1y2);
                graphics.DrawLine(borderPen1, x + width - 1, y, x + width - 1, y + height);
            }
            if (bottom)
            {
                var bottom1x1 = left ? x + 1 : x;
                var bottom1x2 = right ? x + width - 1 : x + width;
                graphics.DrawLine(borderPen2, bottom1x1, y + height - 2, bottom1x2, y + height - 2);
                graphics.DrawLine(borderPen1, x, y + height - 1, x + width, y + height - 1);
            }
        }
        private static void DrawBorderStyleRaised(Graphics graphics, int x, int y, int width, int height, Border3DSide sides, bool inner, bool outer)
        {
            var left = (sides & Border3DSide.Left) != 0;
            var top = (sides & Border3DSide.Top) != 0;
            var right = (sides & Border3DSide.Right) != 0;
            var bottom = (sides & Border3DSide.Bottom) != 0;

            borderPen1.DashStyle = DashStyle.Solid;
            borderPen2.DashStyle = DashStyle.Solid;
            borderPen3.DashStyle = DashStyle.Solid;
            borderPen4.DashStyle = DashStyle.Solid;
            borderPen1.Color = outer ? SystemColors.ControlLight : Color.Transparent;
            borderPen2.Color = Color.White;
            borderPen3.Color = outer ? SystemColors.ControlDarkDark : Color.Transparent;
            borderPen4.Color = SystemColors.ControlDark;

            if (left)
            {
                graphics.DrawLine(borderPen1, x, y, x, y + height);
                if (inner)
                    graphics.DrawLine(borderPen2, x + 1, y, x + 1, y + height);
            }
            if (top)
            {
                var top1x2 = right ? x + width - 1 : x + width;
                var top2x1 = left ? x + 1 : x;
                var top2x2 = right ? x + width - 2 : x + width;
                graphics.DrawLine(borderPen1, x, y, top1x2, y);
                if (inner)
                    graphics.DrawLine(borderPen2, top2x1, y + 1, top2x2, y + 1);
            }
            if (right)
            {
                var right2y1 = top ? y + 1 : y;
                var right2y2 = bottom ? y + height - 1 : y + height;
                graphics.DrawLine(borderPen3, x + width - 1, y, x + width - 1, y + height);
                if (inner)
                    graphics.DrawLine(borderPen4, x + width - 2, right2y1, x + width - 2, right2y2);
            }
            if (bottom)
            {
                var bottom2x1 = left ? x + 1 : x;
                var bottom2x2 = right ? x + width - 2 : x + width;
                graphics.DrawLine(borderPen3, x, y + height - 1, x + width, y + height - 1);
                if (inner)
                    graphics.DrawLine(borderPen4, bottom2x1, y + height - 2, bottom2x2, y + height - 2);
            }
        }
        private static void DrawBorderStyleSunken(Graphics graphics, int x, int y, int width, int height, Border3DSide sides, bool inner, bool outer)
        {
            var left = (sides & Border3DSide.Left) != 0;
            var top = (sides & Border3DSide.Top) != 0;
            var right = (sides & Border3DSide.Right) != 0;
            var bottom = (sides & Border3DSide.Bottom) != 0;

            borderPen1.DashStyle = DashStyle.Solid;
            borderPen2.DashStyle = DashStyle.Solid;
            borderPen3.DashStyle = DashStyle.Solid;
            borderPen4.DashStyle = DashStyle.Solid;
            borderPen1.Color = outer ? SystemColors.ControlDark : Color.Transparent;
            borderPen2.Color = SystemColors.ControlDarkDark;
            borderPen3.Color = outer ? Color.White : Color.Transparent;
            borderPen4.Color = SystemColors.ControlLight;

            if (left)
            {
                graphics.DrawLine(borderPen1, x, y, x, y + height);
                if (inner)
                    graphics.DrawLine(borderPen2, x + 1, y, x + 1, y + height);
            }
            if (top)
            {
                var top1x2 = right ? x + width - 1 : x + width;
                var top2x1 = left ? x + 1 : x;
                var top2x2 = right ? x + width - 2 : x + width;
                graphics.DrawLine(borderPen1, x, y, top1x2, y);
                if (inner)
                    graphics.DrawLine(borderPen2, top2x1, y + 1, top2x2, y + 1);
            }
            if (right)
            {
                var right2y1 = top ? y + 1 : y;
                var right2y2 = bottom ? y + height - 1 : y + height;
                graphics.DrawLine(borderPen3, x + width - 1, y, x + width - 1, y + height);
                if (inner)
                    graphics.DrawLine(borderPen4, x + width - 2, right2y1, x + width - 2, right2y2);
            }
            if (bottom)
            {
                var bottom2x1 = left ? x + 1 : x;
                var bottom2x2 = right ? x + width - 2 : x + width;
                graphics.DrawLine(borderPen3, x, y + height - 1, x + width, y + height - 1);
                if (inner)
                    graphics.DrawLine(borderPen4, bottom2x1, y + height - 2, bottom2x2, y + height - 2);
            }
        }

        private struct HLSColor
        {
            private const int ShadowAdj = -333;
            private const int HilightAdj = 500;

            private const int Range = 240;
            private const int HLSMax = Range;
            private const int RGBMax = 255;
            private const int Undefined = HLSMax * 2 / 3;

            private readonly int hue;
            private readonly int saturation;
            private readonly int luminosity;

            private readonly bool isSystemColors_Control;

            public HLSColor(Color color)
            {
                isSystemColors_Control = color == SystemColors.Control;

                int r = color.R;
                int g = color.G;
                int b = color.B;

                var max = Math.Max(Math.Max(r, g), b);
                var min = Math.Min(Math.Min(r, g), b);
                var sum = max + min;

                luminosity = (sum * HLSMax + RGBMax) / (2 * RGBMax);

                var dif = max - min;
                if (dif == 0)
                {
                    saturation = 0;
                    hue = Undefined;
                }
                else
                {
                    if (luminosity <= HLSMax / 2)
                        saturation = (dif * HLSMax + sum / 2) / sum;
                    else
                        saturation = (dif * HLSMax + (2 * RGBMax - sum) / 2) / (2 * RGBMax - sum);

                    var rdelta = ((max - r) * (HLSMax / 6) + dif / 2) / dif;
                    var gdelta = ((max - g) * (HLSMax / 6) + dif / 2) / dif;
                    var bdelta = ((max - b) * (HLSMax / 6) + dif / 2) / dif;

                    if (r == max)
                        hue = bdelta - gdelta;
                    else if (g == max)
                        hue = HLSMax / 3 + rdelta - bdelta;
                    else
                        hue = 2 * HLSMax / 3 + gdelta - rdelta;

                    if (hue < 0)
                        hue += HLSMax;
                    if (hue > HLSMax)
                        hue -= HLSMax;
                }
            }

            public int Luminosity { get { return luminosity; } }

            public static bool operator ==(HLSColor a, HLSColor b)
            {
                return a.Equals(b);
            }
            public static bool operator !=(HLSColor a, HLSColor b)
            {
                return !a.Equals(b);
            }

            public override bool Equals(object o)
            {
                if (o is HLSColor == false)
                    return false;

                var c = (HLSColor)o;
                return hue == c.hue &&
                       saturation == c.saturation &&
                       luminosity == c.luminosity &&
                       isSystemColors_Control == c.isSystemColors_Control;
            }
            public override int GetHashCode()
            {
                return hue << 6 | saturation << 2 | luminosity;
            }
            public Color Darker(float percDarker)
            {
                if (isSystemColors_Control)
                {
                    if (percDarker == 0.0f)
                        return SystemColors.ControlDark;

                    if (percDarker == 1.0f)
                        return SystemColors.ControlDarkDark;

                    var dark = SystemColors.ControlDark;
                    var darkDark = SystemColors.ControlDarkDark;

                    int dr = dark.R - darkDark.R;
                    int dg = dark.G - darkDark.G;
                    int db = dark.B - darkDark.B;

                    return Color.FromArgb(
                        (byte)(dark.R - (byte)(dr * percDarker)),
                        (byte)(dark.G - (byte)(dg * percDarker)),
                        (byte)(dark.B - (byte)(db * percDarker)));
                }

                int oneLum = 0;
                int zeroLum = NewLuma(ShadowAdj, true);

                return ColorFromHLS(hue, zeroLum - (int)((zeroLum - oneLum) * percDarker), saturation);
            }
            public Color Lighter(float percLighter)
            {
                if (isSystemColors_Control)
                {
                    if (percLighter == 0.0f)
                        return SystemColors.ControlLight;

                    if (percLighter == 1.0f)
                        return SystemColors.ControlLightLight;

                    var light = SystemColors.ControlLight;
                    var lightLight = SystemColors.ControlLightLight;

                    int dr = light.R - lightLight.R;
                    int dg = light.G - lightLight.G;
                    int db = light.B - lightLight.B;

                    return Color.FromArgb(
                        (byte)(light.R - (byte)(dr * percLighter)),
                        (byte)(light.G - (byte)(dg * percLighter)),
                        (byte)(light.B - (byte)(db * percLighter)));
                }

                int zeroLum = luminosity;
                int oneLum = NewLuma(HilightAdj, true);

                return ColorFromHLS(hue, zeroLum + (int)((oneLum - zeroLum) * percLighter), saturation);
            }

            private static Color ColorFromHLS(int hue, int luminosity, int saturation)
            {
                byte r, g, b;

                if (saturation == 0)
                    r = g = b = (byte)(luminosity * RGBMax / HLSMax);
                else
                {
                    int magic2;
                    if (luminosity <= HLSMax / 2)
                        magic2 = (luminosity * (HLSMax + saturation) + HLSMax / 2) / HLSMax;
                    else
                        magic2 = luminosity + saturation - (luminosity * saturation + HLSMax / 2) / HLSMax;
                    var magic1 = 2 * luminosity - magic2;

                    r = (byte)((HueToRGB(magic1, magic2, hue + HLSMax / 3) * RGBMax + HLSMax / 2) / HLSMax);
                    g = (byte)((HueToRGB(magic1, magic2, hue) * RGBMax + HLSMax / 2) / HLSMax);
                    b = (byte)((HueToRGB(magic1, magic2, hue - HLSMax / 3) * RGBMax + HLSMax / 2) / HLSMax);
                }

                return Color.FromArgb(r, g, b);
            }
            private static int HueToRGB(int n1, int n2, int hue)
            {
                if (hue < 0)
                    hue += HLSMax;

                if (hue > HLSMax)
                    hue -= HLSMax;

                if (hue < HLSMax / 6)
                    return n1 + ((n2 - n1) * hue + HLSMax / 12) / (HLSMax / 6);
                if (hue < HLSMax / 2)
                    return n2;
                if (hue < HLSMax * 2 / 3)
                    return n1 + ((n2 - n1) * (HLSMax * 2 / 3 - hue) + HLSMax / 12) / (HLSMax / 6);

                return n1;
            }
            private static int NewLuma(int luminosity, int n, bool scale)
            {
                if (n == 0)
                    return luminosity;

                if (scale)
                {
                    if (n > 0)
                        return (int)((luminosity * (1000 - n) + (Range + 1L) * n) / 1000);

                    return luminosity * (n + 1000) / 1000;
                }

                int newLum = luminosity;
                newLum += (int)((long)n * Range / 1000);

                if (newLum < 0)
                    newLum = 0;
                if (newLum > HLSMax)
                    newLum = HLSMax;

                return newLum;
            }

            private int NewLuma(int n, bool scale)
            {
                return NewLuma(luminosity, n, scale);
            }
        }
    }
}


<|start_filename|>Assets/System/Drawing/IDeviceContext.cs<|end_filename|>
﻿namespace System.Drawing
{
    public interface IDeviceContext : IDisposable
    {
    }
}


<|start_filename|>Assets/Unity/API/UnityGdi.cs<|end_filename|>
﻿namespace Unity.API
{
    using System;
    using System.Drawing;
    using System.Drawing.API;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;

    using UE = UnityEngine;
    
    public class UnityGdi : IApiGraphics
    {
        public static UE.Color cursorSelectionColor = Color.FromArgb(128, SystemColors.Highlight).ToUnityColor();
        public static UE.Texture2D defaultTexture = UnityWinForms.DefaultTexture;

        private static readonly UE.GUIContent textContent = new UE.GUIContent(""); // GUIContent.Temp(text) replacement.
        private static readonly UE.Rect sourceRect = new UE.Rect(0f, 0f, 1f, 1f);
        private static readonly UE.Material blendMaterial = new UE.Material(UE.Shader.Find("Hidden/Internal-GUITextureClip"));
        
        public void BeginGroup(float x, float y, float width, float height)
        {
            UE.GUI.BeginGroup(new UE.Rect(x, y, width, height), UE.GUIContent.none, UE.GUIStyle.none);
        }
        public void Clear(Color color)
        {
            UE.GUI.color = color.ToUnityColor();
            UE.GUI.skin.settings.selectionColor = cursorSelectionColor;
        }
        public ITexture CreateTexture(int width, int height)
        {
            return new UnityGdiTexture(width, height);
        }
        public ITexture CreateTexture(object original)
        {
            var texture = original as UE.Texture2D;
            if (texture != null)
                return new UnityGdiTexture(texture);

            var sprite = original as UE.Sprite;
            if (sprite != null)
                return new UnityGdiSprite(sprite);

            throw new NotSupportedException();
        }
        public void DrawImage(Image image, float x, float y, float width, float height, float angle)
        {
            if (image == null || width <= 0 || height <= 0)
                return;

            var unityGdiSprite = image.Texture as UnityGdiSprite;
            if (unityGdiSprite != null && unityGdiSprite.sprite != null)
            {
                var spriteRect = unityGdiSprite.sprite.rect;
                var texture = unityGdiSprite.sprite.texture;
                var sx = spriteRect.x / texture.width;
                var sy = spriteRect.y / texture.height;
                var sw = spriteRect.width / texture.width;
                var sh = spriteRect.height / texture.height;
                UE.GUI.color = image.Color.ToUnityColor();
                UE.GUI.DrawTextureWithTexCoords(new UE.Rect(x, y, width, height), unityGdiSprite.sprite.texture, new UE.Rect(sx, sy, sw, sh));
                return;
            }

            var textureToDraw = defaultTexture;
            var imageTexture = image.Texture as UnityGdiTexture;
            if (imageTexture != null)
                textureToDraw = imageTexture.texture;

            if (angle != 0)
            {
                UE.Matrix4x4 matrixBackup = UE.GUI.matrix;
                UE.GUIUtility.RotateAroundPivot(angle, new UE.Vector2(x + width / 2, y + height / 2));
                UE.GUI.DrawTexture(new UE.Rect(x, y, width, height), ((UnityGdiTexture)image.Texture).texture);
                UE.GUI.matrix = matrixBackup;
                return;
            }

            UE.GUI.color = image.Color.ToUnityColor();
            UE.GUI.DrawTexture(new UE.Rect(x, y, width, height), textureToDraw);
        }
        public void DrawImage(Image image, float x, float y, float width, float height, object material = null)
        {
            var textureToDraw = defaultTexture;
            if (image != null)
            {
                var imageTexture = image.Texture as UnityGdiTexture;
                if (imageTexture != null)
                    textureToDraw = imageTexture.texture;
            }

            // Draw default texture with material if possible.
            if (material != null)
            {
                var mat = material as UE.Material;
                if (mat != null)
                {
                    UnityEngine.Graphics.DrawTexture(new UE.Rect(x, y, width, height), textureToDraw, mat);
                    return;
                }
            }

            UE.GUI.color = UE.Color.white;
            UE.GUI.DrawTexture(new UE.Rect(x, y, width, height), textureToDraw);
        }
        public void DrawLine(Pen pen, float x1, float y1, float x2, float y2, object material = null)
        {
            DrawLine(pen.Color, pen.Width, pen.DashStyle, x1, y1, x2, y2, material);
        }
        public void DrawLine(Color penColor, float penWidth, DashStyle style, float x1, float y1, float x2, float y2, object material = null)
        {
            if (penColor.A <= 0 || penWidth <= 0) return;
            if (UE.Event.current.type != UE.EventType.Repaint)
                return;
            
            var unityColor = penColor.ToUnityColor();
            
            // Diagonal lines.
            // Slower, dash not supported, more precise.
            if (x1 != x2 && y1 != y2)
            {
                float dx = x2 - x1;
                float dy = y2 - y1;
                float length = (float) System.Math.Sqrt(dx * dx + dy * dy);

                if (length < 0.001f)
                    return;

                float wdx = penWidth * dy / length;
                float wdy = penWidth * dx / length;
         
                var matrix = UE.Matrix4x4.identity;
                matrix.m00 = dx;
                matrix.m01 = -wdx;
                matrix.m03 = x1 + 0.5f * wdx;
                matrix.m10 = dy;
                matrix.m11 = wdy;
                matrix.m13 = y1 - 0.5f * wdy;
         
                UE.GL.PushMatrix();
                UE.GL.MultMatrix(matrix);
                UE.Graphics.DrawTexture(sourceRect, defaultTexture, sourceRect, 0, 0, 0, 0, unityColor, blendMaterial);
                UE.GL.PopMatrix();
                
                return;
            }
            
            float x = 0;
            float y = 0;
            float width = 0;
            float height = 0;

            if (x1 == x2)
            {
                if (y1 > y2) y1 += penWidth;
                else y2 += penWidth;
                x = x1;
                width = penWidth;
                if (y1 < y2)
                {
                    y = y1;
                    height = y2 - y1;
                }
                else
                {
                    y = y2;
                    height = y1 - y2;
                }
            }
            if (y1 == y2)
            {
                y = y1;
                height = penWidth;
                if (x1 < x2)
                {
                    x = x1;
                    width = x2 - x1;
                }
                else
                {
                    x = x2;
                    width = x1 - x2;
                }
            }
                    
            var penDash = style;
            
            switch (penDash)
            {
                case DashStyle.Solid:
                    UE.Graphics.DrawTexture(new UE.Rect(x, y, width, height), defaultTexture, sourceRect, 0, 0, 0, 0, unityColor, blendMaterial);
                    break;
                case DashStyle.Dash:
                    float dashStep = penWidth * 6;
                    const float dashSpacing = 2;
                    
                    if (y1 == y2) // Horizontal.
                        for (float i = 0; i < width; i += dashStep)
                        {
                            float dashWidth = dashStep - dashSpacing;
                            if (i + dashWidth > width)
                                dashWidth = width - i;

                            UE.Graphics.DrawTexture(new UE.Rect(x + i, y, dashWidth, penWidth), defaultTexture, sourceRect, 0, 0, 0, 0, unityColor, blendMaterial);
                        }

                    if (x1 == x2) // Vertical.
                        for (float i = 0; i < height; i += dashStep)
                        {
                            float dashHeight = dashStep - dashSpacing;
                            if (i + dashHeight > height)
                                dashHeight = height - i;

                            UE.Graphics.DrawTexture(new UE.Rect(x + width - penWidth, y + i, penWidth, dashHeight), defaultTexture, sourceRect, 0, 0, 0, 0, unityColor, blendMaterial);
                        }
                    break;
            }
        }
        public void DrawPolygon(Pen pen, Point[] points, object material = null)
        {
            for (int i = 0; i < points.Length; i++)
            {
                if (i + 1 >= points.Length) break;

                UE.GL.Begin(UE.GL.LINES);
                UE.GL.Color(pen.Color.ToUnityColor());

                UE.GL.Vertex3(points[i].X, points[i].Y, 0);
                UE.GL.Vertex3(points[i + 1].X, points[i + 1].Y, 0);

                UE.GL.End();
            }
        }
        public void DrawRectangle(Pen pen, float x, float y, float width, float height, object material = null)
        {
            var penColor = pen.Color;
            var penWidth = pen.Width;

            if (penColor.A <= 0 || penWidth <= 0) return;
            if (UE.Event.current.type != UE.EventType.Repaint)
                return;
            
            var color = penColor.ToUnityColor();
            var penDash = pen.DashStyle;
            
            switch (penDash)
            {
                case System.Drawing.Drawing2D.DashStyle.Solid:
                    UE.Graphics.DrawTexture(new UE.Rect(x, y, width, penWidth), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial);
                    UE.Graphics.DrawTexture(new UE.Rect(x + width - penWidth, y + penWidth, penWidth, height - penWidth * 2), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial);
                    
                    if (height > 1)
                        UE.Graphics.DrawTexture(new UE.Rect(x, y + height - penWidth, width, penWidth), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial);

                    if (width > 1)
                        UE.Graphics.DrawTexture(new UE.Rect(x, y + penWidth, penWidth, height - penWidth * 2), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial);

                    break;
                
                case System.Drawing.Drawing2D.DashStyle.Dash:
                    float dash_step = penWidth * 6;
                    for (float i = 0; i < width; i += dash_step)
                    {
                        float dash_width = dash_step - 2;
                        if (i + dash_width > width)
                            dash_width = width - i;

                        UE.Graphics.DrawTexture(new UE.Rect(x + i, y, dash_width, penWidth), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial); // Top.
                        UE.Graphics.DrawTexture(new UE.Rect(x + i, y + height - penWidth, dash_width, penWidth), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial); // Bottom.
                    }
                    for (float i = 0; i < height; i += dash_step)
                    {
                        float dash_height = dash_step - 2;
                        if (i + dash_height > height)
                            dash_height = height - i;
                        
                        UE.Graphics.DrawTexture(new UE.Rect(x + width - penWidth, y + i, penWidth, dash_height), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial); // Right.
                        UE.Graphics.DrawTexture(new UE.Rect(x, y + i, penWidth, dash_height), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial); // Left.
                    }
                    break;
                
                case DashStyle.Dot:
                    for (float i = 0; i < height; i += 2)
                    {
                        UE.Graphics.DrawTexture(new UE.Rect(x + width - 1, y + i, 1, 1), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial); // Right.
                        UE.Graphics.DrawTexture(new UE.Rect(x, y + i, 1, 1), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial); // Left.
                    }
                    for (float i = 0; i < width; i += 2)
                    {
                        UE.Graphics.DrawTexture(new UE.Rect(x + i, y, 1, 1), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial); // Top.
                        UE.Graphics.DrawTexture(new UE.Rect(x + i, y + height - 1, 1, 1), defaultTexture, sourceRect, 0, 0, 0, 0, color, blendMaterial); // Bottom.
                    }
                    
                    break;
            }
        }
        public void DrawString(string text, Font font, Color color, float x, float y, float width, float height, ContentAlignment align, object material = null)
        {
            if (text == null || font == null) return;

            if (UE.Event.current.type != UE.EventType.Repaint)
                return;
            
            // TODO: material not supported.

            // Set align.
            var uAlign = UE.TextAnchor.UpperLeft;
            switch (align)
            {
                case ContentAlignment.BottomCenter:
                    uAlign = UE.TextAnchor.LowerCenter;
                    break;
                case ContentAlignment.BottomLeft:
                    uAlign = UE.TextAnchor.LowerLeft;
                    break;
                case ContentAlignment.BottomRight:
                    uAlign = UE.TextAnchor.LowerRight;
                    break;
                case ContentAlignment.MiddleCenter:
                    uAlign = UE.TextAnchor.MiddleCenter;
                    break;
                case ContentAlignment.MiddleLeft:
                    uAlign = UE.TextAnchor.MiddleLeft;
                    break;
                case ContentAlignment.MiddleRight:
                    uAlign = UE.TextAnchor.MiddleRight;
                    break;
                case ContentAlignment.TopCenter:
                    uAlign = UE.TextAnchor.UpperCenter;
                    break;
                case ContentAlignment.TopLeft:
                    uAlign = UE.TextAnchor.UpperLeft;
                    break;
                case ContentAlignment.TopRight:
                    uAlign = UE.TextAnchor.UpperRight;
                    break;
            }

            var labelSkin = UE.GUI.skin.label;
            int guiSkinFontSizeBuffer = GUI_SetFont(labelSkin, font);

            UE.GUI.color = color.ToUnityColor();
            labelSkin.alignment = uAlign;

            textContent.text = text;
            
            // It's faster to invoke less methods and use your own GUIContent. Not that much, but anyway.
            // NOTE: +1 because something changed in a newer versions of Unity (testing on 2019.1.12f1).
            UE.GUI.Label(new UE.Rect(x, y, width + 1, height), textContent, labelSkin);

            labelSkin.fontSize = guiSkinFontSizeBuffer;
        }
        public void EndGroup()
        {
            UE.GUI.EndGroup();
        }
        public void FillRectangle(Brush brush, float x, float y, float width, float height, object material = null)
        {
            var solidBrush = brush as SolidBrush;
            if (solidBrush != null)
                FillRectangle(solidBrush.Color, x, y, width, height, material);
        }
        public void FillRectangle(Color color, float x, float y, float width, float height, object material = null)
        {
            if (color.A <= 0)
                return;
            
            if (UE.Event.current.type != UE.EventType.Repaint)
                return;
            
            var rect = new UE.Rect(x, y, width, height);

            if (material == null || material is UE.Material == false)
            {
                UE.Graphics.DrawTexture(rect, defaultTexture, sourceRect, 0, 0, 0, 0, color.ToUnityColor(), blendMaterial);
                return;
            }

            var umat = (UE.Material)material;
            umat.color = color.ToUnityColor();
            UE.Graphics.DrawTexture(rect, defaultTexture, sourceRect, 0, 0, 0, 0, umat);
        }
        public void Focus()
        {
            UE.GUI.FocusControl("nextControl");
        }
        public void FocusNext()
        {
            UE.GUI.SetNextControlName("nextControl");
        }
        public SizeF MeasureString(string text, Font font)
        {
            var labelSkin = UE.GUI.skin.label;
            int guiSkinFontSizeBuffer = GUI_SetFont(labelSkin, font);

            textContent.text = text;
            
            var size = labelSkin.CalcSize(textContent);

            labelSkin.fontSize = guiSkinFontSizeBuffer;

            return new SizeF(size.x, size.y);
        }
        
        internal string uwfDrawPasswordField(string s, Font font, Color color, float x, float y, float width, float height, HorizontalAlignment alignment)
        {
            if (s == null) s = "";

            UE.GUI.skin.textField.alignment = UE.TextAnchor.UpperLeft;
            switch (alignment)
            {
                case HorizontalAlignment.Center:
                    UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleCenter;
                    break;
                default:
                    UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleLeft;
                    break;
                case HorizontalAlignment.Right:
                    UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleRight;
                    break;
            }

            GUI_SetFont(UE.GUI.skin.textField, font);
            
            UE.GUI.color = color.ToUnityColor();

            UE.GUI.skin.textField.hover.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textField.active.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textField.focused.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textField.normal.background = UnityWinForms.TransparentTexture;
            
            return UE.GUI.PasswordField(new UE.Rect(x, y, width, height), s, '*');
        }
        internal string uwfDrawTextArea(string s, Font font, Color color, float x, float y, float width, float height)
        {
            if (s == null) s = "";

            UE.GUI.skin.textArea.alignment = UE.TextAnchor.UpperLeft;

            UE.GUI.color = color.ToUnityColor();
            //GUI.skin.textArea.hover.textColor = brush.Color.ToUColor();

            GUI_SetFont(UE.GUI.skin.textArea, font);

            UE.GUI.skin.textArea.hover.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textArea.active.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textArea.focused.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textArea.normal.background = UnityWinForms.TransparentTexture;

            return UE.GUI.TextArea(new UE.Rect(x, y, width, height), s);
        }
        internal string uwfDrawTextField(string s, Font font, Color color, float x, float y, float width, float height, HorizontalAlignment alignment)
        {
            if (s == null) s = "";

            UE.GUI.skin.textField.alignment = UE.TextAnchor.UpperLeft;
            switch (alignment)
            {
                case HorizontalAlignment.Center:
                    UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleCenter;
                    break;
                default:
                    UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleLeft;
                    break;
                case HorizontalAlignment.Right:
                    UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleRight;
                    break;
            }

            GUI_SetFont(UE.GUI.skin.textField, font);

            UE.GUI.color = color.ToUnityColor();

            UE.GUI.skin.textField.hover.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textField.active.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textField.focused.background = UnityWinForms.TransparentTexture;
            UE.GUI.skin.textField.normal.background = UnityWinForms.TransparentTexture;
            
            return UE.GUI.TextField(new UE.Rect(x, y, width, height), s);
        }
        
        private static int GUI_SetFont(UE.GUIStyle style, Font font)
        {
            int guiSkinFontSizeBuffer = style.fontSize;
            if (font != null)
            {
                if (font.fontObject == null && Unity.API.UnityWinForms.gResources != null)
                {
                    var fonts = Unity.API.UnityWinForms.gResources.Fonts;
                    if (fonts != null)
                        for (int i = 0; i < fonts.Count; i++)
                        {
                            var fontItem = fonts[i];
                            if (fontItem.fontNames[0] != font.Name) continue;

                            font.fontObject = fontItem;
                            break;
                        }
                }

                if (font.fontObject != null)
                    style.font = (UE.Font)font.fontObject;
                else
                {
                    style.font = null;
#if UNITY_EDITOR
                    UnityEngine.Debug.LogError("Font not found: " + font.Name);
#endif
                }

                var fontStyle = font.Style;
                style.fontSize = (int)font.Size;
                bool styleBold = (fontStyle & FontStyle.Bold) == FontStyle.Bold;
                bool styleItalic = (fontStyle & FontStyle.Italic) == FontStyle.Italic;
                if (styleBold)
                {
                    if (styleItalic)
                        style.fontStyle = UnityEngine.FontStyle.BoldAndItalic;
                    else
                        style.fontStyle = UnityEngine.FontStyle.Bold;
                }
                else if (styleItalic)
                    style.fontStyle = UnityEngine.FontStyle.Italic;
                else style.fontStyle = UnityEngine.FontStyle.Normal;
            }
            else
            {
                if (UnityWinForms.gResources.Fonts.Count > 0)
                {
                    var _font = UnityWinForms.gResources.Fonts[0];
                    if (_font != null)
                        style.font = _font;
                    style.fontSize = 12;
                    style.fontStyle = UnityEngine.FontStyle.Normal;
                }
            }
            return guiSkinFontSizeBuffer;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/FormClosingEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.ComponentModel;

    public enum CloseReason
    {
        None = 0,
        WindowsShutDown = 1,
        MdiFormClosing = 2,
        UserClosing = 3,
        TaskManagerClosing = 4,
        FormOwnerClosing = 5,
        ApplicationExitCall = 6,
    }

    public class FormClosingEventArgs : CancelEventArgs
    {
        public FormClosingEventArgs(CloseReason closeReason, bool cancel)
        {
            CloseReason = closeReason;
        }

        public CloseReason CloseReason { get; private set; }
    }
}


<|start_filename|>Assets/Controls/ColorPickerForm.cs<|end_filename|>
namespace System.Windows.Forms
{
    using System.Drawing;

    public class ColorPickerForm : Form
    {
        private new readonly Pen borderPen;
        private readonly AlphaPicker alphaPicker;
        private readonly ValueSaturationPicker vsPicker;
        private readonly HuePicker huePicker;

        private readonly Label aLabel;

        private readonly NumericUpDown hueNumeric;
        private readonly NumericUpDown saturationNumeric;
        private readonly NumericUpDown valueNumeric;

        private readonly NumericUpDown rNumeric;
        private readonly NumericUpDown gNumeric;
        private readonly NumericUpDown bNumeric;

        private readonly NumericUpDown aNumeric;

        private Color color;

        public ColorPickerForm()
        {
            borderPen = new Pen(Color.FromArgb(204, 206, 219));

            BackColor = Color.White;
            Size = new Size(188, 272);
            Location = new Point(
                Screen.PrimaryScreen.WorkingArea.Width / 2 - Width / 2,
                Screen.PrimaryScreen.WorkingArea.Height / 2 - Height / 2);
            FormBorderStyle = FormBorderStyle.FixedSingle;
            Text = "Pick a color";
            KeyPreview = true;
            TopMost = true;

            vsPicker = new ValueSaturationPicker(128, 128);
            vsPicker.Location = new Point(16, 32);
            vsPicker.ValueChanged += VsPickerValueChanged;
            vsPicker.SaturationChanged += VsPickerSaturationChanged;

            Controls.Add(vsPicker);

            huePicker = new HuePicker(20, 128);
            huePicker.Location = new Point(vsPicker.Location.X + vsPicker.Width + 8, vsPicker.Location.Y);
            huePicker.HueChanged += huePicker_HueChanged;

            Controls.Add(huePicker);

            var hueLabel = new Label();
            hueLabel.Text = "H:";
            hueLabel.Location = new Point(vsPicker.Location.X, vsPicker.Location.Y + vsPicker.Height + 8);
            var saturationLabel = new Label();
            saturationLabel.Text = "S:";
            saturationLabel.Location = new Point(hueLabel.Location.X, hueLabel.Location.Y + 22);
            var valueLabel = new Label();
            valueLabel.Text = "V:";
            valueLabel.Location = new Point(hueLabel.Location.X, saturationLabel.Location.Y + 22);

            Controls.Add(hueLabel);
            Controls.Add(saturationLabel);
            Controls.Add(valueLabel);

            hueNumeric = new NumericUpDown();
            hueNumeric.Minimum = 0;
            hueNumeric.Maximum = 359;
            hueNumeric.Increment = 5;
            hueNumeric.Location = new Point(hueLabel.Location.X + 24, hueLabel.Location.Y);
            hueNumeric.Size = new Size(50, 20);
            hueNumeric.ValueChanged += HueNumericValueChanged;
            hueNumeric.TextAlign = HorizontalAlignment.Center;
            saturationNumeric = new NumericUpDown();
            saturationNumeric.Minimum = 0;
            saturationNumeric.Maximum = 255;
            saturationNumeric.Location = new Point(saturationLabel.Location.X + 24, saturationLabel.Location.Y);
            saturationNumeric.Size = new Size(50, 20);
            saturationNumeric.ValueChanged += SaturationNumericValueChanged;
            saturationNumeric.TextAlign = HorizontalAlignment.Center;
            valueNumeric = new NumericUpDown();
            valueNumeric.Minimum = 0;
            valueNumeric.Maximum = 255;
            valueNumeric.Location = new Point(valueLabel.Location.X + 24, valueLabel.Location.Y);
            valueNumeric.Size = new Size(50, 20);
            valueNumeric.ValueChanged += ValueNumericValueChanged;
            valueNumeric.TextAlign = HorizontalAlignment.Center;

            Controls.Add(hueNumeric);
            Controls.Add(saturationNumeric);
            Controls.Add(valueNumeric);

            var rLabel = new Label();
            rLabel.Text = "R:";
            rLabel.Location = new Point(hueNumeric.Location.X + hueNumeric.Width + 8, hueLabel.Location.Y);
            var gLabel = new Label();
            gLabel.Text = "G:";
            gLabel.Location = new Point(rLabel.Location.X, saturationLabel.Location.Y);
            var bLabel = new Label();
            bLabel.Text = "B:";
            bLabel.Location = new Point(rLabel.Location.X, valueLabel.Location.Y);

            Controls.Add(rLabel);
            Controls.Add(gLabel);
            Controls.Add(bLabel);

            rNumeric = new NumericUpDown();
            rNumeric.Minimum = 0;
            rNumeric.Maximum = 255;
            rNumeric.Location = new Point(rLabel.Location.X + 24, rLabel.Location.Y);
            rNumeric.Size = new Size(50, 20);
            rNumeric.TextAlign = HorizontalAlignment.Center;
            rNumeric.ValueChanged += rNumeric_ValueChanged;
            gNumeric = new NumericUpDown();
            gNumeric.Minimum = 0;
            gNumeric.Maximum = 255;
            gNumeric.Location = new Point(gLabel.Location.X + 24, gLabel.Location.Y);
            gNumeric.Size = new Size(50, 20);
            gNumeric.TextAlign = HorizontalAlignment.Center;
            gNumeric.ValueChanged += gNumeric_ValueChanged;
            bNumeric = new NumericUpDown();
            bNumeric.Minimum = 0;
            bNumeric.Maximum = 255;
            bNumeric.Location = new Point(bLabel.Location.X + 24, bLabel.Location.Y);
            bNumeric.Size = new Size(50, 20);
            bNumeric.TextAlign = HorizontalAlignment.Center;
            bNumeric.ValueChanged += bNumeric_ValueChanged;

            Controls.Add(rNumeric);
            Controls.Add(gNumeric);
            Controls.Add(bNumeric);

            alphaPicker = new AlphaPicker(valueNumeric.Location.X + valueNumeric.Width - valueLabel.Location.X, 20);
            alphaPicker.Location = new Point(valueLabel.Location.X, valueLabel.Location.Y + 26);
            alphaPicker.AlphaChanged += alphaPicker_AlphaChanged;
            aLabel = new Label();
            aLabel.Location = new Point(bLabel.Location.X, alphaPicker.Location.Y);
            aLabel.Text = "A:";
            aNumeric = new NumericUpDown();
            aNumeric.Minimum = 0;
            aNumeric.Maximum = 255;
            aNumeric.Value = 255;
            aNumeric.Location = new Point(bNumeric.Location.X, aLabel.Location.Y);
            aNumeric.Size = new Size(50, 20);
            aNumeric.TextAlign = HorizontalAlignment.Center;
            aNumeric.ValueChanged += aNumeric_ValueChanged;

            Controls.Add(alphaPicker);
            Controls.Add(aLabel);
            Controls.Add(aNumeric);
        }

        public event EventHandler ColorChanged;

        public Color Color
        {
            get { return color; }
            set
            {
                if (color == value)
                    return;
                
                color = value;

                rNumeric.ValueChanged -= rNumeric_ValueChanged;
                rNumeric.Value = color.R;
                rNumeric.ValueChanged += rNumeric_ValueChanged;

                gNumeric.ValueChanged -= gNumeric_ValueChanged;
                gNumeric.Value = color.G;
                gNumeric.ValueChanged += gNumeric_ValueChanged;

                bNumeric.ValueChanged -= bNumeric_ValueChanged;
                bNumeric.Value = color.B;
                bNumeric.ValueChanged += bNumeric_ValueChanged;

                alphaPicker.Alpha = (float)color.A / 255;

                UpdateControlsFromRGB();
                
                OnColorChanged(EventArgs.Empty);
            }
        }

        protected virtual void OnColorChanged(EventArgs e)
        {
            var handler = ColorChanged;
            if (handler != null)
                handler(this, e);
        }
        protected override void OnKeyUp(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape || (e.KeyCode == Keys.W && e.Control))
                Close();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.DrawLine(borderPen, 1, uwfHeaderHeight - 1, Width - 1, uwfHeaderHeight - 1);
        }

        private void VsPickerValueChanged(object sender, EventArgs e)
        {
            valueNumeric.ValueChanged -= ValueNumericValueChanged;
            valueNumeric.Value = (int)(vsPicker.Value * 255);
            valueNumeric.ValueChanged += ValueNumericValueChanged;

            Color rgbColor = ColorTranslatorEx.FromHSV(huePicker.Hue * 359, vsPicker.Saturation, vsPicker.Value);

            rNumeric.ValueChanged -= rNumeric_ValueChanged;
            rNumeric.Value = rgbColor.R;
            rNumeric.ValueChanged += rNumeric_ValueChanged;
            gNumeric.ValueChanged -= gNumeric_ValueChanged;
            gNumeric.Value = rgbColor.G;
            gNumeric.ValueChanged += gNumeric_ValueChanged;
            bNumeric.ValueChanged -= bNumeric_ValueChanged;
            bNumeric.Value = rgbColor.B;
            bNumeric.ValueChanged += bNumeric_ValueChanged;

            color = Color.FromArgb((int)(alphaPicker.Alpha * 255), rgbColor);
            
            OnColorChanged(EventArgs.Empty);
        }
        private void VsPickerSaturationChanged(object sender, EventArgs e)
        {
            saturationNumeric.ValueChanged -= SaturationNumericValueChanged;
            saturationNumeric.Value = (int)(vsPicker.Saturation * 255);
            saturationNumeric.ValueChanged += SaturationNumericValueChanged;

            Color rgbColor = ColorTranslatorEx.FromHSV(huePicker.Hue * 359, vsPicker.Saturation, vsPicker.Value);

            rNumeric.ValueChanged -= rNumeric_ValueChanged;
            rNumeric.Value = rgbColor.R;
            rNumeric.ValueChanged += rNumeric_ValueChanged;
            gNumeric.ValueChanged -= gNumeric_ValueChanged;
            gNumeric.Value = rgbColor.G;
            gNumeric.ValueChanged += gNumeric_ValueChanged;
            bNumeric.ValueChanged -= bNumeric_ValueChanged;
            bNumeric.Value = rgbColor.B;
            bNumeric.ValueChanged += bNumeric_ValueChanged;

            color = Color.FromArgb((int)(alphaPicker.Alpha * 255), rgbColor);
            
            OnColorChanged(EventArgs.Empty);
        }
        private void huePicker_HueChanged(object sender, EventArgs e)
        {
            vsPicker.SetHue(huePicker.Hue);

            hueNumeric.ValueChanged -= HueNumericValueChanged;
            hueNumeric.Value = (int)((1f - huePicker.Hue) * 359);
            hueNumeric.ValueChanged += HueNumericValueChanged;

            Color rgbColor = ColorTranslatorEx.FromHSV(huePicker.Hue * 359, vsPicker.Saturation, vsPicker.Value);

            rNumeric.ValueChanged -= rNumeric_ValueChanged;
            rNumeric.Value = rgbColor.R;
            rNumeric.ValueChanged += rNumeric_ValueChanged;
            gNumeric.ValueChanged -= gNumeric_ValueChanged;
            gNumeric.Value = rgbColor.G;
            gNumeric.ValueChanged += gNumeric_ValueChanged;
            bNumeric.ValueChanged -= bNumeric_ValueChanged;
            bNumeric.Value = rgbColor.B;
            bNumeric.ValueChanged += bNumeric_ValueChanged;

            color = Color.FromArgb((int)(alphaPicker.Alpha * 255), rgbColor);
            
            OnColorChanged(EventArgs.Empty);
        }
        private void HueNumericValueChanged(object sender, EventArgs e)
        {
            huePicker.Hue = 1f - (float)hueNumeric.Value / 359f;
        }
        private void SaturationNumericValueChanged(object sender, EventArgs e)
        {
            vsPicker.Saturation = (float)saturationNumeric.Value / 255;
        }
        private void ValueNumericValueChanged(object sender, EventArgs e)
        {
            vsPicker.Value = (float)valueNumeric.Value / 255;
        }
        private void rNumeric_ValueChanged(object sender, EventArgs e)
        {
            UpdateControlsFromRGB();
        }
        private void gNumeric_ValueChanged(object sender, EventArgs e)
        {
            UpdateControlsFromRGB();
        }
        private void bNumeric_ValueChanged(object sender, EventArgs e)
        {
            UpdateControlsFromRGB();
        }
        private void alphaPicker_AlphaChanged(object sender, EventArgs e)
        {
            aNumeric.ValueChanged -= aNumeric_ValueChanged;
            aNumeric.Value = (int)(alphaPicker.Alpha * 255);
            aNumeric.ValueChanged += aNumeric_ValueChanged;

            color = Color.FromArgb((int)(alphaPicker.Alpha * 255), Color);
            
            OnColorChanged(EventArgs.Empty);
        }
        private void aNumeric_ValueChanged(object sender, EventArgs e)
        {
            alphaPicker.AlphaChanged -= alphaPicker_AlphaChanged;
            alphaPicker.Alpha = (float)Convert.ToDouble(aNumeric.Value / 255);
            alphaPicker.AlphaChanged += alphaPicker_AlphaChanged;

            color = Color.FromArgb((int)(alphaPicker.Alpha * 255), Color);
            
            OnColorChanged(EventArgs.Empty);
        }
        private void UpdateControlsFromRGB()
        {
            Color rgbColor = Color.FromArgb(Convert.ToInt32(rNumeric.Value), Convert.ToInt32(gNumeric.Value), Convert.ToInt32(bNumeric.Value));

            double hue;
            double saturation;
            double value;

            ColorTranslatorEx.ToHSV(rgbColor, out hue, out saturation, out value);
            hue /= 359;

            huePicker.HueChanged -= huePicker_HueChanged;
            huePicker.Hue = hue;
            huePicker.HueChanged += huePicker_HueChanged;
            vsPicker.SetHue(hue);
            vsPicker.ValueChanged -= VsPickerValueChanged;
            vsPicker.Value = (float)value;
            vsPicker.ValueChanged += VsPickerValueChanged;
            vsPicker.SaturationChanged -= VsPickerSaturationChanged;
            vsPicker.Saturation = (float)saturation;
            vsPicker.SaturationChanged += VsPickerSaturationChanged;

            hueNumeric.ValueChanged -= HueNumericValueChanged;
            hueNumeric.Value = Convert.ToInt32(hue * 359);
            hueNumeric.ValueChanged += HueNumericValueChanged;
            saturationNumeric.ValueChanged -= SaturationNumericValueChanged;
            saturationNumeric.Value = Convert.ToInt32(saturation * 255);
            saturationNumeric.ValueChanged += SaturationNumericValueChanged;
            valueNumeric.ValueChanged -= ValueNumericValueChanged;
            valueNumeric.Value = Convert.ToInt32(value * 255);
            valueNumeric.ValueChanged += ValueNumericValueChanged;

            rNumeric.ValueChanged -= rNumeric_ValueChanged;
            rNumeric.Value = rgbColor.R;
            rNumeric.ValueChanged += rNumeric_ValueChanged;
            gNumeric.ValueChanged -= gNumeric_ValueChanged;
            gNumeric.Value = rgbColor.G;
            gNumeric.ValueChanged += gNumeric_ValueChanged;
            bNumeric.ValueChanged -= bNumeric_ValueChanged;
            bNumeric.Value = rgbColor.B;
            bNumeric.ValueChanged += bNumeric_ValueChanged;

            color = Color.FromArgb((int)(alphaPicker.Alpha * 255), rgbColor);
            
            OnColorChanged(EventArgs.Empty);
        }

        private class ValueSaturationPicker : Button
        {
            private readonly Pen borderPen = new Pen(Color.White);
            private readonly Pen cursorPen = new Pen(Color.White);
            private readonly Bitmap image;

            private float value;
            private double hueValue;
            private bool mouseDown;
            private float saturation;

            public ValueSaturationPicker(int w, int h)
            {
                Size = new Size(w, h);

                image = new Bitmap(w, h);
                UpdateImage();

                MouseHook.MouseUp += MouseHookUpHandler;
            }

            public event EventHandler ValueChanged = delegate { };
            public event EventHandler SaturationChanged = delegate { };

            public float Value
            {
                get { return value; }
                set
                {
                    this.value = value;
                    ValueChanged(this, EventArgs.Empty);
                }
            }
            public float Saturation
            {
                get { return saturation; }
                set
                {
                    saturation = value;
                    SaturationChanged(this, EventArgs.Empty);
                }
            }

            public void SetHue(double value)
            {
                hueValue = value;
                UpdateImage();
            }

            protected override void Dispose(bool release_all)
            {
                MouseHook.MouseUp -= MouseHookUpHandler;

                base.Dispose(release_all);
            }
            protected override void OnMouseDown(MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                    mouseDown = true;
            }
            protected override void OnMouseMove(MouseEventArgs e)
            {
                if (mouseDown)
                {
                    Value = (float)(Height - e.Y) / Height;
                    Saturation = (float)e.X / Width;
                    if (Value < 0) Value = 0;
                    if (Value > 1) Value = 1;
                    if (Saturation < 0) Saturation = 0;
                    if (Saturation > 1) Saturation = 1;
                }
            }
            protected override void OnMouseUp(MouseEventArgs e)
            {
                UpdateValues();
                mouseDown = false;

                base.OnMouseUp(e);
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                if (image != null)
                    e.Graphics.DrawImage(image, 0, 0, Width, Height);

                e.Graphics.DrawRectangle(cursorPen, Saturation * Width - 2, Height - Value * Height - 2, 4, 4);

                var borderColor = uwfBorderColor;
                if (uwfHovered) borderColor = uwfBorderHoverColor;
                borderPen.Color = borderColor;

                e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
            }

            private void MouseHookUpHandler(object sender, MouseEventArgs e)
            {
                if (mouseDown)
                    UpdateValues();

                mouseDown = false;
            }
            private void UpdateImage()
            {
                double hue = hueValue;
                double saturation = 0f;
                double value = 1f;

                var imageWidth = image.Width;
                var imageHeight = image.Height;

                for (int i = 0; i < imageWidth; i++)
                {
                    saturation = (float)i / imageWidth;

                    for (int k = 0; k < imageHeight; k++)
                    {
                        value = (float)k / imageHeight;

                        // HSL to RGB convertion.
                        Color pixelColor = ColorTranslatorEx.FromHSV(hue * 359, saturation, value);
                        image.SetPixel(i, k, pixelColor);
                    }
                }

                image.Apply();
            }
            private void UpdateValues()
            {
                var mLoc = PointToClient(MousePosition);

                float mX = mLoc.X;
                float mY = mLoc.Y;

                if (mX < 0) mX = 0;
                else if (mX > Width) mX = Width;

                if (mY < 0) mY = 0;
                else if (mY > Height) mY = Height;

                Value = (float)(Height - mY) / Height;
                Saturation = (float)mX / Width;
                if (Value < 0) Value = 0;
                if (Value > 1) Value = 1;
                if (Saturation < 0) Saturation = 0;
                if (Saturation > 1) Saturation = 1;
            }
        }

        private class HuePicker : Button
        {
            private readonly Pen borderPen = new Pen(Color.White);
            private readonly Pen cursorPen = new Pen(Color.White);
            private readonly Bitmap image;

            private double hue;
            private bool mouseDown;

            public HuePicker(int w, int h)
            {
                Size = new Size(w, h);

                image = new Bitmap(w, h);
                UpdateImage();

                MouseHook.MouseUp += UwfAppOwnerOnUpClick;
            }

            public event EventHandler HueChanged = delegate { };

            public double Hue
            {
                get { return hue; }
                set
                {
                    hue = value;
                    UpdateImage();
                    HueChanged(this, EventArgs.Empty);
                }
            }

            protected override void Dispose(bool release_all)
            {
                MouseHook.MouseUp -= UwfAppOwnerOnUpClick;

                base.Dispose(release_all);
            }
            protected override void OnMouseDown(MouseEventArgs e)
            {
                mouseDown = true;

                base.OnMouseDown(e);
            }
            protected override void OnMouseUp(MouseEventArgs e)
            {
                mouseDown = false;

                Hue = 1f - (float)e.Y / Height;
                if (Hue < 0) Hue = 0;
                if (Hue > 1) Hue = 1;

                base.OnMouseUp(e);
            }
            protected override void OnMouseMove(MouseEventArgs e)
            {
                if (mouseDown)
                {
                    Hue = 1f - (float)e.Y / Height;
                    if (Hue < 0) Hue = 0;
                    if (Hue > 1) Hue = 1;
                }

                base.OnMouseMove(e);
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                var borderColor = uwfBorderColor;
                if (uwfHovered) borderColor = uwfBorderHoverColor;
                borderPen.Color = borderColor;

                if (image != null)
                    e.Graphics.DrawImage(image, 0, 0, Width, Height);

                e.Graphics.DrawLine(cursorPen, 0, (float)(1 - Hue) * Height, Width, (float)(1 - Hue) * Height);
                e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
            }

            private void UwfAppOwnerOnUpClick(object sender, MouseEventArgs mouseEventArgs)
            {
                mouseDown = false;
            }
            private void UpdateImage()
            {
                double hue = 0f;
                double saturation = .9f;
                double luminosity = .5f;

                var imageWidth = image.Width;
                var imageHeight = image.Height;

                for (int i = 0; i < imageWidth; i++)
                {
                    for (int k = 0; k < imageHeight; k++)
                    {
                        hue = (float)k / imageHeight;

                        // HSL to RGB convertion.
                        var pixelColor = ColorTranslatorEx.FromHsb(hue, saturation, luminosity);
                        image.SetPixel(i, k, pixelColor);
                    }
                }

                image.Apply();
            }
        }

        private class AlphaPicker : Button
        {
            private readonly Pen borderPen;
            private readonly Pen cursorPen;
            private readonly Bitmap image;

            private float alpha;
            private bool mouseDown;

            public AlphaPicker(int w, int h)
            {
                Alpha = 1;
                Size = new Size(w, h);

                borderPen = new Pen(uwfBorderColor);
                cursorPen = new Pen(Color.White);
                image = new Bitmap(w, h);
                for (int i = 0; i < w; i++)
                {
                    int rgb = (int)(((float)i / w) * 255);
                    var currentColor = Color.FromArgb(rgb, rgb, rgb);
                    for (int k = 0; k < h; k++)
                        image.SetPixel(i, k, currentColor);
                }
                image.Apply();
            }

            public event EventHandler AlphaChanged = delegate { };

            public float Alpha
            {
                get { return alpha; }
                set
                {
                    var changed = alpha != value;
                    if (changed)
                    {
                        alpha = value;
                        AlphaChanged(this, EventArgs.Empty);
                    }
                }
            }

            protected override void OnMouseDown(MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                    mouseDown = true;
            }
            protected override void OnMouseMove(MouseEventArgs e)
            {
                if (!mouseDown) return;

                Alpha = (float)e.X / Width;
                if (Alpha < 0) Alpha = 0;
                if (Alpha > 1) Alpha = 1;
            }
            protected override void OnMouseUp(MouseEventArgs e)
            {
                var mclient = PointToClient(MousePosition);
                var x = mclient.X;
                if (x <= 0) x = 0;
                if (x > Width) x = Width;

                Alpha = (float)x / Width;
                if (Alpha < 0) Alpha = 0;
                if (Alpha > 1) Alpha = 1;
                mouseDown = false;

                base.OnMouseUp(e);
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                var borderColor = uwfBorderColor;
                if (uwfHovered) borderColor = uwfBorderHoverColor;

                borderPen.Color = borderColor;

                if (image != null)
                    e.Graphics.DrawImage(image, 0, 0, Width, Height);

                e.Graphics.DrawLine(cursorPen, Alpha * Width, 0, Alpha * Width, Height);
                e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
            }
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/DragEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum DragDropEffects
    {
        Scroll = -2147483648,
        All = -2147483645,
        None = 0,
        Copy = 1,
        Move = 2,
        Link = 4,
    }

    public class DragEventArgs : EventArgs
    {
        public DragEventArgs(IDataObject data, int keyState, int x, int y, DragDropEffects allowedEffect, DragDropEffects effect)
        {
            this.Data = data;
            this.KeyState = keyState;
            this.X = x;
            this.Y = y;
            this.AllowedEffect = allowedEffect;
            this.Effect = effect;
        }

        public DragDropEffects AllowedEffect { get; private set; }
        public IDataObject Data { get; private set; }
        public DragDropEffects Effect { get; private set; }
        public int KeyState { get; private set; }
        public int X { get; private set; }
        public int Y { get; private set; }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ComboBoxStyle.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum ComboBoxStyle
    {
        Simple = 0,
        DropDown = 1,
        DropDownList = 2,
    }
}


<|start_filename|>Assets/System/Windows/Forms/RepeatButton.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    internal class RepeatButton : Button
    {
        private bool mdown = false;
        private bool repeatClick = false;
        private float repeatCooldown = 0;
        private float repeatCooldownCurrent = 0;
        private bool repeatStarted;
        private float cooldownBetweenClicks = .1f;
        private float waitCooldown = .4f;

        public RepeatButton()
        {
            MouseHook.MouseUp += Owner_UpClick;
            Application.UpdateEvent += ApplicationOnUpdateEvent;
        }

        public float CooldownBetweenClicks
        {
            get { return cooldownBetweenClicks; }
            set { cooldownBetweenClicks = value; }
        }
        /// <summary>
        /// After first click.
        /// </summary>
        public float WaitCooldown
        {
            get { return waitCooldown; }
            set { waitCooldown = value; }
        }

        internal override void RaiseOnMouseClick(MouseEventArgs e)
        {
            // We want to prevent clicking a button after MouseUp event. So it wont be double clicking thing.
            if (repeatStarted == false)
                base.RaiseOnMouseClick(e);
        }

        protected override void Dispose(bool release_all)
        {
            MouseHook.MouseUp -= Owner_UpClick;
            Application.UpdateEvent -= ApplicationOnUpdateEvent;

            base.Dispose(release_all);
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == MouseButtons.Left && e.Clicks >= 1)
                StartRepeat();
        }
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            
            if (e.Button == MouseButtons.Left)
                StartRepeat();
        }
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            if (mdown)
            {
                repeatClick = true;
                repeatCooldown = waitCooldown;
                repeatCooldownCurrent = repeatCooldown;
            }
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            repeatClick = false;
        }

        private void Owner_UpClick(object sender, MouseEventArgs e)
        {
            mdown = false;
            repeatClick = false;
            repeatStarted = false;
        }
        private void ApplicationOnUpdateEvent()
        {
            if (!repeatClick) return;

            if (repeatCooldownCurrent <= 0)
            {
                repeatStarted = true;

                PerformClick();

                repeatCooldown = cooldownBetweenClicks;
                repeatCooldownCurrent = repeatCooldown;
            }
            else
                repeatCooldownCurrent -= swfHelper.GetDeltaTime();
        }
        private void StartRepeat()
        {
            mdown = true;
            repeatClick = true;
            repeatCooldown = waitCooldown;
            repeatCooldownCurrent = repeatCooldown;
        }
    }
}


<|start_filename|>Assets/Controls/Highcharts/YAxis.cs<|end_filename|>
﻿namespace Highcharts
{
    using System.Drawing;

    public class YAxis : Axis
    {
        public YAxis() : base(false)
        {
            gridLineColor = Color.FromArgb(0xE6, 0xE6, 0xE6);
            gridLineWidth = 1;
            lineColor = Color.FromArgb(0xCC, 0xD6, 0xEB);
            lineWidth = 0;
            tickColor = Color.FromArgb(0xCC, 0xD6, 0xEB);
            tickWidth = 0;
        }
    }
}


<|start_filename|>Assets/System/Drawing/SystemPens.cs<|end_filename|>
﻿namespace System.Drawing
{
    public static class SystemPens
    {
        private static Pen activeBorder;
        private static Pen activeCaption;
        private static Pen activeCaptionText;
        private static Pen appWorkspace;
        private static Pen buttonFace;
        private static Pen buttonHighlight;
        private static Pen buttonShadow;
        private static Pen control;
        private static Pen controlText;
        private static Pen controlDark;
        private static Pen controlDarkDark;
        private static Pen controlLight;
        private static Pen controlLightLight;
        private static Pen desktop;
        private static Pen gradientActiveCaption;
        private static Pen gradientInactiveCaption;
        private static Pen grayText;
        private static Pen highlight;
        private static Pen highlightText;
        private static Pen hotTrack;
        private static Pen inactiveBorder;
        private static Pen inactiveCaption;
        private static Pen inactiveCaptionText;
        private static Pen info;
        private static Pen infoText;
        private static Pen menu;
        private static Pen menuBar;
        private static Pen menuHighlight;
        private static Pen menuText;
        private static Pen scrollBar;
        private static Pen window;
        private static Pen windowFrame;
        private static Pen windowText;

        public static Pen ActiveBorder
        {
            get
            {
                if (activeBorder == null)
                    activeBorder = new Pen(SystemColors.ActiveBorder);

                return activeBorder;
            }
        }
        public static Pen ActiveCaption
        {
            get
            {
                if (activeCaption == null)
                    activeCaption = new Pen(SystemColors.ActiveCaption);

                return activeCaption;
            }
        }
        public static Pen ActiveCaptionText
        {
            get
            {
                if (activeCaptionText == null)
                    activeCaptionText = new Pen(SystemColors.ActiveCaptionText);

                return activeCaptionText;
            }
        }
        public static Pen AppWorkspace
        {
            get
            {
                if (appWorkspace == null)
                    appWorkspace = new Pen(SystemColors.AppWorkspace);

                return appWorkspace;
            }
        }
        public static Pen ButtonFace
        {
            get
            {
                if (buttonFace == null)
                    buttonFace = new Pen(SystemColors.ButtonFace);

                return buttonFace;
            }
        }
        public static Pen ButtonHighlight
        {
            get
            {
                if (buttonHighlight == null)
                    buttonHighlight = new Pen(SystemColors.ButtonHighlight);

                return buttonHighlight;
            }
        }
        public static Pen ButtonShadow
        {
            get
            {
                if (buttonShadow == null)
                    buttonShadow = new Pen(SystemColors.ButtonShadow);

                return buttonShadow;
            }
        }
        public static Pen Control
        {
            get
            {
                if (control == null)
                    control = new Pen(SystemColors.Control);

                return control;
            }
        }
        public static Pen ControlText
        {
            get
            {
                if (controlText == null)
                    controlText = new Pen(SystemColors.ControlText);

                return controlText;
            }
        }
        public static Pen ControlDark
        {
            get
            {
                if (controlDark == null)
                    controlDark = new Pen(SystemColors.ControlDark);

                return controlDark;
            }
        }
        public static Pen ControlDarkDark
        {
            get
            {
                if (controlDarkDark == null)
                    controlDarkDark = new Pen(SystemColors.ControlDarkDark);

                return controlDarkDark;
            }
        }
        public static Pen ControlLight
        {
            get
            {
                if (controlLight == null)
                    controlLight = new Pen(SystemColors.ControlLight);

                return controlLight;
            }
        }
        public static Pen ControlLightLight
        {
            get
            {
                if (controlLightLight == null)
                    controlLightLight = new Pen(SystemColors.ControlLightLight);

                return controlLightLight;
            }
        }
        public static Pen Desktop
        {
            get
            {
                if (desktop == null)
                    desktop = new Pen(SystemColors.Desktop);

                return desktop;
            }
        }
        public static Pen GradientActiveCaption
        {
            get
            {
                if (gradientActiveCaption == null)
                    gradientActiveCaption = new Pen(SystemColors.GradientActiveCaption);

                return gradientActiveCaption;
            }
        }
        public static Pen GradientInactiveCaption
        {
            get
            {
                if (gradientInactiveCaption == null)
                    gradientInactiveCaption = new Pen(SystemColors.GradientInactiveCaption);

                return gradientInactiveCaption;
            }
        }
        public static Pen GrayText
        {
            get
            {
                if (grayText == null)
                    grayText = new Pen(SystemColors.GrayText);

                return grayText;
            }
        }
        public static Pen Highlight
        {
            get
            {
                if (highlight == null)
                    highlight = new Pen(SystemColors.Highlight);

                return highlight;
            }
        }
        public static Pen HighlightText
        {
            get
            {
                if (highlightText == null)
                    highlightText = new Pen(SystemColors.HighlightText);

                return highlightText;
            }
        }
        public static Pen HotTrack
        {
            get
            {
                if (hotTrack == null)
                    hotTrack = new Pen(SystemColors.HotTrack);

                return hotTrack;
            }
        }
        public static Pen InactiveBorder
        {
            get
            {
                if (inactiveBorder == null)
                    inactiveBorder = new Pen(SystemColors.InactiveBorder);

                return inactiveBorder;
            }
        }
        public static Pen InactiveCaption
        {
            get
            {
                if (inactiveCaption == null)
                    inactiveCaption = new Pen(SystemColors.InactiveCaption);

                return inactiveCaption;
            }
        }
        public static Pen InactiveCaptionText
        {
            get
            {
                if (inactiveCaptionText == null)
                    inactiveCaptionText = new Pen(SystemColors.InactiveCaptionText);

                return inactiveCaptionText;
            }
        }
        public static Pen Info
        {
            get
            {
                if (info == null)
                    info = new Pen(SystemColors.Info);

                return info;
            }
        }
        public static Pen InfoText
        {
            get
            {
                if (infoText == null)
                    infoText = new Pen(SystemColors.InfoText);

                return infoText;
            }
        }
        public static Pen Menu
        {
            get
            {
                if (menu == null)
                    menu = new Pen(SystemColors.Menu);

                return menu;
            }
        }
        public static Pen MenuBar
        {
            get
            {
                if (menuBar == null)
                    menuBar = new Pen(SystemColors.MenuBar);

                return menuBar;
            }
        }
        public static Pen MenuHighlight
        {
            get
            {
                if (menuHighlight == null)
                    menuHighlight = new Pen(SystemColors.MenuHighlight);

                return menuHighlight;
            }
        }
        public static Pen MenuText
        {
            get
            {
                if (menuText == null)
                    menuText = new Pen(SystemColors.MenuText);

                return menuText;
            }
        }
        public static Pen ScrollBar
        {
            get
            {
                if (scrollBar == null)
                    scrollBar = new Pen(SystemColors.ScrollBar);
                
                return scrollBar;
            }
        }
        public static Pen Window
        {
            get
            {
                if (window == null)
                    window = new Pen(SystemColors.Window);

                return window;
            }
        }
        public static Pen WindowFrame
        {
            get
            {
                if (windowFrame == null)
                    windowFrame = new Pen(SystemColors.WindowFrame);

                return windowFrame;
            }
        }
        public static Pen WindowText
        {
            get
            {
                if (windowText == null)
                    windowText = new Pen(SystemColors.WindowText);

                return windowText;
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripItemClickedEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void ToolStripItemClickedEventHandler(object sender, ToolStripItemClickedEventArgs e);
}


<|start_filename|>Assets/Examples/Panels/PanelFileDialog.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelFileDialog : BaseExamplePanel
    {
        public override void Initialize()
        {
            var labelFilter = this.Create<Label>("Filter:");
            var textFilter = this.Create<TextBox>();
            textFilter.Text = "All files|*.*";
            textFilter.Width = 320;
            
            var labelPath = this.Create<Label>("Selected path");
            var buttonOpen = this.Create<Button>("Open");
            var buttonSave = this.Create<Button>("Save");

            buttonOpen.Click += (sender, args) =>
            {
                var ofd = new OpenFileDialog();
                ofd.Filter = textFilter.Text;
                ofd.InitialDirectory = "C:\\";
                ofd.ShowDialog(
                    (form, result) =>
                    {
                        if (result == DialogResult.OK)
                            labelPath.Text = ofd.FileName;
                    });
            };
            buttonSave.Click += (sender, args) =>
            {
                var sfd = new SaveFileDialog();
                sfd.Filter = textFilter.Text;
                sfd.ShowDialog(
                    (form, result) =>
                    {
                        if (result == DialogResult.OK)
                            labelPath.Text = sfd.FileName;
                    });
            };
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/NativeMethods.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    internal static class NativeMethods
    {
        public const int BDR_RAISEDINNER = 0x0004,
                         BDR_RAISEDOUTER = 0x0001,
                         BDR_SUNKENINNER = 0x0008,
                         BDR_SUNKENOUTER = 0x0002,
                         BF_LEFT = 0x0001,
                         BF_TOP = 0x0002,
                         BF_RIGHT = 0x0004,
                         BF_BOTTOM = 0x0008,
                         BF_ADJUST = 0x2000,
                         BF_FLAT = 0x4000,
                         BF_MIDDLE = 0x0800,
                         EDGE_BUMP = 0x0001 | 0x0008,
                         EDGE_ETCHED = 0x0002 | 0x0004,
                         EDGE_RAISED = 0x0001 | 0x0004,
                         EDGE_SUNKEN = 0x0002 | 0x0008;

        public const int WHEEL_DELTA = 120,
                         WM_PARENTNOTIFY = 0x0210,
                         WM_ENTERMENULOOP = 0x0211,
                         WM_EXITMENULOOP = 0x0212,
                         WM_NEXTMENU = 0x0213,
                         WM_SIZING = 0x0214,
                         WM_CAPTURECHANGED = 0x0215,
                         WM_MOVING = 0x0216,
                         WM_POWERBROADCAST = 0x0218,
                         WM_DEVICECHANGE = 0x0219,
                         WM_IME_SETCONTEXT = 0x0281,
                         WM_IME_NOTIFY = 0x0282,
                         WM_IME_CONTROL = 0x0283,
                         WM_IME_COMPOSITIONFULL = 0x0284,
                         WM_IME_SELECT = 0x0285,
                         WM_IME_CHAR = 0x0286,
                         WM_IME_KEYDOWN = 0x0290,
                         WM_IME_KEYUP = 0x0291,
                         WM_MDICREATE = 0x0220,
                         WM_MDIDESTROY = 0x0221,
                         WM_MDIACTIVATE = 0x0222,
                         WM_MDIRESTORE = 0x0223,
                         WM_MDINEXT = 0x0224,
                         WM_MDIMAXIMIZE = 0x0225,
                         WM_MDITILE = 0x0226,
                         WM_MDICASCADE = 0x0227,
                         WM_MDIICONARRANGE = 0x0228,
                         WM_MDIGETACTIVE = 0x0229,
                         WM_MDISETMENU = 0x0230,
                         WM_ENTERSIZEMOVE = 0x0231,
                         WM_EXITSIZEMOVE = 0x0232,
                         WM_DROPFILES = 0x0233,
                         WM_MDIREFRESHMENU = 0x0234,
                         WM_MOUSEHOVER = 0x02A1,
                         WM_MOUSELEAVE = 0x02A3,
                         WM_CUT = 0x0300,
                         WM_COPY = 0x0301,
                         WM_PASTE = 0x0302,
                         WM_CLEAR = 0x0303,
                         WM_UNDO = 0x0304,
                         WM_RENDERFORMAT = 0x0305,
                         WM_RENDERALLFORMATS = 0x0306,
                         WM_DESTROYCLIPBOARD = 0x0307,
                         WM_DRAWCLIPBOARD = 0x0308,
                         WM_PAINTCLIPBOARD = 0x0309,
                         WM_VSCROLLCLIPBOARD = 0x030A,
                         WM_SIZECLIPBOARD = 0x030B,
                         WM_ASKCBFORMATNAME = 0x030C,
                         WM_CHANGECBCHAIN = 0x030D,
                         WM_HSCROLLCLIPBOARD = 0x030E,
                         WM_QUERYNEWPALETTE = 0x030F,
                         WM_PALETTEISCHANGING = 0x0310,
                         WM_PALETTECHANGED = 0x0311,
                         WM_HOTKEY = 0x0312,
                         WM_PRINT = 0x0317,
                         WM_PRINTCLIENT = 0x0318,
                         WM_THEMECHANGED = 0x031A,
                         WM_HANDHELDFIRST = 0x0358,
                         WM_HANDHELDLAST = 0x035F,
                         WM_AFXFIRST = 0x0360,
                         WM_AFXLAST = 0x037F,
                         WM_PENWINFIRST = 0x0380,
                         WM_PENWINLAST = 0x038F,
                         WM_APP = 0x8000,
                         WM_USER = 0x0400,
                         WM_REFLECT = WM_USER + 0x1C00,
                         WS_OVERLAPPED = 0x00000000,
                         WS_POPUP = unchecked((int)0x80000000),
                         WS_CHILD = 0x40000000,
                         WS_MINIMIZE = 0x20000000,
                         WS_VISIBLE = 0x10000000,
                         WS_DISABLED = 0x08000000, // preventing auto-focus atm.
                         WS_CLIPSIBLINGS = 0x04000000,
                         WS_CLIPCHILDREN = 0x02000000,
                         WS_MAXIMIZE = 0x01000000,
                         WS_CAPTION = 0x00C00000,
                         WS_BORDER = 0x00800000,
                         WS_DLGFRAME = 0x00400000,
                         WS_VSCROLL = 0x00200000,
                         WS_HSCROLL = 0x00100000,
                         WS_SYSMENU = 0x00080000,
                         WS_THICKFRAME = 0x00040000,
                         WS_TABSTOP = 0x00010000,
                         WS_MINIMIZEBOX = 0x00020000,
                         WS_MAXIMIZEBOX = 0x00010000,
                         WS_EX_DLGMODALFRAME = 0x00000001,
                         WS_EX_MDICHILD = 0x00000040,
                         WS_EX_TOOLWINDOW = 0x00000080,
                         WS_EX_CLIENTEDGE = 0x00000200,
                         WS_EX_CONTEXTHELP = 0x00000400,
                         WS_EX_RIGHT = 0x00001000,
                         WS_EX_LEFT = 0x00000000,
                         WS_EX_RTLREADING = 0x00002000,
                         WS_EX_LEFTSCROLLBAR = 0x00004000,
                         WS_EX_CONTROLPARENT = 0x00010000,
                         WS_EX_STATICEDGE = 0x00020000,
                         WS_EX_APPWINDOW = 0x00040000,
                         WS_EX_LAYERED = 0x00080000,
                         WS_EX_TOPMOST = 0x00000008,
                         WS_EX_LAYOUTRTL = 0x00400000,
                         WS_EX_NOINHERITLAYOUT = 0x00100000,
                         WPF_SETMINPOSITION = 0x0001,
                         WM_CHOOSEFONT_GETLOGFONT = 0x0400 + 1;

        public const int SB_HORZ = 0,
                         SB_VERT = 1;
    }
}


<|start_filename|>Assets/System/Windows/Forms/TabAlignment.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum TabAlignment
    {
        Top = 0,
        Bottom = 1,
        Left = 2,
        Right = 3,
    }
}


<|start_filename|>Assets/System/Windows/Forms/LayoutEventHandler.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public delegate void LayoutEventHandler(object sender, LayoutEventArgs e);
}

<|start_filename|>Assets/System/Drawing/SizeF.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Globalization;
    
    public struct SizeF : IEquatable<SizeF>
    {
        public static readonly SizeF Empty = new SizeF();

        public static explicit operator PointF(SizeF size)
        {
            return new PointF(size.Width, size.Height);
        }

        public static SizeF operator +(SizeF sz1, SizeF sz2)
        {
            return Add(sz1, sz2);
        }
        public static SizeF operator -(SizeF sz1, SizeF sz2)
        {
            return Subtract(sz1, sz2);
        }
        public static bool operator ==(SizeF sz1, SizeF sz2)
        {
            return sz1.Width == sz2.Width && sz1.Height == sz2.Height;
        }
        public static bool operator !=(SizeF sz1, SizeF sz2)
        {
            return !(sz1 == sz2);
        }

        public float Height { get; set; }
        public bool IsEmpty
        {
            get { return Width == 0 && Height == 0; }
        }
        public float Width { get; set; }

        public SizeF(SizeF size) : this()
        {
            Width = size.Width;
            Height = size.Height;
        }
        public SizeF(PointF pt) : this()
        {
            Width = pt.X;
            Height = pt.Y;
        }
        public SizeF(float width, float height) : this()
        {
            this.Width = width;
            this.Height = height;
        }

        public bool Equals(SizeF other)
        {
            return Width.Equals(other.Width) && Height.Equals(other.Height);
        }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            return obj is SizeF && Equals((SizeF) obj);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public PointF ToPointF()
        {
            return (PointF)this;
        }
        public Size ToSize()
        {
            return Size.Truncate(this);
        }
        public override string ToString()
        {
            return "{Width=" + Width.ToString(CultureInfo.CurrentCulture) + ", Height=" + Height.ToString(CultureInfo.CurrentCulture) + "}";
        }

        public static SizeF Add(SizeF sz1, SizeF sz2)
        {
            return new SizeF(sz1.Width + sz2.Width, sz1.Height + sz2.Height);
        }   
        public static SizeF Subtract(SizeF sz1, SizeF sz2)
        {
            return new SizeF(sz1.Width - sz2.Width, sz1.Height - sz2.Height);
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/Screen.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public class Screen
    {
        internal static int height;
        internal static int width;

        private static Screen primaryScreen;
        private Rectangle workingArea;

        public static Screen PrimaryScreen
        {
            get
            {
                if (primaryScreen == null)
                {
                    primaryScreen = new Screen();
                    primaryScreen.workingArea = new Rectangle(0, 0, width, height);
                }
                else
                {
                    if (primaryScreen.workingArea.Width != width ||
                        primaryScreen.workingArea.Height != height)
                        primaryScreen.workingArea = new Rectangle(0, 0, width, height);
                }
                return primaryScreen;
            }
        }
        public Rectangle WorkingArea { get { return workingArea; } }
    }
}


<|start_filename|>Assets/System/Windows/Forms/PictureBox.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.ComponentModel;
    using System.Drawing;

    public class PictureBox : Control, ISupportInitialize
    {
        public PictureBox()
        {
            BorderStyle = BorderStyle.None;
        }

        public BorderStyle BorderStyle { get; set; }
        public Bitmap Image { get; set; }

        protected override Size DefaultSize
        {
            get { return new Size(100, 50); }
        }

        public void BeginInit()
        {
            // ImageLocation not supported yet.
        }
        public void EndInit()
        {
            // ImageLocation not supported yet.
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;

            var image = Image;
            if (image != null) // TODO: Animate image.
                g.DrawImage(image, 0, 0, image.Width, image.Height);

            ControlPaint.PrintBorder(g, ClientRectangle, BorderStyle, Border3DStyle.Sunken);

            base.OnPaint(e);
        }
    }
}


<|start_filename|>Assets/System/Drawing/Point.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Globalization;
    
    public struct Point : IEquatable<Point>
    {
        public static readonly Point Empty = new Point();

        public Point(int x, int y) : this()
        {
            X = x;
            Y = y;
        }
        public Point(Size sz) : this()
        {
            X = sz.Width;
            Y = sz.Height;
        }
        public Point(int dw) : this()
        {
            unchecked
            {
                X = (short)LOWORD(dw);
                Y = (short)HIWORD(dw);
            }
        }

        public bool IsEmpty
        {
            get { return X == 0 && Y == 0; }
        }
        public int X { get; set; }
        public int Y { get; set; }

        public static implicit operator PointF(Point p)
        {
            return new PointF(p.X, p.Y);
        }
        public static explicit operator Size(Point p)
        {
            return new Size(p.X, p.Y);
        }

        public static Point operator +(Point pt, Size sz)
        {
            return Add(pt, sz);
        }    
        public static Point operator -(Point pt, Size sz)
        {
            return Subtract(pt, sz);
        }
        public static bool operator ==(Point left, Point right)
        {
            return left.X == right.X && left.Y == right.Y;
        }
        public static bool operator !=(Point left, Point right)
        {
            return !(left == right);
        }

        public static Point Add(Point pt, Size sz)
        {
            return new Point(pt.X + sz.Width, pt.Y + sz.Height);
        }
        public static Point Ceiling(PointF value)
        {
            return new Point((int)Math.Ceiling(value.X), (int)Math.Ceiling(value.Y));
        }
        public static Point Round(PointF value)
        {
            return new Point((int)Math.Round(value.X), (int)Math.Round(value.Y));
        }
        public static Point Subtract(Point pt, Size sz)
        {
            return new Point(pt.X - sz.Width, pt.Y - sz.Height);
        }
        public static Point Truncate(PointF value)
        {
            return new Point((int)value.X, (int)value.Y);
        }

        public bool Equals(Point other)
        {
            return X == other.X && Y == other.Y;
        }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            return obj is Point && Equals((Point)obj);
        }
        public override int GetHashCode()
        {
            return X ^ Y;
        }
        public void Offset(int dx, int dy)
        {
            X += dx;
            Y += dy;
        }
        public void Offset(Point point)
        {
            X += point.X;
            Y += point.Y;
        }
        public override string ToString()
        {
            return "{X=" + X.ToString(CultureInfo.CurrentCulture) + ",Y=" + Y.ToString(CultureInfo.CurrentCulture) + " }";
        }

        private static int HIWORD(int n)
        {
            return (n >> 16) & 0xffff;
        }
        private static int LOWORD(int n)
        {
            return n & 0xffff;
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelProgressBar.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelProgressBar : BaseExamplePanel
    {
        private Timer timer;

        public override void Initialize()
        {
            var labelMarqueeText = "Marguee. Value: ";
            var labelMarquee = this.Create<Label>(labelMarqueeText);

            var progressBarMarquee = this.Create<ProgressBar>();
            progressBarMarquee.Style = ProgressBarStyle.Marquee;

            var labelBlocksText = "Blocks. Value: ";
            var labelBlocks = this.Create<Label>(labelBlocksText, false, 8, lineOffset);

            var progressBarBlocks = this.Create<ProgressBar>();
            progressBarBlocks.Style = ProgressBarStyle.Blocks;

            timer = new Timer();
            timer.Interval = 100;
            timer.Tick += (sender, args) =>
            {
                var nextValue = progressBarMarquee.Value + 1;
                if (nextValue > progressBarMarquee.Maximum)
                    nextValue = 0;

                progressBarMarquee.Value = nextValue;
                progressBarBlocks.Value = nextValue;

                labelMarquee.Text = labelMarqueeText + progressBarMarquee.Value;
                labelBlocks.Text = labelBlocksText + progressBarBlocks.Value;
            };
            timer.Start();
        }

        protected override void Dispose(bool release_all)
        {
            base.Dispose(release_all);

            if (timer != null)
                timer.Dispose();
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/SystemInformation.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    public static class SystemInformation
    {
        private static Size border3DSize = new Size(2, 2);
        private static int captionHeight = 24; // 23 original + 1 px form border.
        private static int horizontalScrollBarArrowWidth = 17;
        private static int horizontalScrollBarHeight = 15; // 17 original (1px left border + 1px right padding?), same for vertical. 
        private static int mouseWheelScrollLines = 3;
        private static int verticalScrollBarArrowHeight = 17;
        private static int verticalScrollBarWidth = 15;
        
        public static Size Border3DSize
        {
            get { return border3DSize; }
            internal set { border3DSize = value; }
        }
        public static int CaptionHeight
        {
            get { return captionHeight; }
            internal set { captionHeight = value; }
        }
        public static bool HighContrast { get; internal set; }
        public static int HorizontalScrollBarArrowWidth
        {
            get { return horizontalScrollBarArrowWidth; }
            internal set { horizontalScrollBarArrowWidth = value; }
        }
        public static int HorizontalScrollBarHeight
        {
            get { return horizontalScrollBarHeight; }
            internal set { horizontalScrollBarHeight = value; }
        }
        public static int MouseWheelScrollLines
        {
            get { return mouseWheelScrollLines; }
            internal set { mouseWheelScrollLines = value; }
        }
        public static int VerticalScrollBarArrowHeight
        {
            get { return verticalScrollBarArrowHeight; }
            internal set { verticalScrollBarArrowHeight = value; }
        }
        public static int VerticalScrollBarWidth
        {
            get { return verticalScrollBarWidth; }
            internal set { verticalScrollBarWidth = value; }
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelTrackBar.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Drawing;
    using System.Windows.Forms;
    
    public class PanelTrackBar : BaseExamplePanel
    {
        public override void Initialize()
        {
            var label = this.Create<Label>("Value: ");
            var track = this.Create<TrackBar>();
            track.Orientation = Orientation.Vertical;
            track.TickStyle = TickStyle.Both;
            track.ValueChanged += (sender, args) => label.Text = "Value: "+ track.Value;
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/IResizableControl.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Drawing;

    [Flags]
    public enum ControlResizeTypes
    {
        None = 0,

        Right = 1,
        Down = 2,
        Left = 4,
        Up = 8,

        DownUp = Down | Up,
        RightDown = Right | Down,
        LeftDown = Left | Down,
        LeftRight = Left | Right,
        LeftUp = Left | Up,
        RightUp = Right | Up,
    }

    public interface IResizableControl
    {
        /// <summary>
        /// Updates cursor type depending on resize type.
        /// </summary>
        /// <param name="mclient">Relative mouse position to client</param>
        /// <returns></returns>
        ControlResizeTypes GetResizeAt(Point mclient);
    }
}


<|start_filename|>Assets/System/Windows/Forms/TreeViewAction.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum TreeViewAction
    {
        Unknown = 0,
        ByKeyboard = 1,
        ByMouse = 2,
        Collapse = 3,
        Expand = 4,
    }
}


<|start_filename|>Assets/System/Drawing/SystemFonts.cs<|end_filename|>
﻿namespace System.Drawing
{
    public static class SystemFonts
    {
        public static readonly Font CaptionFont = new Font("Segoe UI", 11.25f);
        public static readonly Font DefaultFont = new Font("Microsoft Sans Serif", 8.25f);
        public static readonly Font DialogFont = new Font("Tahoma", 8);
        public static readonly Font IconTitleFont = new Font("Segoe UI", 9);
        public static readonly Font MenuFont = new Font("Segoe UI", 9);
        public static readonly Font MessageBoxFont = new Font("Segoe UI", 9);
        public static readonly Font SmallCaptionFont = new Font("Segoe UI", 11.25f);
        public static readonly Font StatusFont = new Font("Segoe UI", 9);

        internal static readonly Font uwfArial_10 = new Font("Arial", 10);
        internal static readonly Font uwfArial_12 = new Font("Arial", 12);
        internal static readonly Font uwfArial_14 = new Font("Arial", 14);
        internal static readonly Font uwfArial_16 = new Font("Arial", 16);
    }
}


<|start_filename|>Assets/Core/API/IApiInput.cs<|end_filename|>
﻿namespace System.Drawing.API
{
    public interface IApiInput
    {
        bool CursorVisible { get; set; }
    }
}

<|start_filename|>Assets/Controls/Highcharts/LegendItemStyle.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Drawing;

    public struct LegendItemStyle : IEquatable<LegendItemStyle>
    {
        public readonly Color color;
        public readonly Font font;

        public LegendItemStyle(Color color)
        {
            this.color = color;
            font = Highchart.DefaultFont12B;
        }

        public bool Equals(LegendItemStyle other)
        {
            return color.Equals(other.color) && Equals(font, other.font);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            return obj is LegendItemStyle && Equals((LegendItemStyle)obj);
        }
        public override int GetHashCode()
        {
            unchecked
            {
                return (color.GetHashCode() * 397) ^ (font != null ? font.GetHashCode() : 0);
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripDropDownItem.cs<|end_filename|>
namespace System.Windows.Forms
{
    using System.Drawing;

    public class ToolStripDropDownItem : ToolStripItem
    {
        private readonly ToolStripItemCollection dropDownItems;
        private ToolStripDropDown dropDownToolStrip;
        private ToolStripDropDown userDropDown;
        private float mouseHoverTime;
        private bool pressed;

        protected ToolStripDropDownItem()
        {
            dropDownItems = new ToolStripItemCollection(Parent, null);

            ArrowColor = Color.Black;
            ArrowImage = ApplicationResources.Images.DropDownRightArrow;
        }

        internal delegate void uwfDropDownHandler(ToolStripDropDown dropDown);
        internal event uwfDropDownHandler uwfDropDownCreated; // Workaround to not implement ToolStripRenderer.
        
        public ToolStripDropDown DropDown
        {
            get { return dropDownToolStrip; }
            set { userDropDown = value; }
        }
        public ToolStripItemCollection DropDownItems { get { return dropDownItems; } }
        public override bool Pressed
        {
            get
            {
                return pressed;
            }
        }

        internal Color ArrowColor { get; set; }
        internal Bitmap ArrowImage { get; set; }

        internal void CloseEverything()
        {
            // Self
            var parent = Owner as ToolStripDropDown;
            if (parent != null)
            {
                parent.Dispose();

                var parentItem = parent.OwnerItem as ToolStripDropDownItem;
                if (parentItem != null)
                    parentItem.CloseEverything();
            }
        }
        internal void CloseToolStrip()
        {
            if (dropDownToolStrip == null)
                return;

            if (dropDownToolStrip.IsDisposed == false)
                dropDownToolStrip.Dispose();
        }
        internal void CreateToolStrip()
        {
            if (Enabled == false)
                return;

            if (dropDownItems.Count == 0)
                return;

            var dropDownBounds = new Rectangle(Point.Empty, Owner.Size);

            for (int i = 0; i < dropDownItems.Count; i++) // Reset items.
            {
                var item = dropDownItems[i];
                item.Unselect();

                var dropDownItem = item as ToolStripDropDownItem;
                if (dropDownItem == null) continue;

                dropDownItem.ArrowImage = ApplicationResources.Images.DropDownRightArrow;
                dropDownItem.ArrowColor = Color.Black;
            }

            var direction = ToolStripDropDownDirection.Right;
            if (Owner.IsDropDown == false)
                direction = ToolStripDropDownDirection.BelowRight;
            
            dropDownToolStrip = userDropDown == null 
                ? new ToolStripDropDownMenu()
                : userDropDown;
            dropDownToolStrip.OwnerItem = this;
            dropDownToolStrip.Items.AddRange(dropDownItems);
            dropDownToolStrip.selectedItem = dropDownToolStrip.SelectNextToolStripItem(null, true);
            dropDownToolStrip.shouldFixWidth = true;
            dropDownToolStrip.direction = direction;
            dropDownToolStrip.Location = DropDownDirectionToDropDownBounds(direction, dropDownBounds).Location;
            dropDownToolStrip.Disposed += DropDownToolStrip_Disposed;
            dropDownToolStrip.Show(dropDownToolStrip.Location);

            if (uwfDropDownCreated != null)
                uwfDropDownCreated(dropDownToolStrip);

            pressed = true;
        }
        internal void ResetToolStrip()
        {
            if (dropDownToolStrip == null)
                return;

            var clientRect = new Rectangle(dropDownToolStrip.Location, dropDownToolStrip.Size);
            var contains = clientRect.Contains(Owner.PointToClient(Control.MousePosition));
            if (!contains)
                pressed = false;
            else
                pressed = !pressed;

            dropDownToolStrip.Disposed -= DropDownToolStrip_Disposed;
            dropDownToolStrip = null;

            //Owner.Focus();
        }
        internal override void Unselect()
        {
            base.Unselect();

            if (dropDownToolStrip == null)
                return;

            CloseToolStrip();
        }

        protected internal override void DrawImage(Graphics graphics)
        {
            var image = Image;
            if (image != null)
            {
                var rect = Bounds;
                graphics.uwfDrawImage(
                    image,
                    uwfImageColor,
                    rect.X + 2,
                    rect.Y + 2,
                    rect.Height - 4,
                    rect.Height - 4);
            }
        }

        protected override void OnClick(EventArgs e)
        {
            if (Enabled == false)
                return;

            base.OnClick(e);

            if (DropDownItems.Count == 0)
            {
                CloseEverything();
                return;
            }

            if (dropDownToolStrip != null)
                return;

            if (!pressed)
                CreateToolStrip();
            else
                pressed = false;
        }
        protected override void OnMouseHover(EventArgs e)
        {
            base.OnMouseHover(e);

            if (Owner == null || Owner.IsDropDown == false)
                return;

            // Create toolstrip if hovering item with mouse.
            if (dropDownToolStrip != null)
            {
                mouseHoverTime = 0f;
                return;
            }

            mouseHoverTime += swfHelper.GetDeltaTime();
            if (mouseHoverTime > .5f)
                CreateToolStrip();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (dropDownItems.Count > 0 && Owner != null && Owner.Orientation == Orientation.Vertical)
            {
                var bounds = Bounds;
                e.Graphics.uwfDrawImage(
                    ArrowImage,
                    ArrowColor,
                    bounds.X + bounds.Width - 25,
                    bounds.Y + (bounds.Height - ArrowImage.Height) / 2,
                    ArrowImage.Width,
                    ArrowImage.Height);
            }
        }

        private Rectangle DropDownDirectionToDropDownBounds(ToolStripDropDownDirection dropDownDirection, Rectangle dropDownBounds)
        {
            var offset = Point.Empty;

            switch (dropDownDirection)
            {
                case ToolStripDropDownDirection.AboveLeft:
                    offset.X = -dropDownBounds.Width + this.Width;
                    offset.Y = -dropDownBounds.Height + 1;
                    break;
                case ToolStripDropDownDirection.AboveRight:
                    offset.Y = -dropDownBounds.Height + 1;
                    break;
                case ToolStripDropDownDirection.BelowRight:
                    offset.Y = this.Height - 2;
                    break;
                case ToolStripDropDownDirection.BelowLeft:
                    offset.X = -dropDownBounds.Width + this.Width;
                    offset.Y = this.Height - 1;
                    break;
                case ToolStripDropDownDirection.Right:
                    offset.X = this.Width;
                    if (!IsOnDropDown)
                        offset.X -= 1;
                    else
                    {
                        offset.X -= 6;
                        offset.Y -= 2;
                    }
                    break;

                case ToolStripDropDownDirection.Left:
                    offset.X = -dropDownBounds.Width;
                    break;
            }

            var itemScreenLocation = Owner.PointToScreen(Point.Empty);
            itemScreenLocation.Offset(Bounds.Location);
            dropDownBounds.Location = new Point(itemScreenLocation.X + offset.X, itemScreenLocation.Y + offset.Y);
            return dropDownBounds;
        }
        private void DropDownToolStrip_Disposed(object sender, EventArgs e)
        {
            ResetToolStrip();
        }
    }
}

<|start_filename|>Assets/Controls/Highcharts/Highchart.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Windows.Forms;

    // Based on https://www.highcharts.com/
    public class Highchart : Control
    {
        public static readonly string DefaultFontName = "Arial";
        public static readonly Font   DefaultFont10   = new Font(DefaultFontName, 10);
        public static readonly Font   DefaultFont12   = new Font(DefaultFontName, 12);
        public static readonly Font   DefaultFont12B  = new Font(DefaultFontName, 12, FontStyle.Bold);
        public static readonly Font   DefaultFont18   = new Font(DefaultFontName, 18);
        
        // Localization text.
        public static string textLegendMenu_Color = "Color...";

        public int     categoriesMinStep = 20;
        public double? fixedMax;
        public double? fixedMin;

        internal readonly Color categoriesColor  = Color.Gray;
        internal readonly Font  categoriesFont   = DefaultFont10;
        internal readonly Color gridTextColor    = Color.Gray;
        internal readonly Pen   mousePositionPen = new Pen(Color.Gray);

        internal float circleRadius    = 2;
        internal int   gridTextYOffet  = -10;
        internal int   gridTextXOffset = -2;
        internal int   mouseX;
        internal int   mouseY;
        internal int   nextColorIndex;

        internal string[]     cachedCategories;
        internal float        cachedCategoriesStep;
        internal List<string> cachedCategoriesFiltered;
        internal int          cachedGridLines = 6;
        internal double       cachedGridLinesStep;
        internal double       cachedGridMaxValue;
        internal double       cachedGridMinValue;
        internal string[]     cachedGridValues;
        internal int          cachedPlotTop;
        internal int          cachedPlotBottom;
        internal int          cachedPlotLeft;
        internal int          cachedPlotRight;
        internal int          cachedPlotHeight;
        internal int          cachedPlotWidth;
        internal double       cachedPlotMin;
        internal double       cachedPlotMax;
        internal int          cachedSubtitleY;

        private Control plot;
        private LegendButton[] legendButtons;
        private bool updateLegendButtonsFlag;

        public Highchart()
        {
            chart = new Chart();
            colors = new[]
            {
                Color.FromArgb(0x7c, 0xb5, 0xec), Color.FromArgb(0x43, 0x43, 0x48),
                Color.FromArgb(0x90, 0xed, 0x7d), Color.FromArgb(0xf7, 0xa3, 0x5c),
                Color.FromArgb(0x80, 0x85, 0xe9), Color.FromArgb(0xf1, 0x5c, 0x80),
                Color.FromArgb(0xe4, 0xd3, 0x54), Color.FromArgb(0x2b, 0x90, 0x8f),
                Color.FromArgb(0xf4, 0x5b, 0x5b), Color.FromArgb(0x91, 0xe8, 0xe1),
            };
            legend = new Legend();
            plotOptions = new PlotOptions();
            series = new SeriesCollection(this);
            subtitle = new HightchartSubtitle();
            title = new HighchartTitle();
            xAxis = new XAxis();
            yAxis = new AxisCollection(this);
            yAxis.Add(new YAxis());
            
            plot = new Control();
            plot.Padding = new Padding(1);
            plot.Visible = false;
            Controls.Add(plot);
            
            cachedPlotLeft = chart.spacingLeft + 38;
            
            Recalc();
        }

        public Chart chart { get; private set; }
        public Color[] colors { get; private set; }
        public Legend legend { get; private set; }
        public PlotOptions plotOptions { get; private set; }
        public SeriesCollection series { get; private set; }
        public HightchartSubtitle subtitle { get; private set; }
        public HighchartTitle title { get; private set; }
        public Axis xAxis { get; private set; }
        public AxisCollection yAxis { get; private set; }
        
        internal string[] Categories
        {
            get { return cachedCategories; }
        }

        public void RecalcCategories()
        {
            if (cachedPlotWidth > 0)
            {
                int maxDataAmount = GetSeriesMaximumDataAmount();
                if (maxDataAmount == -1)
                    return;

                if (maxDataAmount == 1)
                    cachedCategoriesStep = cachedPlotWidth;
                else
                    cachedCategoriesStep = (float)cachedPlotWidth / (maxDataAmount - 1);
                if (cachedCategoriesStep < categoriesMinStep)
                    cachedCategoriesStep = categoriesMinStep;

                float nextCategoriesAmount = cachedPlotWidth / cachedCategoriesStep;
                float skipFactor = maxDataAmount / nextCategoriesAmount;

                if (xAxis.categories.Count > 0)
                    cachedCategories = xAxis.categories.ToArray();
                else
                {
                    if (maxDataAmount != -1 && (cachedCategories == null || cachedCategories.Length != maxDataAmount))
                    {
                        cachedCategories = new string[maxDataAmount];
                        for (int i = 0; i < cachedCategories.Length; i++)
                            cachedCategories[i] = (i + 1).ToString();
                    }
                }

                if (cachedCategories != null && cachedCategories.Length > 0)
                {
                    if (cachedCategories.Length == 1)
                        cachedCategoriesStep = cachedPlotWidth;
                    else
                        cachedCategoriesStep = (float)cachedPlotWidth / (cachedCategories.Length - 1);

                    if (cachedCategoriesStep < categoriesMinStep)
                    {
                        cachedCategoriesStep = categoriesMinStep;

                        // Filter categories.
                        cachedCategoriesFiltered = new List<string>();
                        for (float i = 0; i < cachedCategories.Length; i += skipFactor)
                            cachedCategoriesFiltered.Add(cachedCategories[(int) i]);
                    }
                    else
                        cachedCategoriesFiltered = cachedCategories.ToList();
                }
            }
        }
        public void ResetColorIndex()
        {
            nextColorIndex = 0;
        }
        public override void Refresh()
        {
            base.Refresh();

            Recalc();
        }
        public void UpdatePlot(bool force = false)
        {
            if (cachedPlotHeight <= 0) 
                return;
            
            cachedGridMaxValue = GetSeriesMaximum();
            cachedGridMinValue = GetSeriesMinimum();
            
            if (force == false && fixedMin == null && fixedMax == null)
            {
                if (cachedPlotMax != 0 && cachedPlotMin != 0)
                    if (cachedGridMaxValue == cachedPlotMax &&
                        cachedGridMinValue == cachedPlotMin)
                        return;
            }
            
            cachedGridLinesStep = (double)cachedPlotHeight / cachedGridLines;
            cachedGridValues = new string[cachedGridLines + 1]; // + bottom line.

            const string valFormat = "0.00";
            
            if (cachedGridMaxValue <= cachedGridMinValue)
                cachedGridMaxValue = cachedGridMinValue + 1;
                
            double valRange = cachedGridMaxValue - cachedGridMinValue;
            double valStep = valRange / (cachedGridValues.Length - 1);

            int valIndex = 0;
            for (double i = cachedGridMaxValue; i > cachedGridMinValue; i -= valStep)
            {
                cachedGridValues[valIndex] = i.ToString(valFormat);
                valIndex++;
            }
            cachedGridValues[cachedGridValues.Length - 1] = cachedGridMinValue.ToString(valFormat);

            cachedPlotMin = cachedGridMinValue;
            cachedPlotMax = cachedGridMaxValue;
        }

        internal Color GetNextColor()
        {
            if (colors == null || colors.Length == 0) return Color.Gray;
            if (colors.Length == 1) return colors[0];

            var nc = colors[nextColorIndex];

            nextColorIndex++;
            if (nextColorIndex >= colors.Length)
                nextColorIndex = 0;

            return nc;
        }
        internal void AsyncUpdateLegendButtons()
        {
            updateLegendButtonsFlag = true;
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            mouseX = MathHelper.Clamp(e.X, cachedPlotLeft, cachedPlotRight);
            mouseY = MathHelper.Clamp(e.Y, cachedPlotTop, cachedPlotBottom);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            var graphics = e.Graphics;
            
            TryUpdateLegendButtons(graphics);
            
            graphics.uwfFillRectangle(chart.backgroundColor, 0, 0, Width, Height);

            DrawTitle(graphics);

            if (cachedPlotHeight > 0)
            {
                DrawPlotBack(graphics);
                DrawYAxes(graphics);
                DrawXAxis(graphics);
                
                for (int i = 0; i < series.Count; i++)
                {
                    var s = series[i];
                    if (!s.visible) continue;
                    
                    DrawSeries(graphics, s);
                }
                
                DrawTooltip(graphics);
                DrawPlotBorder(graphics);
            }

            if (chart.borderWidth > 0)
            {
                var borderPen = chart.borderPen;
                borderPen.Color = chart.borderColor;
                borderPen.Width = chart.borderWidth;

                graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
            }
        }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
        }
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            Refresh();
        }
        protected virtual void DrawSeries(Graphics g, Series s)
        {
            var clipRect = new Rectangle(plot.Padding.Left, plot.Padding.Top, plot.Width - plot.Padding.Horizontal, plot.Height - plot.Padding.Vertical);
            
            g.GroupBegin(plot);
            s.Paint(g, clipRect); 
            g.GroupEnd();
        }
        protected virtual void DrawTitle(Graphics g)
        {
            if (title.text != null) g.uwfDrawString(title.text, title.font, title.color, title.x, title.y, Width - title.x, title.font.Size + 6, title.align);
            if (subtitle.text != null) g.uwfDrawString(subtitle.text, subtitle.font, subtitle.color, subtitle.x, cachedSubtitleY, Width - subtitle.x, subtitle.font.Size + 6, subtitle.align);
        }
        protected virtual void DrawTooltip(Graphics g)
        {
            if (hovered == false)
                return;
            if (GetSeriesMaximumDataAmount() <= 0)
                return;

            var font = DefaultFont10;

            mousePositionPen.Color = chart.plotBorderColor;
            g.DrawLine(mousePositionPen, mouseX, cachedPlotTop, mouseX, cachedPlotBottom);

            for (int i = 0, index = 0; i < series.Count; i++)
            {
                var s = series[i];
                if (s.visible == false || s.data.Count == 0)
                    continue;

                var val = GetValueAtX(s, mouseX);

                g.uwfDrawString(
                    "v: " + val,
                    font,
                    s.color,
                    cachedPlotLeft + 8,
                    cachedPlotTop + index * 14,
                    cachedPlotWidth,
                    20,
                    ContentAlignment.TopLeft);

                index++;
            }
        }
        protected virtual void DrawPlotBack(Graphics g)
        {
            g.uwfFillRectangle(chart.plotBackgroundColor, cachedPlotLeft, cachedPlotTop, cachedPlotRight - cachedPlotLeft, cachedPlotBottom - cachedPlotTop);
        }
        protected virtual void DrawPlotBorder(Graphics g)
        {
            if (chart.plotBorderPen.Width != 0)
                g.DrawRectangle(chart.plotBorderPen, cachedPlotLeft, cachedPlotTop, cachedPlotRight - cachedPlotLeft, cachedPlotBottom - cachedPlotTop);
        }
        protected virtual void DrawXAxis(Graphics g)
        {
            if (xAxis.visible == false)
                return;
            
            if (cachedCategoriesFiltered != null)
            {
                // Categories.
                var cachedCategoriesLength = cachedCategoriesFiltered.Count;
                for (int i = 0; i < cachedCategoriesLength; i++)
                {
                    float categoryX = cachedPlotLeft + i * cachedCategoriesStep;
                    g.DrawLine(xAxis.tickPen, categoryX, cachedPlotBottom + xAxis.offset, categoryX, cachedPlotBottom + xAxis.tickLength + xAxis.offset);
                    g.uwfDrawString(
                        cachedCategoriesFiltered[i],
                        categoriesFont,
                        categoriesColor,
                        categoryX - cachedCategoriesStep / 2,
                        cachedPlotBottom + xAxis.offset,
                        cachedCategoriesStep,
                        32,
                        ContentAlignment.MiddleCenter);
                }

                if (cachedCategoriesStep == categoriesMinStep) // Draw last tick if needed.
                    g.DrawLine(xAxis.tickPen, cachedPlotRight, cachedPlotBottom + xAxis.offset, cachedPlotRight, cachedPlotBottom + xAxis.tickLength + xAxis.offset);
            }
            
            // Axis line.
            if (xAxis.lineWidth > 0)
                g.DrawLine(xAxis.linePen, cachedPlotLeft, cachedPlotBottom + xAxis.offset, cachedPlotRight, cachedPlotBottom + xAxis.offset);
        }
        protected virtual void DrawYAxes(Graphics g)
        {
            for (int i = 0; i < yAxis.Count; i++)
            {
                var ya = yAxis[i];
                if (ya.visible == false)
                    continue;

                // Grid.
                if (ya.gridLineWidth > 0)
                {
                    for (int k = 0; k <= cachedGridLines; k++)
                    {
                        var gridY = (int)(cachedPlotTop + k * cachedGridLinesStep);

                        g.DrawLine(ya.gridPen, cachedPlotLeft, gridY, cachedPlotRight, gridY);
                        g.uwfDrawString(cachedGridValues[k], ya.gridFont, gridTextColor, 0, gridY + gridTextYOffet,
                            cachedPlotLeft - ya.offset + gridTextXOffset, 20, HorizontalAlignment.Right);
                    }
                }

                // Draw axis line.
                if (ya.lineWidth > 0)
                    g.DrawLine(ya.linePen, cachedPlotLeft - ya.offset, cachedPlotTop, cachedPlotLeft - ya.offset, cachedPlotBottom);
            }
        }

        internal string GetCategoryAtAx(int x)
        {
            var categories = xAxis.categories;
            if (categories == null || categories.Count == 0)
                return null;

            var categoriesCount = categories.Count;
            var xCoef = (float)(x - cachedPlotLeft) / cachedPlotWidth;
            var dataIndex = (int)(xCoef * categoriesCount);
            if (dataIndex >= categoriesCount || dataIndex < 0)
                return null;

            return categories[dataIndex];
        }
        internal double GetSeriesMaximum()
        {
            if (fixedMax != null)
                return fixedMax.Value;
            
            var max = 1d;
            var seriesCount = series.Count;
            
            for (int i = 0; i < seriesCount; i++)
            {
                var s = series[i];
                if (s.visible == false) 
                    continue;
                
                var sMax = s.data.GetMax();
                if (sMax > max)
                    max = sMax;
            }
            
            return max;
        }
        internal double GetSeriesMinimum()
        {
            if (fixedMin != null)
                return fixedMin.Value;
            
            var min = 0d;
            var seriesCount = series.Count;
            
            for (int i = 0; i < seriesCount; i++)
            {
                var s = series[i];
                if (s.visible == false)
                    continue;

                var sMin = s.data.GetMin();
                if (sMin < min)
                    min = sMin;
            }

            return min;
        }
        internal int GetSeriesMaximumDataAmount()
        {
            if (series.Count == 0)
                return -1;

            int? a = null;
            
            for (int i = 0; i < series.Count; i++)
            {
                var seriesItem = series[i];
                if (!seriesItem.visible) continue;

                if (a == null)
                    a = seriesItem.data.Count;
                else if (seriesItem.data.Count > a)
                    a = seriesItem.data.Count;
            }
            
            if (a == null) 
                return -1;
            
            return a.Value;
        }
        internal int GetSeriesMinimumDataAmount()
        {
            if (series.Count == 0)
                return -1;

            if (series.Count == 1)
            {
                if (series[0].visible == false)
                    return -1;
                return series[0].data.Count;
            }

            int? a = null;
            for (int i = 0; i < series.Count; i++)
                if (series[i].visible)
                {
                    if (a == null)
                        a = series[i].data.Count;
                    else if (series[i].data.Count < a)
                        a = series[i].data.Count;
                }
            if (a == null) return -1;
            return a.Value;
        }
        internal double GetValueAtX(Series s, int x)
        {
            if (s == null || s.data.Count == 0)
                return 0;

            var maxDataAmount = GetSeriesMaximumDataAmount();
            if (maxDataAmount == 0) return 0;

            var xMod = (float)(x - cachedPlotLeft - plot.Padding.Left) / cachedPlotWidth;
            var dataIndex = (int) (xMod * (maxDataAmount - 1));
            if (dataIndex >= s.data.Count || dataIndex < 0)
                return 0;

            return s.data[dataIndex];
        }
        internal void Recalc()
        {
            var marginBottom = chart.spacingBottom;
            var marginLeft = chart.spacingLeft + 38;
            var marginRight = chart.spacingRight;
            var marginTop = chart.spacingTop;

            if (chart.marginBottom != null) marginBottom = chart.marginBottom.Value;
            if (chart.marginLeft != null) marginLeft = chart.marginLeft.Value;
            if (chart.marginRight != null) marginRight = chart.marginRight.Value;
            if (chart.marginTop != null) marginTop = chart.marginTop.Value;
            
            cachedPlotBottom = Height - marginBottom;
            cachedPlotLeft = marginLeft;
            cachedPlotRight = Width - marginRight;
            cachedPlotTop = marginTop;
            cachedSubtitleY = subtitle.y;

            // Calc stuff that can change plot size first.

            // Check title & subtitle.
            if (title.text != null)
            {
                cachedPlotTop = (int)title.font.Size;
                cachedSubtitleY += (int)title.font.Size;

                if (title.floating == false)
                    cachedPlotTop += title.margin;
            }
            
            if (subtitle.text != null && subtitle.floating == false)
                cachedPlotTop += (int)subtitle.font.Size;
            
            // Check legend.
            if (legend.enabled && legend.floating == false)
            {
                if (legend.layout == LegendLayouts.horizontal)
                {
                    var lbHeight = UpdateLegendLocation();

                    cachedPlotBottom -= lbHeight + legend.margin + 12; // + categories text height?
                }
                else
                {
                    // vertical
                }
            }
            
            // Time to find out the plot size.
            cachedPlotBottom -= xAxis.tickLength;
            cachedPlotHeight = cachedPlotBottom - cachedPlotTop;
            cachedPlotWidth = cachedPlotRight - cachedPlotLeft;
            
            plot.Location = new Point(cachedPlotLeft, cachedPlotTop);
            plot.Size = new Size(cachedPlotWidth, cachedPlotHeight);

            // Other stuff.
            RecalcCategories();
            UpdatePlot(true);
        }
        internal int UpdateLegendLocation()
        {
            if (legendButtons == null) return 0;

            int plotCenterX = cachedPlotLeft + (cachedPlotRight - cachedPlotLeft) / 2;
            int totalLBWidth = 0;
            for (int i = 0; i < legendButtons.Length; i++)
                totalLBWidth += legendButtons[i].Width + legend.itemDistance;

            // Horizontal.
            if (cachedPlotWidth >= totalLBWidth)
            {
                int leftPos = plotCenterX - totalLBWidth / 2;
                int lbHeight = 0;
                for (int i = 0, cw = 0; i < legendButtons.Length; i++)
                {
                    var lb = legendButtons[i];
                    lb.Location = new Point(leftPos + cw, Height - lb.Height - chart.spacingBottom);

                    cw += lb.Width + legend.itemDistance;
                    lbHeight = lb.Height;
                }

                return lbHeight;
            }
            else
            {
                // Vertical.
                int lbHeight = 0;
                for (int i = 0; i < legendButtons.Length; i++)
                {
                    var lb = legendButtons[i];
                    lb.Location = new Point(plotCenterX - lb.Width / 2, Height - lb.Height * (i + 1) - chart.spacingBottom);
                    lbHeight += lb.Height;
                }

                return lbHeight;
            }
        }

        private void TryUpdateLegendButtons(Graphics g)
        {
            if (!updateLegendButtonsFlag)
                return;
            
            updateLegendButtonsFlag = false;
            
            if (legendButtons != null)
                for (int i = 0; i < legendButtons.Length; i++)
                    legendButtons[i].Dispose();

            if (!legend.enabled)
                return;
            
            legendButtons = new LegendButton[series.Count];
            
            for (int i = 0; i < legendButtons.Length; i++)
            {
                var s = series[i];
                var lb = new LegendButton(legend, s);

                lb.Width = (int) g.MeasureString(lb.Text, legend.itemStyle.font).Width + 20;

                if (legend.layout == LegendLayouts.horizontal)
                    lb.Location = new Point(i * 120, Height - lb.Height);

                Controls.Add(lb);

                legendButtons[i] = lb;
            }

            Recalc();
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/HorizontalAlignment.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public enum HorizontalAlignment
    {
        Left = 0,
        Right = 1,
        Center = 2,
    }
}


<|start_filename|>Assets/Examples/Panels/PanelComboBox.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelComboBox : BaseExamplePanel
    {
        public override void Initialize()
        {
            var items = new object[]
                        {
                            "hello",
                            "world",
                            100, 
                            110,
                            120,
                            130,
                            140,
                            150,
                            160,
                            170,
                            180,
                            190
                        };


            // Normal.
            this.Create<Label>("Normal: ");
            var comboNormal = this.Create<ComboBox>();
            comboNormal.Items.AddRange(items);


            // Style: list.
            this.Create<Label>("DropDownStyle List:", false, 8, lineOffset);
            var comboList = this.Create<ComboBox>();
            comboList.Items.AddRange(items);
            comboList.DropDownStyle = ComboBoxStyle.DropDownList;

            // ItemHeight.
            this.Create<Label>("Item height:", false, 8, lineOffset);
            var numericItemHeight = this.Create<NumericUpDown>();
            var comboItemHeight = this.Create<ComboBox>("", true);

            numericItemHeight.Value = 24;
            numericItemHeight.ValueChanged += (sender, args) => comboItemHeight.ItemHeight = (int)numericItemHeight.Value;

            comboItemHeight.Items.AddRange(items);
            comboItemHeight.ItemHeight = (int)numericItemHeight.Value;
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ScrollEventHandler.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public delegate void ScrollEventHandler(object sender, ScrollEventArgs e);
}


<|start_filename|>Assets/Examples/Panels/PanelTableViewLazy.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Diagnostics;
    using System.Windows.Forms;
    
    public class PanelTableViewLazy : BaseExamplePanel
    {
        public override void Initialize()
        {
            var watch = Stopwatch.StartNew();
            var label = this.Create<Label>();
            var table = this.Create<TableView>();
            table.Width = 480;
            table.Height = 320;
            
            // This will prevent allocating default cell controls(NumericUpDown).
            table.SkipControlsInitializations = true;
                
            // Max reasonable can be 1024x1024, but amount of columns and rows controls will slow it down.  
            const int ROWS_COUNT = 512;
            const int COLUMN_COUNT = 512;

            // Add columns.
            for (int i = 0; i < COLUMN_COUNT; i++)
            {
                var columnName = i.ToString();
                
                table.Columns.Add(columnName, columnName);
            }
            
            // Add rows.
            for (int i = 0; i < ROWS_COUNT; i++)
            {
                table.Rows.Add();
                table.Rows[i].ItemsControls.CreateControlOnCellVisible = (columnIndex, rowIndex) => new TextBox()
                {
                    Text = "C: " + columnIndex + ", R: " + rowIndex,
                    TextAlign = HorizontalAlignment.Center
                };
            }
            
            table.Refresh();
            table.TryInitializeDefferedControls();
            
            watch.Stop();
            label.Text = "Table[" + COLUMN_COUNT + ", " + ROWS_COUNT + "] was created in " + watch.ElapsedMilliseconds + " ms.";
        }
    }
}

<|start_filename|>Assets/System/Windows/Forms/MonthCalendar.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    using System.Collections.Generic;
    using System.Drawing;
    using System.Globalization;

    public class MonthCalendar : Control
    {
        internal CultureInfo uwfCultureInfo = Application.CurrentCulture;
        internal Padding uwfInnerPadding = new Padding(1);

        private readonly Pen borderPen = new Pen(SystemColors.ControlDark);
        private readonly List<Control> daysControls = new List<Control>();
        private readonly Pen todayPen = new Pen(SystemColors.HotTrack);

        private DayOfWeek firstDayOfWeek;
        private DateTime selectedDate;
        private bool showToday;
        private Button todayButton;
        private DateTime todayDate;
        private DateTime value;

        public MonthCalendar()
        {
            firstDayOfWeek = uwfCultureInfo.DateTimeFormat.FirstDayOfWeek;

            BackColor = Color.White;
            CellWidth = 22;
            ShowToday = true;
            TitleBackColor = Color.Transparent;
            TitleForeColor = Color.FromArgb(42, 42, 42);
            TodayDate = DateTime.Now;
            Value = DateTime.Now;

            var prevMonthButton = new RepeatButton();
            prevMonthButton.CooldownBetweenClicks = .4f;
            prevMonthButton.Image = uwfAppOwner.Resources.ArrowLeft;
            prevMonthButton.Size = new Size(16, 16);
            prevMonthButton.Location = new Point(4, 10);
            prevMonthButton.Click += (s, a) => { SetDate(selectedDate.AddMonths(-1)); };
            Controls.Add(prevMonthButton);

            var nextMonthButton = new RepeatButton();
            nextMonthButton.CooldownBetweenClicks = .4f;
            nextMonthButton.Anchor = AnchorStyles.Right;
            nextMonthButton.Image = uwfAppOwner.Resources.ArrowRight;
            nextMonthButton.Size = new Size(16, 16);
            nextMonthButton.Location = new Point(Width - nextMonthButton.Width - 4, 10);
            nextMonthButton.Click += (s, a) => { SetDate(selectedDate.AddMonths(1)); };
            Controls.Add(nextMonthButton);

            SetArrowButtonDefaultStyle(prevMonthButton);
            SetArrowButtonDefaultStyle(nextMonthButton);
        }

        public event DateRangeEventHandler DateChanged = delegate { };

        public int CellWidth { get; set; }
        public DayOfWeek FirstDayOfWeek
        {
            get { return firstDayOfWeek; }
            set
            {
                if (firstDayOfWeek != value)
                {
                    firstDayOfWeek = value;
                    SetDate(selectedDate);
                }
            }
        }
        public bool ShowToday
        {
            get { return showToday; }
            set
            {
                if (showToday != value)
                {
                    showToday = value;
                    if (showToday)
                        CreateTodayButton();
                    else
                    {
                        if (todayButton != null)
                            todayButton.Dispose();
                        todayButton = null;
                    }
                }
            }
        }

        public Color TitleBackColor { get; set; }
        public Color TitleForeColor { get; set; }
        public DateTime TodayDate
        {
            get { return todayDate; }
            set
            {
                todayDate = value;
                UpdateTodayDate();
            }
        }
        public DateTime Value
        {
            get { return value; }
            set
            {
                this.value = value;
                SetDate(this.value);
                DateChanged(this, new DateRangeEventArgs(this.value, this.value));
            }
        }

        internal Color uwfBorderColor
        {
            get { return borderPen.Color; }
            set { borderPen.Color = value; }
        }

        protected override Size DefaultSize
        {
            get
            {
                return new Size(164, 162);
            }
        }

        public void SetDate(DateTime date)
        {
            selectedDate = date;

            // TODO: update only if month & year are changed.

            for (int i = 0; i < daysControls.Count; i++)
                daysControls[i].Dispose();
            daysControls.Clear();

            var monthStartDayOfWeek = new DateTime(date.Year, date.Month, 1).DayOfWeek;
            var startDate = new DateTime(date.Year, date.Month, 1).AddDays(-(int)monthStartDayOfWeek + (int)firstDayOfWeek);
            var labelDate = new DateTime(startDate.Year, startDate.Month, startDate.Day);
            var labelFont = new Font("Arial", 11);

            var leftOffset = uwfInnerPadding.Left + 4; // 4 = 1 border + 3 pixels.

            for (int row = 0; row < 7; row++)
            {
                for (int column = 0; column < 7; column++)
                {
                    if (row == 0) // Header.
                    {
                        var labelDayOfWeek = new Label();
                        labelDayOfWeek.AutoSize = false;
                        labelDayOfWeek.Font = labelFont;
                        labelDayOfWeek.ForeColor = SystemColors.InfoText;
                        labelDayOfWeek.Location = new Point(leftOffset + CellWidth * column, 33);
                        labelDayOfWeek.Size = new Size(CellWidth, 20);
                        labelDayOfWeek.Text = uwfCultureInfo.DateTimeFormat.GetShortestDayName(labelDate.DayOfWeek);
                        labelDayOfWeek.TextAlign = ContentAlignment.TopCenter;
                        labelDayOfWeek.Padding = new Padding();
                        Controls.Add(labelDayOfWeek);

                        daysControls.Add(labelDayOfWeek);

                        labelDate = labelDate.AddDays(1);
                    }
                    else
                    {
                        var dayColor = date.Month == startDate.Month ? SystemColors.InfoText : SystemColors.GrayText;
                        var dayDate = new DateTime(startDate.Year, startDate.Month, startDate.Day);

                        var dayButton = new Button();
                        dayButton.ForeColor = dayColor;
                        dayButton.Size = new Size(CellWidth, 15);
                        dayButton.Location = new Point(leftOffset + CellWidth * column, 33 + 15 * row);
                        dayButton.BackColor = Color.Transparent;
                        dayButton.uwfBorderColor = Color.Transparent;
                        dayButton.uwfBorderHoverColor = Color.FromArgb(112, 192, 231);
                        dayButton.uwfHoverColor = Color.FromArgb(229, 243, 251);
                        dayButton.Text = startDate.Day.ToString();
                        dayButton.Padding = new Padding();
                        dayButton.Click += (s, a) =>
                        {
                            Value = dayDate;
                        };
                        Controls.Add(dayButton);

                        if (TodayDate.Year == startDate.Year && TodayDate.Month == startDate.Month && TodayDate.Day == startDate.Day)
                        {
                            dayButton.ForeColor = Color.FromArgb(0, 102, 204);
                            dayButton.uwfBorderColor = dayButton.ForeColor;
                            dayButton.uwfBorderHoverColor = dayButton.uwfBorderColor;
                            dayButton.uwfHoverColor = dayButton.BackColor;
                        }

                        if (Value.Year == dayDate.Year && Value.Month == dayDate.Month && Value.Day == dayDate.Day)
                        {
                            dayButton.BackColor = Color.FromArgb(203, 232, 246);
                            dayButton.uwfBorderColor = Color.FromArgb(38, 160, 218);
                            dayButton.uwfBorderHoverColor = dayButton.uwfBorderColor;
                            dayButton.uwfHoverColor = dayButton.BackColor;
                        }

                        startDate = startDate.AddDays(1);
                        daysControls.Add(dayButton);
                    }
                }
            }
        }
        public override void Refresh()
        {
            base.Refresh();
            SetDate(selectedDate);

            if (todayButton != null)
            {
                todayButton.Location = new Point(3 + 2 * CellWidth, 33 + 7 * 15);
            }
        }

        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            var newDate = selectedDate.AddMonths(e.Delta > 0 ? -1 : 1);

            SetDate(newDate);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.uwfFillRectangle(BackColor, 0, 0, Width, Height);

            // Header.
            e.Graphics.uwfFillRectangle(TitleBackColor, 0, 0, Width, 32);
            e.Graphics.uwfDrawString(uwfCultureInfo.DateTimeFormat.MonthNames[selectedDate.Month - 1] + " " + selectedDate.Year, Font, TitleForeColor, 0, 8, Width, 32, ContentAlignment.TopCenter);

            if (ShowToday)
                e.Graphics.DrawRectangle(todayPen, CellWidth * 1, 141, CellWidth - 2, 13);

            e.Graphics.DrawRectangle(borderPen, uwfInnerPadding.Left, uwfInnerPadding.Top, Width - uwfInnerPadding.Horizontal, Height - uwfInnerPadding.Vertical);
        }

        private static string GetTodayText(CultureInfo info)
        {
            if (info != null)
                switch (info.Name)
                {
                    case "af-ZA": return "Vandag";
                    case "ar-AE": return "اليوم";
                    case "eu-ES": return "Gaur";
                    case "be-BY": return "Сёння";
                    case "bg-BG": return "Днес";
                    case "ca-ES": return "Avui";
                    case "zh-CN":
                    case "zh-CHS":
                    case "zh-CHT": return "今天";
                    case "cs-CZ": return "Dnes";
                    case "da-DK": return "I dag";
                    case "nl-BE": return "Vandaag";
                    case "et-EE": return "Täna";
                    case "fo-FO": break;
                    case "fi-FI ": return "Tänään";
                    case "fr-FR": return "Aujourd'hui";
                    case "de-DE": return "Heute";
                    case "el-GR": return "Σήμερα";
                    case "he-IL": return "היום";
                    case "hu-HU": return "Ma";
                    case "is-IS": return "Í dag";
                    case "id-ID": return "Hari ini";
                    case "it-IT": return "Oggi";
                    case "ja-JP": return "今日";
                    case "ko-KR": return "오늘";
                    case "lv-LV": return "Šodien";
                    case "lt-LT": return "Šiandien";
                    case "nb-NO": return "I dag";
                    case "pl-PL": return "Dzisiaj";
                    case "pt-PT": return "Hoje";
                    case "ro-RO": return "Astăzi";
                    case "ru-RU": return "Сегодня";
                    case "Lt-sr-SP": return "Данас";
                    case "sk-SK": return "Dnes";
                    case "sl-SI": return "Danes";
                    case "es-ES": return "Hoy";
                    case "sv-SE": return "I dag";
                    case "th-TH": return "ในวันนี้";
                    case "tr-TR": return "Bugün";
                    case "uk-UA": return "Сьогодні";
                    case "vi-VN": return "Hôm nay";
                }

            return "Today";
        }
        private static void SetArrowButtonDefaultStyle(Button button)
        {
            button.BackColor = Color.Transparent;

            button.uwfBorderColor = Color.Transparent;
            button.uwfBorderHoverColor = Color.Transparent;
            button.uwfBorderSelectColor = Color.Transparent;
            button.uwfHoverColor = Color.Transparent;
            button.uwfImageColor = Color.FromArgb(48, 48, 48);
            button.uwfImageHoverColor = Color.FromArgb(0, 102, 204);
        }

        private void CreateTodayButton()
        {
            todayButton = new TodayButton();
            todayButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; 
            todayButton.BackColor = Color.Transparent;
            todayButton.Font = new Font("Arial", 11); // 12 is too big.
            todayButton.Location = new Point(3 + 2 * CellWidth, 33 + 7 * 15);
            todayButton.TextAlign = ContentAlignment.MiddleLeft;
            todayButton.Size = new Size(Width - uwfInnerPadding.Right - todayButton.Location.X - 4, 20);

            todayButton.uwfBorderColor = Color.Transparent;
            todayButton.uwfBorderHoverColor = Color.Transparent;
            todayButton.uwfBorderSelectColor = Color.Transparent;
            todayButton.uwfHoverColor = Color.Transparent;

            todayButton.Click += (s, a) =>
            {
                Value = TodayDate;
            };
            Controls.Add(todayButton);

            UpdateTodayDate();
        }
        private void UpdateTodayDate()
        {
            if (todayButton != null)
                todayButton.Text = GetTodayText(uwfCultureInfo) + ": " + todayDate.ToString(uwfCultureInfo.DateTimeFormat.ShortDatePattern);
        }

        /// <summary>
        /// With fore hover color.
        /// </summary>
        private class TodayButton : Button
        {
            public Color ForeBaseColor = SystemColors.InfoText;
            public Color ForeHoverColor = SystemColors.HotTrack;

            protected override void OnPaint(PaintEventArgs e)
            {
                if (hovered)
                    ForeColor = ForeHoverColor;
                else
                    ForeColor = ForeBaseColor;

                base.OnPaint(e);
            }
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelPanel.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System;
    using System.Linq;
    using System.Windows.Forms;

    public class PanelPanel : BaseExamplePanel
    {
        public override void Initialize()
        {
            var panel = this.Create<Panel>();
            panel.BorderStyle = BorderStyle.Fixed3D;

            for (int i = 0; i < 20; i++)
            {
                panel.Create<Label>("label" + i);
                panel.Create<Button>("button" + i, true, 32);
            }

            var checkBoxAutoscroll = this.Create<CheckBox>("AutoScroll", false, 8, panel.Height + 8);
            checkBoxAutoscroll.CheckedChanged += (sender, args) => { panel.AutoScroll = checkBoxAutoscroll.Checked; };

            var borderStyles = Enum.GetNames(typeof(BorderStyle)).Cast<object>().ToArray();

            this.Create<Label>("BorderStyle:", false, 8, lineOffset);
            var comboBorder = this.Create<ComboBox>();
            comboBorder.Items.AddRange(borderStyles);
            comboBorder.SelectedIndex = 2;
            comboBorder.SelectedIndexChanged += (sender, args) =>
                {
                    var selectedItem = comboBorder.SelectedItem.ToString();
                    panel.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), selectedItem);
                };
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelScrollBar.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;

    public class PanelScrollBar : BaseExamplePanel
    {
        public override void Initialize()
        {
            var scrollValue = this.Create<Label>();
            var hscroll = this.Create<HScrollBar>();
            var vscroll = this.Create<VScrollBar>();

            hscroll.ValueChanged += (sender, args) => scrollValue.Text = hscroll.Value.ToString();
            
            vscroll.Minimum = -200;
            vscroll.Height = 320;
            vscroll.ValueChanged += (sender, args) => scrollValue.Text = vscroll.Value.ToString();
        }
    }
}


<|start_filename|>Assets/Examples/Panels/PanelPictureBox.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System;
    using System.Windows.Forms;

    public class PanelPictureBox : BaseExamplePanel
    {
        public override void Initialize()
        {
            var borderStyles = Enum.GetNames(typeof(BorderStyle));

            var pictureBox = this.Create<PictureBox>();
            this.Create<Label>("Border style:", false, 8, 64);
            var comboBorder = this.Create<ComboBox>();

            comboBorder.Items.AddRange(borderStyles);
            comboBorder.SelectedIndex = 0;
            comboBorder.SelectedIndexChanged += (sender, args) =>
            {
                var selectedItem = comboBorder.SelectedItem.ToString();
                pictureBox.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), selectedItem);
            };

            pictureBox.BackgroundImage = uwfAppOwner.Resources.ArrowUp;
            pictureBox.BackgroundImageLayout = ImageLayout.Tile;
            pictureBox.Image = uwfAppOwner.Resources.DateTimePicker;
        }
    }
}


<|start_filename|>Assets/System/Drawing/StringFormat.cs<|end_filename|>
﻿namespace System.Drawing
{
    public enum StringAlignment
    {
        Near = 0,
        Center = 1,
        Far = 2,
    }

    public sealed class StringFormat
    {
        public StringAlignment Alignment { get; set; }
        public StringAlignment LineAlignment { get; set; }
    }
}


<|start_filename|>Assets/Controls/Highcharts/LegendButton.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    internal sealed class LegendButton : Button
    {
        private const int DefaultTextMarginLeft = 16;
        
        public LegendButton(Legend l, Series s)
        {
            Legend = l;
            Series = s;
            TextLeftMargin = DefaultTextMarginLeft;
            
            TextFromSeries();
        }

        public Legend Legend { get; private set; }
        public Series Series { get; private set; }
        public int TextLeftMargin { get; set; }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);

            switch (e.Button)
            {
                case MouseButtons.Left:
                    Series.visible = !Series.visible;

                    var highcharts = Parent as Highchart;
                    if (highcharts != null) 
                        highcharts.UpdatePlot(); // Update plot min and max values range.
                    break;
                
                case MouseButtons.Right:
                    
                    var itemColor = new ToolStripMenuItem(Highchart.textLegendMenu_Color);
                    itemColor.Click += (sender, args) =>
                    {
                        var form = new ColorPickerForm();
                        form.Color = Series.color;
                        form.ColorChanged += (sender2, args2) => Series.color = form.Color; 
                        form.ShowDialog();
                    };

                    var context = new ContextMenuStrip();
                    context.Items.Add(itemColor);
                    context.Show(null, MousePosition);
                    break;
            }
        }
        
        protected override void OnPaint(PaintEventArgs e)
        {
            var graphics = e.Graphics;

            // User original series color or hidden color for icon and use styles for text.
            var seriesColor = Series.color;
            var textColor = Legend.itemStyle.color;
            
            if (!Series.visible)
            {
                seriesColor = Legend.itemHiddenStyle.color;
                textColor = seriesColor;
            }

            // Text also supports hover style.
            if (hovered)
                textColor = Legend.itemHoverStyle.color;
            
            Series.PaintIcon(graphics, new Rectangle(0, 0, TextLeftMargin, 16));

            graphics.uwfDrawString(Text, Font, textColor, TextLeftMargin, 0, Width - TextLeftMargin, Height, ContentAlignment.MiddleCenter);
        }
        
        protected override void OnPaintBackground(PaintEventArgs e)
        { }
        
        private void TextFromSeries()
        {
            Text = Series.name != null 
                ? Series.name 
                : "Series " + (Series.index + 1);
        }
    }
}


<|start_filename|>Assets/Controls/Highcharts/AxisTitle.cs<|end_filename|>
﻿namespace Highcharts
{
    using System;
    using System.Windows.Forms;

    public class AxisTitle : IDisposable
    {
        private readonly Axis owner;

        public AxisTitle(Axis axis)
        {
            owner = axis;

            align = HorizontalAlignment.Center;
            offset = 0;
            margin = 0;
            text = null;
            x = 0;
            y = 0;

            if (axis.horizontal == false) margin = 10;
        }

        /// <summary>
        /// Alignment of the title relative to the axis values. Possible values are "low", "middle" or "high". Defaults to middle.
        /// </summary>
        public HorizontalAlignment align { get; set; }
        /// <summary>
        /// The pixel distance between the axis labels or line and the title. Defaults to 0 for horizontal axes, 10 for vertical
        /// </summary>
        public int margin { get; set; }
        /// <summary>
        /// The distance of the axis title from the axis line. By default, this distance is computed from the offset width of the labels, 
        /// the labels' distance from the axis and the title's margin. However when the offset option is set, it overrides all this.
        /// </summary>
        public int offset { get; set; }
        /// <summary>
        /// The actual text of the axis title. It can contain basic HTML text markup like <b/>, <i/> and spans with style.
        /// </summary>
        public string text { get; set; }
        /// <summary>
        /// Horizontal pixel offset of the title position. Defaults to 0.
        /// </summary>
        public int x { get; set; }
        /// <summary>
        /// Vertical pixel offset of the title position.
        /// </summary>
        public int y { get; set; }

        public void Dispose()
        {
            if (owner != null) owner.Dispose();
        }
    }
}


<|start_filename|>Assets/System/Drawing/Image.cs<|end_filename|>
﻿namespace System.Drawing
{
    using System.Drawing.API;    
    
    public abstract class Image
    {
        internal Image()
        {
            Color = Color.White;
        }
        
        public int Height { get { return Texture.Height; } }
        public Size Size { get { return new Size(Width, Height); } }
        public object Tag { get; set; }
        public int Width { get { return Texture.Width; } }

        internal Color Color { get; set; }
        internal ITexture Texture { get; set; }
    }
}


<|start_filename|>Assets/Controls/Highcharts/HighchartTitle.cs<|end_filename|>
﻿namespace Highcharts
{
    using System.Drawing;
    using System.Windows.Forms;

    public class HighchartTitle
    {
        public HighchartTitle()
        {
            align = HorizontalAlignment.Center;
            color = Color.FromArgb(0x33, 0x33, 0x33);
            floating = false;
            font = Highchart.DefaultFont18;
            margin = 15;
            text = "Chart title";
            x = 0;
            y = 0;
        }

        /// <summary>
        /// The horizontal alignment of the title. Can be one of "left", "center" and "right". Defaults to center.
        /// </summary>
        public HorizontalAlignment align { get; set; }
        public Color color { get; set; }
        /// <summary>
        /// When the title is floating, the plot area will not move to make space for it. Defaults to false.
        /// </summary>
        public bool floating { get; set; }
        public Font font { get; set; }
        /// <summary>
        /// The margin between the title and the plot area, or if a subtitle is present, 
        /// the margin between the subtitle and the plot area. Defaults to 15.
        /// </summary>
        public int margin { get; set; }
        /// <summary>
        /// The title of the chart. To disable the title, set the text to null. Defaults to Chart title.
        /// </summary>
        public string text { get; set; }
        /// <summary>
        /// The x position of the title relative to the alignment within chart.spacingLeft and chart.spacingRight. Defaults to 0.
        /// </summary>
        public int x { get; set; }
        /// <summary>
        /// The y position of the title relative to the alignment within chart.spacingTop and chart.spacingBottom. 
        /// By default it depends on the font size.
        /// </summary>
        public int y { get; set; }
    }
}


<|start_filename|>Assets/System/Windows/Forms/KeyEventHandler.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public delegate void KeyEventHandler(object sender, KeyEventArgs e);
}


<|start_filename|>Assets/Examples/Panels/PanelButton.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public class PanelButton : BaseExamplePanel
    {
        private int clickCount;

        public override void Initialize()
        {
            // Normal.
            this.Create<Label>("Normal:");
            this.Create<Button>("button");

            // Style.
            this.Create<Label>("Styled:", false, 8, lineOffset);
            var buttonStyled = this.Create<Button>("button");
            buttonStyled.uwfBorderColor = Color.Transparent;
            buttonStyled.uwfBorderHoverColor = Color.Transparent;
            buttonStyled.uwfBorderSelectColor = Color.Transparent;
            buttonStyled.BackColor = Color.FromArgb(64, 64, 64);
            buttonStyled.ForeColor = Color.FromArgb(160, 160, 160);
            buttonStyled.uwfHoverColor = Color.FromArgb(74, 74, 74);

            // Background image.
            var imageLayouts = Enum.GetNames(typeof(ImageLayout));

            this.Create<Label>("Background Image:", false, 8, lineOffset);
            var comboBImage = this.Create<ComboBox>();
            var buttonBImage = this.Create<Button>("", true);

            comboBImage.Items.AddRange(imageLayouts);
            comboBImage.SelectedIndex = 2;
            comboBImage.SelectedIndexChanged += (sender, args) =>
            {
                var selectedItem = comboBImage.SelectedItem.ToString();
                buttonBImage.BackgroundImageLayout = (ImageLayout)Enum.Parse(typeof(ImageLayout), selectedItem);
            };
            buttonBImage.BackgroundImage = uwfAppOwner.Resources.FormResize;

            // Image.
            var imageAlign = Enum.GetNames(typeof(ContentAlignment));

            this.Create<Label>("Image:", false, 8, lineOffset);
            var comboImage = this.Create<ComboBox>();
            var buttonImage = this.Create<Button>("", true);

            comboImage.Items.AddRange(imageAlign);
            comboImage.SelectedIndex = 4;
            comboImage.SelectedIndexChanged += (sender, args) =>
            {
                var selectedItem = comboImage.SelectedItem.ToString();
                buttonImage.ImageAlign = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), selectedItem);
            };
            buttonImage.Image = uwfAppOwner.Resources.RadioButton_Checked;

            // Disabled.
            this.Create<Label>("Disabled:", false, 8, lineOffset);
            var buttonDisabled = this.Create<Button>("button");
            buttonDisabled.Enabled = false;

            // FlatStyle.
            var flatStyles = Enum.GetNames(typeof(FlatStyle));

            this.Create<Label>("Flat styles:", false, 8, lineOffset);
            this.Create<Label>("Note: only affect border color, gradient fill is not supported", false, 8, 16);
            var comboFlatStyle = this.Create<ComboBox>();
            var buttonFlatStyle = this.Create<Button>("button", true);

            comboFlatStyle.Items.AddRange(flatStyles);
            comboFlatStyle.SelectedIndex = 2;
            comboFlatStyle.SelectedIndexChanged += (sender, args) =>
            {
                var selectedItem = comboFlatStyle.SelectedItem.ToString();
                buttonFlatStyle.FlatStyle = (FlatStyle)Enum.Parse(typeof(FlatStyle), selectedItem);
            };

            // Click.
            var labelClick = this.Create<Label>("Click:", false, 8, lineOffset);
            this.Create<Label>("Note: try to use spacebar or enter", false, 8, 16);
            var buttonClick = this.Create<Button>("+1");
            buttonClick.Click += (sender, args) =>
            {
                clickCount += 1;
                labelClick.Text = "Click: " + clickCount;
            };
            
            // Perform Click..
            this.Create<Label>("Invoke PerformClick on previous button", false, 8, lineOffset);
            var buttonPClick = this.Create<Button>("button");
            buttonPClick.Click += (sender, args) => buttonClick.PerformClick();

            // User paint.
            this.Create<Label>("User paint:", false, 8, lineOffset);
            this.Create<CustomButton>();
        }

        private class CustomButton : Button
        {
            private readonly Pen borderPen = new Pen(SystemColors.ActiveBorder);
            private readonly Brush rectBrush = Brushes.CadetBlue;
            private readonly Timer timer;

            private float rectX;

            public CustomButton()
            {
                timer = new Timer();
                timer.Interval = 1;
                timer.Tick += (sender, args) =>
                {
                    rectX += .5f;
                    if (rectX > Width)
                        rectX = -16;
                };
                timer.Start();
            }

            protected override void Dispose(bool release_all)
            {
                timer.Dispose();

                base.Dispose(release_all);
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                e.Graphics.FillRectangle(rectBrush, rectX, 3, 16, 16);
                e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height);
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ButtonBorderStyle.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum ButtonBorderStyle
    {
        None,
        Dotted,
        Dashed,
        Solid,
        Inset,
        Outset,
    }
}


<|start_filename|>Assets/System/Windows/Forms/Border3DStyle.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public enum Border3DStyle
    {
        Adjust = NativeMethods.BF_ADJUST,
        Bump = NativeMethods.EDGE_BUMP,
        Etched = NativeMethods.EDGE_ETCHED,
        Flat = NativeMethods.BF_FLAT | NativeMethods.EDGE_SUNKEN,
        Raised = NativeMethods.EDGE_RAISED,
        RaisedInner = NativeMethods.BDR_RAISEDINNER,
        RaisedOuter = NativeMethods.BDR_RAISEDOUTER,
        Sunken = NativeMethods.EDGE_SUNKEN,
        SunkenInner = NativeMethods.BDR_SUNKENINNER,
        SunkenOuter = NativeMethods.BDR_SUNKENOUTER,
    }
}


<|start_filename|>Assets/Examples/Panels/PanelRadioButton.cs<|end_filename|>
﻿namespace UnityWinForms.Examples.Panels
{
    using System.Windows.Forms;
    
    public class PanelRadioButton : BaseExamplePanel
    {
        public override void Initialize()
        {
            var radio = this.Create<RadioButton>("AutoCheck = false");
            radio.AutoCheck = false;
            radio.Width = 200;
            
            var groupBox = this.Create<GroupBox>();

            var r1 = groupBox.Create<RadioButton>("First");
            var r2 = groupBox.Create<RadioButton>("Second");
            var r3 = groupBox.Create<RadioButton>("Third");

            // hack: to make sure tabulation will work fine.
            r1.TabIndex = 1;
            r2.TabIndex = 2;
            r3.TabIndex = 3;
        }
    }
}

<|start_filename|>Assets/System/Drawing/Pens.cs<|end_filename|>
﻿namespace System.Drawing
{
    public static class Pens
    {
        private static Pen aliceBlue;
        private static Pen antiqueWhite;
        private static Pen aqua;
        private static Pen aquamarine;
        private static Pen azure;
        private static Pen beige;
        private static Pen bisque;
        private static Pen black;
        private static Pen blanchedAlmond;
        private static Pen blue;
        private static Pen blueViolet;
        private static Pen brown;
        private static Pen burlyWood;
        private static Pen cadetBlue;
        private static Pen chartreuse;
        private static Pen chocolate;
        private static Pen coral;
        private static Pen cornflowerBlue;
        private static Pen cornsilk;
        private static Pen crimson;
        private static Pen cyan;
        private static Pen darkBlue;
        private static Pen darkCyan;
        private static Pen darkGoldenrod;
        private static Pen darkGray;
        private static Pen darkGreen;
        private static Pen darkKhaki;
        private static Pen darkMagenta;
        private static Pen darkOliveGreen;
        private static Pen darkOrange;
        private static Pen darkOrchid;
        private static Pen darkRed;
        private static Pen darkSalmon;
        private static Pen darkSeaGreen;
        private static Pen darkSlateBlue;
        private static Pen darkSlateGray;
        private static Pen darkTurquoise;
        private static Pen darkViolet;
        private static Pen deepPink;
        private static Pen deepSkyBlue;
        private static Pen dimGray;
        private static Pen dodgerBlue;
        private static Pen firebrick;
        private static Pen floralWhite;
        private static Pen forestGreen;
        private static Pen fuchsia;
        private static Pen gainsboro;
        private static Pen ghostWhite;
        private static Pen gold;
        private static Pen goldenrod;
        private static Pen gray;
        private static Pen green;
        private static Pen greenYellow;
        private static Pen honeydew;
        private static Pen hotPink;
        private static Pen indianRed;
        private static Pen indigo;
        private static Pen ivory;
        private static Pen khaki;
        private static Pen lavender;
        private static Pen lavenderBlush;
        private static Pen lawnGreen;
        private static Pen lemonChiffon;
        private static Pen lightBlue;
        private static Pen lightCoral;
        private static Pen lightCyan;
        private static Pen lightGoldenrodYellow;
        private static Pen lightGray;
        private static Pen lightGreen;
        private static Pen lightPink;
        private static Pen lightSalmon;
        private static Pen lightSeaGreen;
        private static Pen lightSkyBlue;
        private static Pen lightSlateGray;
        private static Pen lightSteelBlue;
        private static Pen lightYellow;
        private static Pen lime;
        private static Pen limeGreen;
        private static Pen linen;
        private static Pen magenta;
        private static Pen maroon;
        private static Pen mediumAquamarine;
        private static Pen mediumBlue;
        private static Pen mediumOrchid;
        private static Pen mediumPurple;
        private static Pen mediumSeaGreen;
        private static Pen mediumSlateBlue;
        private static Pen mediumSpringGreen;
        private static Pen mediumTurquoise;
        private static Pen mediumVioletRed;
        private static Pen midnightBlue;
        private static Pen mintCream;
        private static Pen mistyRose;
        private static Pen moccasin;
        private static Pen navajoWhite;
        private static Pen navy;
        private static Pen oldLace;
        private static Pen olive;
        private static Pen oliveDrab;
        private static Pen orange;
        private static Pen orangeRed;
        private static Pen orchid;
        private static Pen paleGoldenrod;
        private static Pen paleGreen;
        private static Pen paleTurquoise;
        private static Pen paleVioletRed;
        private static Pen papayaWhip;
        private static Pen peachPuff;
        private static Pen peru;
        private static Pen pink;
        private static Pen plum;
        private static Pen powderBlue;
        private static Pen purple;
        private static Pen red;
        private static Pen rosyBrown;
        private static Pen royalBlue;
        private static Pen saddleBrown;
        private static Pen salmon;
        private static Pen sandyBrown;
        private static Pen seaGreen;
        private static Pen seaShell;
        private static Pen sienna;
        private static Pen silver;
        private static Pen skyBlue;
        private static Pen slateBlue;
        private static Pen slateGray;
        private static Pen snow;
        private static Pen springGreen;
        private static Pen steelBlue;
        private static Pen tan;
        private static Pen teal;
        private static Pen thistle;
        private static Pen tomato;
        private static Pen transparent;
        private static Pen turquoise;
        private static Pen violet;
        private static Pen wheat;
        private static Pen white;
        private static Pen whiteSmoke;
        private static Pen yellow;
        private static Pen yellowGreen;
        
        public static Pen AliceBlue
        {
            get
            {
                if (aliceBlue == null)
                    aliceBlue = new Pen(Color.AliceBlue);
                return aliceBlue;
            }
        }
        public static Pen AntiqueWhite
        {
            get
            {
                if (antiqueWhite == null)
                    antiqueWhite = new Pen(Color.AntiqueWhite);
                return antiqueWhite;
            }
        }
        public static Pen Aqua
        {
            get
            {
                if (aqua == null)
                    aqua = new Pen(Color.Aqua);
                return aqua;
            }
        }
        public static Pen Aquamarine
        {
            get
            {
                if (aquamarine == null)
                    aquamarine = new Pen(Color.Aquamarine);
                return aquamarine;
            }
        }
        public static Pen Azure
        {
            get
            {
                if (azure == null)
                    azure = new Pen(Color.Azure);
                return azure;
            }
        }
        public static Pen Beige
        {
            get
            {
                if (beige == null)
                    beige = new Pen(Color.Beige);
                return beige;
            }
        }
        public static Pen Bisque
        {
            get
            {
                if (bisque == null)
                    bisque = new Pen(Color.Bisque);
                return bisque;
            }
        }
        public static Pen Black
        {
            get
            {
                if (black == null)
                    black = new Pen(Color.Black);
                return black;
            }
        }
        public static Pen BlanchedAlmond
        {
            get
            {
                if (blanchedAlmond == null)
                    blanchedAlmond = new Pen(Color.BlanchedAlmond);
                return blanchedAlmond;
            }
        }
        public static Pen Blue
        {
            get
            {
                if (blue == null)
                    blue = new Pen(Color.Blue);
                return blue;
            }
        }
        public static Pen BlueViolet
        {
            get
            {
                if (blueViolet == null)
                    blueViolet = new Pen(Color.BlueViolet);
                return blueViolet;
            }
        }
        public static Pen Brown
        {
            get
            {
                if (brown == null)
                    brown = new Pen(Color.Brown);
                return brown;
            }
        }
        public static Pen BurlyWood
        {
            get
            {
                if (burlyWood == null)
                    burlyWood = new Pen(Color.BurlyWood);
                return burlyWood;
            }
        }
        public static Pen CadetBlue
        {
            get
            {
                if (cadetBlue == null)
                    cadetBlue = new Pen(Color.CadetBlue);
                return cadetBlue;
            }
        }
        public static Pen Chartreuse
        {
            get
            {
                if (chartreuse == null)
                    chartreuse = new Pen(Color.Chartreuse);
                return chartreuse;
            }
        }
        public static Pen Chocolate
        {
            get
            {
                if (chocolate == null)
                    chocolate = new Pen(Color.Chocolate);
                return chocolate;
            }
        }
        public static Pen Coral
        {
            get
            {
                if (coral == null)
                    coral = new Pen(Color.Coral);
                return coral;
            }
        }
        public static Pen CornflowerBlue
        {
            get
            {
                if (cornflowerBlue == null)
                    cornflowerBlue = new Pen(Color.CornflowerBlue);
                return cornflowerBlue;
            }
        }
        public static Pen Cornsilk
        {
            get
            {
                if (cornsilk == null)
                    cornsilk = new Pen(Color.Cornsilk);
                return cornsilk;
            }
        }
        public static Pen Crimson
        {
            get
            {
                if (crimson == null)
                    crimson = new Pen(Color.Crimson);
                return crimson;
            }
        }
        public static Pen Cyan
        {
            get
            {
                if (cyan == null)
                    cyan = new Pen(Color.Cyan);
                return cyan;
            }
        }
        public static Pen DarkBlue
        {
            get
            {
                if (darkBlue == null)
                    darkBlue = new Pen(Color.DarkBlue);
                return darkBlue;
            }
        }
        public static Pen DarkCyan
        {
            get
            {
                if (darkCyan == null)
                    darkCyan = new Pen(Color.DarkCyan);
                return darkCyan;
            }
        }
        public static Pen DarkGoldenrod
        {
            get
            {
                if (darkGoldenrod == null)
                    darkGoldenrod = new Pen(Color.DarkGoldenrod);
                return darkGoldenrod;
            }
        }
        public static Pen DarkGray
        {
            get
            {
                if (darkGray == null)
                    darkGray = new Pen(Color.DarkGray);
                return darkGray;
            }
        }
        public static Pen DarkGreen
        {
            get
            {
                if (darkGreen == null)
                    darkGreen = new Pen(Color.DarkGreen);
                return darkGreen;
            }
        }
        public static Pen DarkKhaki
        {
            get
            {
                if (darkKhaki == null)
                    darkKhaki = new Pen(Color.DarkKhaki);
                return darkKhaki;
            }
        }
        public static Pen DarkMagenta
        {
            get
            {
                if (darkMagenta == null)
                    darkMagenta = new Pen(Color.DarkMagenta);
                return darkMagenta;
            }
        }
        public static Pen DarkOliveGreen
        {
            get
            {
                if (darkOliveGreen == null)
                    darkOliveGreen = new Pen(Color.DarkOliveGreen);
                return darkOliveGreen;
            }
        }
        public static Pen DarkOrange
        {
            get
            {
                if (darkOrange == null)
                    darkOrange = new Pen(Color.DarkOrange);
                return darkOrange;
            }
        }
        public static Pen DarkOrchid
        {
            get
            {
                if (darkOrchid == null)
                    darkOrchid = new Pen(Color.DarkOrchid);
                return darkOrchid;
            }
        }
        public static Pen DarkRed
        {
            get
            {
                if (darkRed == null)
                    darkRed = new Pen(Color.DarkRed);
                return darkRed;
            }
        }
        public static Pen DarkSalmon
        {
            get
            {
                if (darkSalmon == null)
                    darkSalmon = new Pen(Color.DarkSalmon);
                return darkSalmon;
            }
        }
        public static Pen DarkSeaGreen
        {
            get
            {
                if (darkSeaGreen == null)
                    darkSeaGreen = new Pen(Color.DarkSeaGreen);
                return darkSeaGreen;
            }
        }
        public static Pen DarkSlateBlue
        {
            get
            {
                if (darkSlateBlue == null)
                    darkSlateBlue = new Pen(Color.DarkSlateBlue);
                return darkSlateBlue;
            }
        }
        public static Pen DarkSlateGray
        {
            get
            {
                if (darkSlateGray == null)
                    darkSlateGray = new Pen(Color.DarkSlateGray);
                return darkSlateGray;
            }
        }
        public static Pen DarkTurquoise
        {
            get
            {
                if (darkTurquoise == null)
                    darkTurquoise = new Pen(Color.DarkTurquoise);
                return darkTurquoise;
            }
        }
        public static Pen DarkViolet
        {
            get
            {
                if (darkViolet == null)
                    darkViolet = new Pen(Color.DarkViolet);
                return darkViolet;
            }
        }
        public static Pen DeepPink
        {
            get
            {
                if (deepPink == null)
                    deepPink = new Pen(Color.DeepPink);
                return deepPink;
            }
        }
        public static Pen DeepSkyBlue
        {
            get
            {
                if (deepSkyBlue == null)
                    deepSkyBlue = new Pen(Color.DeepSkyBlue);
                return deepSkyBlue;
            }
        }
        public static Pen DimGray
        {
            get
            {
                if (dimGray == null)
                    dimGray = new Pen(Color.DimGray);
                return dimGray;
            }
        }
        public static Pen DodgerBlue
        {
            get
            {
                if (dodgerBlue == null)
                    dodgerBlue = new Pen(Color.DodgerBlue);
                return dodgerBlue;
            }
        }
        public static Pen Firebrick
        {
            get
            {
                if (firebrick == null)
                    firebrick = new Pen(Color.Firebrick);
                return firebrick;
            }
        }
        public static Pen FloralWhite
        {
            get
            {
                if (floralWhite == null)
                    floralWhite = new Pen(Color.FloralWhite);
                return floralWhite;
            }
        }
        public static Pen ForestGreen
        {
            get
            {
                if (forestGreen == null)
                    forestGreen = new Pen(Color.ForestGreen);
                return forestGreen;
            }
        }
        public static Pen Fuchsia
        {
            get
            {
                if (fuchsia == null)
                    fuchsia = new Pen(Color.Fuchsia);
                return fuchsia;
            }
        }
        public static Pen Gainsboro
        {
            get
            {
                if (gainsboro == null)
                    gainsboro = new Pen(Color.Gainsboro);
                return gainsboro;
            }
        }
        public static Pen GhostWhite
        {
            get
            {
                if (ghostWhite == null)
                    ghostWhite = new Pen(Color.GhostWhite);
                return ghostWhite;
            }
        }
        public static Pen Gold
        {
            get
            {
                if (gold == null)
                    gold = new Pen(Color.Gold);
                return gold;
            }
        }
        public static Pen Goldenrod
        {
            get
            {
                if (goldenrod == null)
                    goldenrod = new Pen(Color.Goldenrod);
                return goldenrod;
            }
        }
        public static Pen Gray
        {
            get
            {
                if (gray == null)
                    gray = new Pen(Color.Gray);
                return gray;
            }
        }
        public static Pen Green
        {
            get
            {
                if (green == null)
                    green = new Pen(Color.Green);
                return green;
            }
        }
        public static Pen GreenYellow
        {
            get
            {
                if (greenYellow == null)
                    greenYellow = new Pen(Color.GreenYellow);
                return greenYellow;
            }
        }
        public static Pen Honeydew
        {
            get
            {
                if (honeydew == null)
                    honeydew = new Pen(Color.Honeydew);
                return honeydew;
            }
        }
        public static Pen HotPink
        {
            get
            {
                if (hotPink == null)
                    hotPink = new Pen(Color.HotPink);
                return hotPink;
            }
        }
        public static Pen IndianRed
        {
            get
            {
                if (indianRed == null)
                    indianRed = new Pen(Color.IndianRed);
                return indianRed;
            }
        }
        public static Pen Indigo
        {
            get
            {
                if (indigo == null)
                    indigo = new Pen(Color.Indigo);
                return indigo;
            }
        }
        public static Pen Ivory
        {
            get
            {
                if (ivory == null)
                    ivory = new Pen(Color.Ivory);
                return ivory;
            }
        }
        public static Pen Khaki
        {
            get
            {
                if (khaki == null)
                    khaki = new Pen(Color.Khaki);
                return khaki;
            }
        }
        public static Pen Lavender
        {
            get
            {
                if (lavender == null)
                    lavender = new Pen(Color.Lavender);
                return lavender;
            }
        }
        public static Pen LavenderBlush
        {
            get
            {
                if (lavenderBlush == null)
                    lavenderBlush = new Pen(Color.LavenderBlush);
                return lavenderBlush;
            }
        }
        public static Pen LawnGreen
        {
            get
            {
                if (lawnGreen == null)
                    lawnGreen = new Pen(Color.LawnGreen);
                return lawnGreen;
            }
        }
        public static Pen LemonChiffon
        {
            get
            {
                if (lemonChiffon == null)
                    lemonChiffon = new Pen(Color.LemonChiffon);
                return lemonChiffon;
            }
        }
        public static Pen LightBlue
        {
            get
            {
                if (lightBlue == null)
                    lightBlue = new Pen(Color.LightBlue);
                return lightBlue;
            }
        }
        public static Pen LightCoral
        {
            get
            {
                if (lightCoral == null)
                    lightCoral = new Pen(Color.LightCoral);
                return lightCoral;
            }
        }
        public static Pen LightCyan
        {
            get
            {
                if (lightCyan == null)
                    lightCyan = new Pen(Color.LightCyan);
                return lightCyan;
            }
        }
        public static Pen LightGoldenrodYellow
        {
            get
            {
                if (lightGoldenrodYellow == null)
                    lightGoldenrodYellow = new Pen(Color.LightGoldenrodYellow);
                return lightGoldenrodYellow;
            }
        }
        public static Pen LightGray
        {
            get
            {
                if (lightGray == null)
                    lightGray = new Pen(Color.LightGray);
                return lightGray;
            }
        }
        public static Pen LightGreen
        {
            get
            {
                if (lightGreen == null)
                    lightGreen = new Pen(Color.LightGreen);
                return lightGreen;
            }
        }
        public static Pen LightPink
        {
            get
            {
                if (lightPink == null)
                    lightPink = new Pen(Color.LightPink);
                return lightPink;
            }
        }
        public static Pen LightSalmon
        {
            get
            {
                if (lightSalmon == null)
                    lightSalmon = new Pen(Color.LightSalmon);
                return lightSalmon;
            }
        }
        public static Pen LightSeaGreen
        {
            get
            {
                if (lightSeaGreen == null)
                    lightSeaGreen = new Pen(Color.LightSeaGreen);
                return lightSeaGreen;
            }
        }
        public static Pen LightSkyBlue
        {
            get
            {
                if (lightSkyBlue == null)
                    lightSkyBlue = new Pen(Color.LightSkyBlue);
                return lightSkyBlue;
            }
        }
        public static Pen LightSlateGray
        {
            get
            {
                if (lightSlateGray == null)
                    lightSlateGray = new Pen(Color.LightSlateGray);
                return lightSlateGray;
            }
        }
        public static Pen LightSteelBlue
        {
            get
            {
                if (lightSteelBlue == null)
                    lightSteelBlue = new Pen(Color.LightSteelBlue);
                return lightSteelBlue;
            }
        }
        public static Pen LightYellow
        {
            get
            {
                if (lightYellow == null)
                    lightYellow = new Pen(Color.LightYellow);
                return lightYellow;
            }
        }
        public static Pen Lime
        {
            get
            {
                if (lime == null)
                    lime = new Pen(Color.Lime);
                return lime;
            }
        }
        public static Pen LimeGreen
        {
            get
            {
                if (limeGreen == null)
                    limeGreen = new Pen(Color.LimeGreen);
                return limeGreen;
            }
        }
        public static Pen Linen
        {
            get
            {
                if (linen == null)
                    linen = new Pen(Color.Linen);
                return linen;
            }
        }
        public static Pen Magenta
        {
            get
            {
                if (magenta == null)
                    magenta = new Pen(Color.Magenta);
                return magenta;
            }
        }
        public static Pen Maroon
        {
            get
            {
                if (maroon == null)
                    maroon = new Pen(Color.Maroon);
                return maroon;
            }
        }
        public static Pen MediumAquamarine
        {
            get
            {
                if (mediumAquamarine == null)
                    mediumAquamarine = new Pen(Color.MediumAquamarine);

                return mediumAquamarine;
            }
        }
        public static Pen MediumBlue
        {
            get
            {
                if (mediumBlue == null)
                    mediumBlue = new Pen(Color.MediumBlue);

                return mediumBlue;
            }
        }
        public static Pen MediumOrchid
        {
            get
            {
                if (mediumOrchid == null)
                    mediumOrchid = new Pen(Color.MediumOrchid);

                return mediumOrchid;
            }
        }
        public static Pen MediumPurple
        {
            get
            {
                if (mediumPurple == null)
                    mediumPurple = new Pen(Color.MediumPurple);

                return mediumPurple;
            }
        }
        public static Pen MediumSeaGreen
        {
            get
            {
                if (mediumSeaGreen == null)
                    mediumSeaGreen = new Pen(Color.MediumSeaGreen);

                return mediumSeaGreen;
            }
        }
        public static Pen MediumSlateBlue
        {
            get
            {
                if (mediumSlateBlue == null)
                    mediumSlateBlue = new Pen(Color.MediumSlateBlue);

                return mediumSlateBlue;
            }
        }
        public static Pen MediumSpringGreen
        {
            get
            {
                if (mediumSpringGreen == null)
                    mediumSpringGreen = new Pen(Color.MediumSpringGreen);

                return mediumSpringGreen;
            }
        }
        public static Pen MediumTurquoise
        {
            get
            {
                if (mediumTurquoise == null)
                    mediumTurquoise = new Pen(Color.MediumTurquoise);

                return mediumTurquoise;
            }
        }
        public static Pen MediumVioletRed
        {
            get
            {
                if (mediumVioletRed == null)
                    mediumVioletRed = new Pen(Color.MediumVioletRed);

                return mediumVioletRed;
            }
        }
        public static Pen MidnightBlue
        {
            get
            {
                if (midnightBlue == null)
                    midnightBlue = new Pen(Color.MidnightBlue);

                return midnightBlue;
            }
        }
        public static Pen MintCream
        {
            get
            {
                if (mintCream == null)
                    mintCream = new Pen(Color.MintCream);

                return mintCream;
            }
        }
        public static Pen MistyRose
        {
            get
            {
                if (mistyRose == null)
                    mistyRose = new Pen(Color.MistyRose);

                return mistyRose;
            }
        }
        public static Pen Moccasin
        {
            get
            {
                if (moccasin == null)
                    moccasin = new Pen(Color.Moccasin);

                return moccasin;
            }
        }
        public static Pen NavajoWhite
        {
            get
            {
                if (navajoWhite == null)
                    navajoWhite = new Pen(Color.NavajoWhite);

                return navajoWhite;
            }
        }
        public static Pen Navy
        {
            get
            {
                if (navy == null)
                    navy = new Pen(Color.Navy);

                return navy;
            }
        }
        public static Pen OldLace
        {
            get
            {
                if (oldLace == null)
                    oldLace = new Pen(Color.OldLace);

                return oldLace;
            }
        }
        public static Pen Olive
        {
            get
            {
                if (olive == null)
                    olive = new Pen(Color.Olive);

                return olive;
            }
        }
        public static Pen OliveDrab
        {
            get
            {
                if (oliveDrab == null)
                    oliveDrab = new Pen(Color.OliveDrab);

                return oliveDrab;
            }
        }
        public static Pen Orange
        {
            get
            {
                if (orange == null)
                    orange = new Pen(Color.Orange);

                return orange;
            }
        }
        public static Pen OrangeRed
        {
            get
            {
                if (orangeRed == null)
                    orangeRed = new Pen(Color.OrangeRed);

                return orangeRed;
            }
        }
        public static Pen Orchid
        {
            get
            {
                if (orchid == null)
                    orchid = new Pen(Color.Orchid);

                return orchid;
            }
        }
        public static Pen PaleGoldenrod
        {
            get
            {
                if (paleGoldenrod == null)
                    paleGoldenrod = new Pen(Color.PaleGoldenrod);

                return paleGoldenrod;
            }
        }
        public static Pen PaleGreen
        {
            get
            {
                if (paleGreen == null)
                    paleGreen = new Pen(Color.PaleGreen);

                return paleGreen;
            }
        }
        public static Pen PaleTurquoise
        {
            get
            {
                if (paleTurquoise == null)
                    paleTurquoise = new Pen(Color.PaleTurquoise);

                return paleTurquoise;
            }
        }
        public static Pen PaleVioletRed
        {
            get
            {
                if (paleVioletRed == null)
                    paleVioletRed = new Pen(Color.PaleVioletRed);

                return paleVioletRed;
            }
        }
        public static Pen PapayaWhip
        {
            get
            {
                if (papayaWhip == null)
                    papayaWhip = new Pen(Color.PapayaWhip);

                return papayaWhip;
            }
        }
        public static Pen PeachPuff
        {
            get
            {
                if (peachPuff == null)
                    peachPuff = new Pen(Color.PeachPuff);

                return peachPuff;
            }
        }
        public static Pen Peru
        {
            get
            {
                if (peru == null)
                    peru = new Pen(Color.Peru);

                return peru;
            }
        }
        public static Pen Pink
        {
            get
            {
                if (pink == null)
                    pink = new Pen(Color.Pink);

                return pink;
            }
        }
        public static Pen Plum
        {
            get
            {
                if (plum == null)
                    plum = new Pen(Color.Plum);

                return plum;
            }
        }
        public static Pen PowderBlue
        {
            get
            {
                if (powderBlue == null)
                    powderBlue = new Pen(Color.PowderBlue);

                return powderBlue;
            }
        }
        public static Pen Purple
        {
            get
            {
                if (purple == null)
                    purple = new Pen(Color.Purple);

                return purple;
            }
        }
        public static Pen Red
        {
            get
            {
                if (red == null)
                    red = new Pen(Color.Red);

                return red;
            }
        }
        public static Pen RosyBrown
        {
            get
            {
                if (rosyBrown == null)
                    rosyBrown = new Pen(Color.RosyBrown);

                return rosyBrown;
            }
        }
        public static Pen RoyalBlue
        {
            get
            {
                if (royalBlue == null)
                    royalBlue = new Pen(Color.RoyalBlue);

                return royalBlue;
            }
        }
        public static Pen SaddleBrown
        {
            get
            {
                if (saddleBrown == null)
                    saddleBrown = new Pen(Color.SaddleBrown);

                return saddleBrown;
            }
        }
        public static Pen Salmon
        {
            get
            {
                if (salmon == null)
                    salmon = new Pen(Color.Salmon);

                return salmon;
            }
        }
        public static Pen SandyBrown
        {
            get
            {
                if (sandyBrown == null)
                    sandyBrown = new Pen(Color.SandyBrown);

                return sandyBrown;
            }
        }
        public static Pen SeaGreen
        {
            get
            {
                if (seaGreen == null)
                    seaGreen = new Pen(Color.SeaGreen);

                return seaGreen;
            }
        }
        public static Pen SeaShell
        {
            get
            {
                if (seaShell == null)
                    seaShell = new Pen(Color.SeaShell);

                return seaShell;
            }
        }
        public static Pen Sienna
        {
            get
            {
                if (sienna == null)
                    sienna = new Pen(Color.Sienna);

                return sienna;
            }
        }
        public static Pen Silver
        {
            get
            {
                if (silver == null)
                    silver = new Pen(Color.Silver);

                return silver;
            }
        }
        public static Pen SkyBlue
        {
            get
            {
                if (skyBlue == null)
                    skyBlue = new Pen(Color.SkyBlue);

                return skyBlue;
            }
        }
        public static Pen SlateBlue
        {
            get
            {
                if (slateBlue == null)
                    slateBlue = new Pen(Color.SlateBlue);

                return slateBlue;
            }
        }
        public static Pen SlateGray
        {
            get
            {
                if (slateGray == null)
                    slateGray = new Pen(Color.SlateGray);

                return slateGray;
            }
        }
        public static Pen Snow
        {
            get
            {
                if (snow == null)
                    snow = new Pen(Color.Snow);

                return snow;
            }
        }
        public static Pen SpringGreen
        {
            get
            {
                if (springGreen == null)
                    springGreen = new Pen(Color.SpringGreen);

                return springGreen;
            }
        }
        public static Pen SteelBlue
        {
            get
            {
                if (steelBlue == null)
                    steelBlue = new Pen(Color.SteelBlue);

                return steelBlue;
            }
        }
        public static Pen Tan
        {
            get
            {
                if (tan == null)
                    tan = new Pen(Color.Tan);

                return tan;
            }
        }
        public static Pen Teal
        {
            get
            {
                if (teal == null)
                    teal = new Pen(Color.Teal);

                return teal;
            }
        }
        public static Pen Thistle
        {
            get
            {
                if (thistle == null)
                    thistle = new Pen(Color.Thistle);

                return thistle;
            }
        }
        public static Pen Tomato
        {
            get
            {
                if (tomato == null)
                    tomato = new Pen(Color.Tomato);

                return tomato;
            }
        }
        public static Pen Transparent
        {
            get
            {
                if (transparent == null)
                    transparent = new Pen(Color.Transparent);

                return transparent;
            }
        }
        public static Pen Turquoise
        {
            get
            {
                if (turquoise == null)
                    turquoise = new Pen(Color.Turquoise);

                return turquoise;
            }
        }
        public static Pen Violet
        {
            get
            {
                if (violet == null)
                    violet = new Pen(Color.Violet);

                return violet;
            }
        }
        public static Pen Wheat
        {
            get
            {
                if (wheat == null)
                    wheat = new Pen(Color.Wheat);

                return wheat;
            }
        }
        public static Pen White
        {
            get
            {
                if (white == null)
                    white = new Pen(Color.White);

                return white;
            }
        }
        public static Pen WhiteSmoke
        {
            get
            {
                if (whiteSmoke == null)
                    whiteSmoke = new Pen(Color.WhiteSmoke);

                return whiteSmoke;
            }
        }
        public static Pen Yellow
        {
            get
            {
                if (yellow == null)
                    yellow = new Pen(Color.Yellow);

                return yellow;
            }
        }
        public static Pen YellowGreen
        {
            get
            {
                if (yellowGreen == null)
                    yellowGreen = new Pen(Color.YellowGreen);

                return yellowGreen;
            }
        }
    }
}


<|start_filename|>Assets/System/Windows/Forms/ControlStyles.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    [Flags]
    public enum ControlStyles
    {
        ContainerControl = 0x1,
        UserPaint = 0x2,
        Opaque = 0x4,
        ResizeRedraw = 0x10,
        FixedWidth = 0x20,
        FixedHeight = 0x40,
        StandardClick = 0x100,
        Selectable = 0x200,
        UserMouse = 0x400,
        SupportsTransparentBackColor = 0x800,
        StandardDoubleClick = 0x1000,
        AllPaintingInWmPaint = 0x2000,
        CacheText = 0x4000,
        EnableNotifyMessage = 0x8000,
        DoubleBuffer = 0x10000,
        OptimizedDoubleBuffer = 0x20000,
        UseTextForAccessibility = 0x40000,
    }
}


<|start_filename|>Assets/System/Windows/Forms/ToolStripItemClickedEventArgs.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    public class ToolStripItemClickedEventArgs : EventArgs
    {
        private ToolStripItem clickedItem;

        public ToolStripItemClickedEventArgs(ToolStripItem clickedItem)
        {
            this.clickedItem = clickedItem;
        }

        public ToolStripItem ClickedItem { get { return clickedItem; } }
    }
}


<|start_filename|>Assets/System/Windows/Forms/LinkState.cs<|end_filename|>
﻿namespace System.Windows.Forms
{
    [Flags]
    public enum LinkState
    {
        Normal = 0x00,
        Hover = 0x01,
        Active = 0x02,
        Visited = 0x04
    }
}


<|start_filename|>Assets/System/Windows/Forms/SaveFileDialog.cs<|end_filename|>
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public class SaveFileDialog : FileDialog
    {
        public SaveFileDialog()
        {
            Text = "Save as";

            buttonOk.Text = "Save";
        }
    }
}
