Guest User

Modern Theme by AeonHack, converted by Chuiby

a guest
Apr 25th, 2011
2,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.51 KB | None | 0 0
  1. //Modern Theme
  2. public class MTheme : Control
  3. {
  4.     private int _TitleHeight = 25;
  5.     public int TitleHeight
  6.     {
  7.         get
  8.         {
  9.             return _TitleHeight;
  10.         }
  11.         set
  12.         {
  13.             if (value > Height)
  14.             {
  15.                 value = Height;
  16.             }
  17.             if (value < 2)
  18.             {
  19.                 Height = 1;
  20.             }
  21.             _TitleHeight = value;
  22.             Invalidate();
  23.         }
  24.     }
  25.     private HorizontalAlignment _TitleAlign = (HorizontalAlignment)2;
  26.     public HorizontalAlignment TitleAlign
  27.     {
  28.         get
  29.         {
  30.             return _TitleAlign;
  31.         }
  32.         set
  33.         {
  34.             _TitleAlign = value;
  35.             Invalidate();
  36.         }
  37.     }
  38.     protected override void OnHandleCreated(System.EventArgs e)
  39.     {
  40.         Dock = (DockStyle)5;
  41.         if (Parent is Form)
  42.         {
  43.             ((Form)Parent).FormBorderStyle = 0;
  44.         }
  45.         base.OnHandleCreated(e);
  46.     }
  47.     protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  48.     {
  49.         if (new Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(new Rectangle(MousePosition.X, MousePosition.Y, 1, 1)))
  50.         {
  51.             Capture = false;
  52.             var M = Message.Create(Parent.Handle, 161, new IntPtr(2), new IntPtr(0));
  53.             DefWndProc(ref M);
  54.         }
  55.         base.OnMouseDown(e);
  56.     }
  57.     private Color C1 = Color.FromArgb(74, 74, 74);
  58.     private Color C2 = Color.FromArgb(63, 63, 63);
  59.     private Color C3 = Color.FromArgb(41, 41, 41);
  60.     private Color C4 = Color.FromArgb(27, 27, 27);
  61.     private Color C5 = Color.FromArgb(0, 0, 0, 0);
  62.     private Color C6 = Color.FromArgb(25, 255, 255, 255);
  63.     protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
  64.     {
  65.     }
  66.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  67.     {
  68.         using (Bitmap B = new Bitmap(Width, Height))
  69.         {
  70.             using (var G = Graphics.FromImage(B))
  71.             {
  72.                 G.Clear(C3);
  73.  
  74.                 Draw.Gradient(G, C4, C3, 0, 0, Width, _TitleHeight);
  75.  
  76.                 var S = G.MeasureString(Text, Font);
  77.                 var O = 6;
  78.                 if ((int)_TitleAlign == 2)
  79.                 {
  80.                     O = Width / 2 - (int)S.Width / 2;
  81.                 }
  82.                 if ((int)_TitleAlign == 1)
  83.                 {
  84.                     O = Width - (int)S.Width - 6;
  85.                 }
  86.                 Rectangle R = new Rectangle(O, (_TitleHeight + 2) / 2 - (int)S.Height / 2, (int)S.Width, (int)S.Height);
  87.                 using (LinearGradientBrush T = new LinearGradientBrush(R, C1, C3, LinearGradientMode.Vertical))
  88.                 {
  89.                     G.DrawString(Text, Font, T, R);
  90.                 }
  91.  
  92.                 G.DrawLine(new Pen(C3), 0, 1, Width, 1);
  93.  
  94.                 Draw.Blend(G, C5, C6, C5, 0.5F, 0, 0, _TitleHeight + 1, Width, 1);
  95.  
  96.                 G.DrawLine(new Pen(C4), 0, _TitleHeight, Width, _TitleHeight);
  97.                 G.DrawRectangle(new Pen(C4), 0, 0, Width - 1, Height - 1);
  98.  
  99.                 e.Graphics.DrawImage((Image)B.Clone(), (float)0, (float)0);
  100.             }
  101.         }
  102.     }
  103. }
  104. public class MButton : Control
  105. {
  106.     public MButton()
  107.     {
  108.         ForeColor = Color.FromArgb(65, 65, 65);
  109.     }
  110.     private int State;
  111.     protected override void OnMouseEnter(System.EventArgs e)
  112.     {
  113.         State = 1;
  114.         Invalidate();
  115.         base.OnMouseEnter(e);
  116.     }
  117.     protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  118.     {
  119.         State = 2;
  120.         Invalidate();
  121.         base.OnMouseDown(e);
  122.     }
  123.     protected override void OnMouseLeave(System.EventArgs e)
  124.     {
  125.         State = 0;
  126.         Invalidate();
  127.         base.OnMouseLeave(e);
  128.     }
  129.     protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
  130.     {
  131.         State = 1;
  132.         Invalidate();
  133.         base.OnMouseUp(e);
  134.     }
  135.     private Color C1 = Color.FromArgb(31, 31, 31);
  136.     private Color C2 = Color.FromArgb(41, 41, 41);
  137.     private Color C3 = Color.FromArgb(51, 51, 51);
  138.     private Color C4 = Color.FromArgb(0, 0, 0, 0);
  139.     private Color C5 = Color.FromArgb(25, 255, 255, 255);
  140.     protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
  141.     {
  142.     }
  143.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  144.     {
  145.         using (Bitmap B = new Bitmap(Width, Height))
  146.         {
  147.             using (var G = Graphics.FromImage(B))
  148.             {
  149.                 G.DrawRectangle(new Pen(C1), 0, 0, Width - 1, Height - 1);
  150.  
  151.                 if (State == 2)
  152.                 {
  153.                     Draw.Gradient(G, C2, C3, 1, 1, Width - 2, Height - 2);
  154.                 }
  155.                 else
  156.                 {
  157.                     Draw.Gradient(G, C3, C2, 1, 1, Width - 2, Height - 2);
  158.                 }
  159.  
  160.                 var O = G.MeasureString(Text, Font);
  161.                 G.DrawString(Text, Font, new SolidBrush(ForeColor), Width / 2 - O.Width / 2, Height / 2 - O.Height / 2);
  162.  
  163.                 Draw.Blend(G, C4, C5, C4, 0.5F, 0, 1, 1, Width - 2, 1);
  164.  
  165.                 e.Graphics.DrawImage((Image)B.Clone(), (float)0, (float)0);
  166.             }
  167.         }
  168.     }
  169. }
  170. public class MProgress : Control
  171. {
  172.     private int _Value;
  173.     public int Value
  174.     {
  175.         get
  176.         {
  177.             return _Value;
  178.         }
  179.         set
  180.         {
  181.             _Value = value;
  182.             Invalidate();
  183.         }
  184.     }
  185.     private int _Maximum = 100;
  186.     public int Maximum
  187.     {
  188.         get
  189.         {
  190.             return _Maximum;
  191.         }
  192.         set
  193.         {
  194.             if (value == 0)
  195.             {
  196.                 value = 1;
  197.             }
  198.             _Maximum = value;
  199.             Invalidate();
  200.         }
  201.     }
  202.     private Color C1 = Color.FromArgb(31, 31, 31);
  203.     private Color C2 = Color.FromArgb(41, 41, 41);
  204.     private Color C3 = Color.FromArgb(51, 51, 51);
  205.     private Color C4 = Color.FromArgb(0, 0, 0, 0);
  206.     private Color C5 = Color.FromArgb(25, 255, 255, 255);
  207.     protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
  208.     {
  209.     }
  210.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  211.     {
  212.         int V = Width * _Value / _Maximum;
  213.         using (Bitmap B = new Bitmap(Width, Height))
  214.         {
  215.             using (var G = Graphics.FromImage(B))
  216.             {
  217.                 Draw.Gradient(G, C2, C3, 1, 1, Width - 2, Height - 2);
  218.                 G.DrawRectangle(new Pen(C2), 1, 1, V - 3, Height - 3);
  219.                 Draw.Gradient(G, C3, C2, 2, 2, V - 4, Height - 4);
  220.  
  221.                 G.DrawRectangle(new Pen(C1), 0, 0, Width - 1, Height - 1);
  222.  
  223.                 e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  224.             }
  225.         }
  226.     }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment