namespace InstrumentationControls
{
    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Drawing;
    using System.Drawing.Design;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;

    public abstract class InstrumentationControl : Control
    {
        private Bevel bevel = new Bevel(BevelStyle.None, false, false);
        private Timer timer = null;

        public InstrumentationControl()
        {
            base.SetStyle((ControlStyles)0x2000, true);
            base.SetStyle((ControlStyles)0x10000, true);
            base.SetStyle((ControlStyles)2, true);
            base.SetStyle((ControlStyles)0x10, true);
            base.SetStyle((ControlStyles)0x800, true);
            base.SetStyle((ControlStyles)0x200, false);
        }

        protected virtual void Draw(Graphics g, Rectangle r)
        {
            this.DrawBevel(g, r);
        }

        protected virtual void DrawBevel(Graphics g, Rectangle r)
        {
            Rectangle rectangle = this.DisplayRectangle;
            rectangle.Size -= new Size(1, 1);
            this.bevel.Draw(g, rectangle);
        }

        protected virtual void DrawFocus(Graphics g, Rectangle r)
        {
            int margin = this.bevel.GetMargin();
            Rectangle workRectangle = this.WorkRectangle;
            if (margin == 0)
            {
                workRectangle.Width--;
                workRectangle.Height--;
                Pen pen = new Pen(Color.Black);
                pen.DashStyle = (DashStyle) 2;
                g.DrawRectangle(pen, workRectangle);
            }
            else
            {
                workRectangle.X--;
                workRectangle.Y--;
                workRectangle.Width++;
                workRectangle.Height++;
                Pen pen2 = new Pen(Color.LightGreen);
                g.DrawRectangle(pen2, workRectangle);
            }
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            this.Draw(pe.Graphics, pe.ClipRectangle);
            if (this.Focused)
            {
                this.DrawFocus(pe.Graphics, pe.ClipRectangle);
            }
        }
				
        private void SetRegKey(string newRegKey)
        {
            if (base.DesignMode)
            {
                this.timer = new Timer();
                this.timer.Interval = 0x3e8;
                this.timer.Tick += new EventHandler(this.timer_Tick);
                this.timer.Enabled = true;
            }
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this.timer.Enabled = false;
            if ((this.Site != null) && this.Site.DesignMode)
            {
                IComponentChangeService service = (IComponentChangeService) this.Site.GetService(typeof(IComponentChangeService));
            }
        }

			public string About
        {
            get
            {
                return "Something for nothing";
            }
        }

        [Description("Control's Bevel"), DesignerSerializationVisibility((DesignerSerializationVisibility)2), Category("Appearance")]
        public Bevel Bevel
        {
            get
            {
                return this.bevel;
            }
            set
            {
                this.bevel = value;
                base.Invalidate();
            }
        }

        protected virtual Rectangle WorkRectangle
        {
            get
            {
                Rectangle rectangle = this.DisplayRectangle;
                int margin = this.bevel.GetMargin();
                rectangle.Inflate(-margin, -margin);
                return rectangle;
            }
        }
    }
}
