context: namespace MiniTimer_Theme
  {
  
  #region  Imports
  
      using System.Collections.Generic;
      using System;
      using System.Drawing;
      using System.Collections;
      using System.Windows.Forms;
      using System.Drawing.Drawing2D;
      using System.ComponentModel;
  	
  #endregion
  	
  	//|------DO-NOT-REMOVE------|
  	//
  	// Creator: HazelDev
  	// Site   : HazelDev.com
  	// Created: 13.Oct.2014
  	// Changed: 15.Oct.2014
  	// Version: 1.0.0
  	//
  	//|------DO-NOT-REMOVE------|
  	
  #region  ThemeContainer
  	
  	public class MiniTimer_ThemeContainer : ContainerControl
  	{
  		
  #region  Enums
  		
  		public enum MouseState
  		{
  			None = 0,
  			Over = 1,
  			Down = 2,
  			Block = 3
  		}
  		
  #endregion
  #region  Variables
  		
  		private Rectangle HeaderRect;
  		protected MouseState State;
  		private int MoveHeight;
  		private Point MouseP = new Point(0, 0);
  		private bool Cap = false;
  		private bool HasShown;
  		
  #endregion
  #region  Properties
  		
  		private bool _Sizable = true;
  public bool Sizable
  		{
  			get
  			{
  				return _Sizable;
  			}
  			set
  			{
  				_Sizable = value;
  			}
  		}
  		
  		private bool _SmartBounds = true;
  public bool SmartBounds
  		{
  			get
  			{
  				return _SmartBounds;
  			}
  			set
  			{
  				_SmartBounds = value;
  			}
  		}
  		
  		private bool _IsParentForm;
  protected bool IsParentForm
  		{
  			get
  			{
  				return _IsParentForm;
  			}
  		}
  		
  protected bool IsParentMdi
  		{
  			get
  			{
  				if (Parent == null)
  				{
  					return false;
  				}
  				return Parent.Parent != null;
  			}
  		}
  		
  		private bool _ControlMode;
  protected bool ControlMode
  		{
  			get
  			{
  				return _ControlMode;
  			}
  			set
  			{
  				_ControlMode = value;
  				Invalidate();
  			}
  		}
  		
  		private FormStartPosition _StartPosition;
  public FormStartPosition StartPosition
  		{
  			get
  			{
  				if (_IsParentForm && !_ControlMode)
  				{
  					return ParentForm.StartPosition;
  				}
  				else
  				{
  					return _StartPosition;
  				}
  			}
  			set
  			{
  				_StartPosition = value;
  				
  				if (_IsParentForm && !_ControlMode)
  				{
  					ParentForm.StartPosition = value;
  				}
  			}
  		}
  		
  #endregion
  #region  EventArgs
  		
  		protected sealed override void OnParentChanged(EventArgs e)
  		{
  			base.OnParentChanged(e);
  			
  			if (Parent == null)
  			{
  				return ;
  			}
  			_IsParentForm = Parent is Form;
  			
  			if (!_ControlMode)
  			{
  				InitializeMessages();
  				
  				if (_IsParentForm)
  				{
  					this.ParentForm.FormBorderStyle = FormBorderStyle.None;
  					this.ParentForm.TransparencyKey = Color.Fuchsia;
  					
  					if (!DesignMode)
  					{
  						ParentForm.Shown += FormShown;
  					}
  				}
  				Parent.BackColor = BackColor;
  				Parent.MinimumSize = new Size(261, 65);
  			}
  		}
  		
  		protected sealed override void OnSizeChanged(EventArgs e)
  		{
  			base.OnSizeChanged(e);
  			if (!_ControlMode)
  			{
  				HeaderRect = new Rectangle(0, 0, Width - 14, MoveHeight - 7);
  			}
  			Invalidate();
  		}
  		
  		protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  		{
  			base.OnMouseDown(e);
  			if (e.Button == MouseButtons.Left)
  			{
  				SetState(MouseState.Down);
  			}
  			if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized || _ControlMode))
  			{
  				if (HeaderRect.Contains(e.Location))
  				{
  					Capture = false;
  					WM_LMBUTTONDOWN = true;
  					DefWndProc(ref Messages[0]);
  				}
  				else if (_Sizable && !(Previous == 0))
  				{
  					Capture = false;
  					WM_LMBUTTONDOWN = true;
  					DefWndProc(ref Messages[Previous]);
  				}
  			}
  		}
  		
  		protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
  		{
  			base.OnMouseUp(e);
  			Cap = false;
  		}
  		
  		protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
  		{
  			base.OnMouseMove(e);
  			if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized))
  			{
  				if (_Sizable && !_ControlMode)
  				{
  					InvalidateMouse();
  				}
  			}
  			if (Cap)
  			{
  				Parent.Location = (System.Drawing.Point) ((object) (System.Convert.ToDouble(MousePosition ) - System.Convert.ToDouble( MouseP)));
  			}
  		}
  		
  		protected override void OnInvalidated(System.Windows.Forms.InvalidateEventArgs e)
  		{
  			base.OnInvalidated(e);
  			ParentForm.Text = Text;
  		}
  		
  		protected override void OnPaintBackground(PaintEventArgs e)
  		{
  			base.OnPaintBackground(e);
  		}
  		
  		protected override void OnTextChanged(System.EventArgs e)
  		{
  			base.OnTextChanged(e);
  			Invalidate();
  		}
  		
  		private void FormShown(object sender, EventArgs e)
  		{
  			if (_ControlMode || HasShown)
  			{
  				return ;
  			}
  			
  			if (_StartPosition == FormStartPosition.CenterParent || _StartPosition == FormStartPosition.CenterScreen)
  			{
  				Rectangle SB = Screen.PrimaryScreen.Bounds;
  				Rectangle CB = ParentForm.Bounds;
  				ParentForm.Location = new Point(SB.Width / 2 - CB.Width / 2, SB.Height / 2 - CB.Width / 2);
  			}
  			HasShown = true;
  		}
  		
  #endregion
  #region  Mouse & Size
  		
  		private void SetState(MouseState current)
  		{
  			State = current;
  			Invalidate();
  		}
  		
  		private Point GetIndexPoint;
  		private bool B1x;
  		private bool B2x;
  		private bool B3;
  		private bool B4;
  		private int GetIndex()
  		{
  			GetIndexPoint = PointToClient(MousePosition);
  			B1x = GetIndexPoint.X < 7;
  			B2x = GetIndexPoint.X > Width - 7;
  			B3 = GetIndexPoint.Y < 7;
  			B4 = GetIndexPoint.Y > Height - 7;
  			
  			if (B1x && B3)
  			{
  				return 4;
  			}
  			if (B1x && B4)
  			{
  				return 7;
  			}
  			if (B2x && B3)
  			{
  				return 5;
  			}
  			if (B2x && B4)
  			{
  				return 8;
  			}
  			if (B1x)
  			{
  				return 1;
  			}
  			if (B2x)
  			{
  				return 2;
  			}
  			if (B3)
  			{
  				return 3;
  			}
  			if (B4)
  			{
  				return 6;
  			}
  			return 0;
  		}
  		
  		private int Current;
  		private int Previous;
  		private void InvalidateMouse()
  		{
  			Current = GetIndex();
  			if (Current == Previous)
  			{
  				return ;
  			}
  			
  			Previous = Current;
  			switch (Previous)
  			{
  				case 0:
  					Cursor = Cursors.Default;
  					break;
  				case 6:
  					Cursor = Cursors.SizeNS;
  					break;
  				case 8:
  					Cursor = Cursors.SizeNWSE;
  					break;
  				case 7:
  					Cursor = Cursors.SizeNESW;
  					break;
  			}
  		}
  		
  		private Message[] Messages = new Message[9];
  		private void InitializeMessages()
  		{
  			Messages[0] = Message.Create(Parent.Handle, 161, new IntPtr(2), IntPtr.Zero);
  			for (int I = 1; I <= 8; I++)
  			{
  				Messages[I] = Message.Create(Parent.Handle, 161, new IntPtr(I + 9), IntPtr.Zero);
  			}
  		}
  		
  		private void CorrectBounds(Rectangle bounds)
  		{
  			if (Parent.Width > bounds.Width)
  			{
  				Parent.Width = bounds.Width;
  			}
  			if (Parent.Height > bounds.Height)
  			{
  				Parent.Height = bounds.Height;
  			}
  			
  			int X = Parent.Location.X;
  			int Y = Parent.Location.Y;
  			
  			if (X < bounds.X)
  			{
  				X = bounds.X;
  			}
  			if (Y < bounds.Y)
  			{
  				Y = bounds.Y;
  			}
  			
  			int Width = bounds.X + bounds.Width;
  			int Height = bounds.Y + bounds.Height;
  			
  			if (X + Parent.Width > Width)
  			{
  				X = Width - Parent.Width;
  			}
  			if (Y + Parent.Height > Height)
  			{
  				Y = Height - Parent.Height;
  			}
  			
  			Parent.Location = new Point(X, Y);
  		}
  		
  		private bool WM_LMBUTTONDOWN;
  		protected override void WndProc(ref Message m)
  		{
  			base.WndProc(ref m);
  			
  			if (WM_LMBUTTONDOWN && m.Msg == 513)
  			{
  				WM_LMBUTTONDOWN = false;
  				
  				SetState(MouseState.Over);
  				if (!_SmartBounds)
  				{
  					return ;
  				}
  				
  				if (IsParentMdi)
  				{
  					CorrectBounds(new Rectangle(Point.Empty, Parent.Parent.Size));
  				}
  				else
  				{
  					CorrectBounds(Screen.FromControl(Parent).WorkingArea);
  				}
  			}
  		}
  		
  #endregion
  		
  		protected override void CreateHandle()
  		{
  			base.CreateHandle();
  		}
  		
  		public MiniTimer_ThemeContainer()
  		{
  			SetStyle((ControlStyles) (139270), true);
  			BackColor = Color.White;
  			Padding = new Padding(20, 56, 20, 16);
  			DoubleBuffered = true;
  			Dock = DockStyle.Fill;
  			MoveHeight = 48;
  			Font = new Font("Segoe UI", 9);
  			_Sizable = false;
  		}
  		
  		protected override void OnPaint(PaintEventArgs e)
  		{
  			base.OnPaint(e);
  			Graphics G = e.Graphics;
  			G.Clear(Color.FromArgb(255, 255, 255));
  
              G.DrawRectangle(new Pen(Color.FromArgb(221, 221, 221)), new Rectangle(0, 0, Width - 1, Height - 1));
  
              G.FillRectangle(new LinearGradientBrush(new Point(0, 0), new Point(0, 39), Color.FromArgb(255, 255, 255), Color.FromArgb(255, 255, 255)), new Rectangle(1, 1, Width - 2, 39));
              G.DrawLine(new Pen(Color.FromArgb(221, 221, 221)), 1, 41, Width - 2, 41);
              G.FillRectangle(new LinearGradientBrush(new Point(0, 0), new Point(0, Height), Color.FromArgb(238, 238, 238), Color.FromArgb(238, 238, 238)), new Rectangle(1, Height - 42, Width - 2, 41));
              G.DrawLine(new Pen(Color.FromArgb(222, 222, 222)), 1, Height - 44, Width - 2, Height - 44);
              G.DrawLine(new Pen(Color.FromArgb(251, 251, 251)), 1, Height - 43, Width - 2, Height - 43);
              G.DrawString("", new Font("Tahoma", (float)(10.5F), FontStyle.Bold),
                  new SolidBrush(Color.FromArgb(129, 151, 172)), new Rectangle(0, 12, Width - 12, Height),
                  new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near });
          }
  	}
  	
  #endregion
  #region  ControlBox
  
      public class MiniTimer_ControlBox : Control
      {
  
          #region  Enums
  
          public enum MouseState
          {
              None = 0,
              Over = 1,
              Down = 2
          }
  
          #endregion
          #region  MouseStates
          MouseState State = MouseState.None;
          int X;
          Rectangle CloseBtn = new Rectangle(3, 2, 11, 11);
          Rectangle MinBtn = new Rectangle(23, 2, 11, 11);
          Rectangle MaxBtn = new Rectangle(43, 2, 11, 11);
  
          protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
          {
              base.OnMouseDown(e);
  
              State = MouseState.Down;
              Invalidate();
          }
          protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
          {
              base.OnMouseUp(e);
              if (X > 3 && X < 20)
              {
                  // FindForm.Close()
                  //frmBounds.Default.Opacity2.Enabled = true;
                  //FrmMain.Default.Opacity1.Enabled = false;
              }
              else if (X > 23 && X < 40)
              {
  
gt:                 FindForm().WindowState = FormWindowState.Minimized;