Advertisement
Guest User

Electron Theme by AeonHack, converted by Chuiby

a guest
Apr 25th, 2011
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.61 KB | None | 0 0
  1. //Electron Theme
  2. public class ETheme : 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(0, 70, 114);
  58.     private Color C2 = Color.FromArgb(0, 47, 78);
  59.     private Color C3 = Color.FromArgb(0, 34, 57);
  60.     private Color C4 = Color.FromArgb(0, 30, 50);
  61.     protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
  62.     {
  63.     }
  64.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  65.     {
  66.         using (Bitmap B = new Bitmap(Width, Height))
  67.         {
  68.             using (var G = Graphics.FromImage(B))
  69.             {
  70.                 G.Clear(C3);
  71.  
  72.                 Draw.Blend(G, C2, C3, C1, 0.5F, 1, 0, 0, Width, _TitleHeight);
  73.  
  74.                 G.FillRectangle(new SolidBrush(Color.FromArgb(15, 255, 255, 255)), 1, 1, Width - 2, System.Convert.ToInt32(_TitleHeight / 2.0) - 2);
  75.                 G.DrawRectangle(new Pen(Color.FromArgb(35, 255, 255, 255)), 1, 1, Width - 3, _TitleHeight - 2);
  76.  
  77.                 var S = G.MeasureString(Text, Font);
  78.                 var O = 6;
  79.                 if ((int)_TitleAlign == 2)
  80.                 {
  81.                     O = Width / 2 - (int)S.Width / 2;
  82.                 }
  83.                 if ((int)_TitleAlign == 1)
  84.                 {
  85.                     O = Width - (int)S.Width - 14;
  86.                 }
  87.                 var V = System.Convert.ToInt32(_TitleHeight / 2.0 - (S.Height + 4) / 2);
  88.  
  89.                 Draw.Gradient(G, C3, C2, O, V, (int)S.Width + 8, (int)S.Height + 4);
  90.                 G.DrawRectangle(new Pen(C3), O, V, S.Width + 7, S.Height + 3);
  91.  
  92.                 Rectangle R = new Rectangle(O + 4, System.Convert.ToInt32(_TitleHeight / 2 - S.Height / 2), (int)S.Width, (int)S.Height);
  93.                 using (LinearGradientBrush T = new LinearGradientBrush(R, C1, C2, LinearGradientMode.Vertical))
  94.                 {
  95.                     G.DrawString(Text, Font, T, R);
  96.                 }
  97.  
  98.                 G.DrawRectangle(new Pen(C1), 1, _TitleHeight + 1, Width - 3, Height - _TitleHeight - 3);
  99.  
  100.                 G.DrawLine(new Pen(C4), 0, _TitleHeight, Width, _TitleHeight);
  101.                 G.DrawRectangle(new Pen(C4), 0, 0, Width - 1, Height - 1);
  102.                 e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  103.             }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement