Advertisement
PatPositron

Untitled

Apr 20th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.64 KB | None | 0 0
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. using System.Drawing.Drawing2D;
  4.  
  5. public static class Static
  6. {
  7.     public static Font Font = new Font("Helvetica", 9, FontStyle.Bold);
  8.     public static StringFormat Format = new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center };
  9.  
  10.     public static GraphicsPath RoundRect(Rectangle Rectangle, int Curve)
  11.     {
  12.         var P = new GraphicsPath();
  13.         var ArcRectangleWidth = Curve * 2;
  14.         P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90);
  15.         P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90);
  16.         P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90);
  17.         P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90);
  18.         P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
  19.         return P;
  20.     }
  21.     public static GraphicsPath RoundRect(int X, int Y, int Width, int Height, int Curve)
  22.     {
  23.         var Rectangle = new Rectangle(X, Y, Width, Height);
  24.         var P = new GraphicsPath();
  25.         int ArcRectangleWidth = Curve * 2;
  26.         P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90);
  27.         P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90);
  28.         P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90);
  29.         P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90);
  30.         P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
  31.         return P;
  32.     }
  33. }
  34.  
  35. public class Facebook_WhiteButton : Control
  36. {
  37.     private bool IsMouseDown = false;
  38.  
  39.     private SolidBrush TB;
  40.  
  41.     public Facebook_WhiteButton()
  42.     {
  43.         SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  44.         Size = new Size(131, 25);
  45.         Font = Static.Font;
  46.         TB = new SolidBrush(Color.FromArgb(102, 102, 102));
  47.     }
  48.  
  49.     protected override void OnPaint(PaintEventArgs e)
  50.     {
  51.         var G = e.Graphics;
  52.         G.Clear(Color.White);
  53.  
  54.         if (IsMouseDown)
  55.         {
  56.             G.FillPath(new SolidBrush(Color.White), Static.RoundRect(new Rectangle(0, 0, Width - 1, Height), 2));
  57.             G.DrawPath(new Pen(Color.FromArgb(225, 226, 228)), Static.RoundRect(new Rectangle(0, 0, Width - 1, Height - 2), 2));
  58.             G.DrawLine(new Pen(Color.FromArgb(202, 203, 205)), new Point(0, Height), new Point(Width, Height));
  59.             G.DrawLine(new Pen(Color.FromArgb(242, 243, 245)), new Point(1, Height - 1), new Point(Width - 2, Height - 1));
  60.         }
  61.         else
  62.         {
  63.             G.FillPath(new SolidBrush(Color.FromArgb(249, 250, 251)), Static.RoundRect(new Rectangle(0, 0, Width - 1, Height), 2));
  64.             G.DrawPath(new Pen(Color.FromArgb(205, 206, 208)), Static.RoundRect(new Rectangle(0, 0, Width - 1, Height - 2), 2));
  65.             G.DrawLine(new Pen(Color.FromArgb(232, 233, 235)), new Point(1, Height - 1), new Point(Width - 2, Height - 1));
  66.         }
  67.  
  68.         G.DrawString(Text, Font, TB, Bounds, Static.Format);
  69.     }
  70.  
  71.     protected override void OnMouseDown(MouseEventArgs e)
  72.     {
  73.         IsMouseDown = true;
  74.         Invalidate();
  75.         base.OnMouseDown(e);
  76.     }
  77.  
  78.     protected override void OnMouseUp(MouseEventArgs e)
  79.     {
  80.         IsMouseDown = false;
  81.         Invalidate();
  82.         base.OnMouseUp(e);
  83.     }
  84. }
  85.  
  86. public class Facebook_BlueButton : Control
  87. {
  88.     private bool IsMouseDown = false;
  89.  
  90.     private Color G1, G2;
  91.     private LinearGradientBrush B;
  92.  
  93.     public Facebook_BlueButton()
  94.     {
  95.         SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  96.         Size = new Size(131, 25);
  97.         ForeColor = Color.LightGray;
  98.         Font = Static.Font;
  99.         G1 = Color.FromArgb(99, 123, 173);
  100.         G2 = Color.FromArgb(79, 103, 153);
  101.     }
  102.  
  103.     protected override void OnPaint(PaintEventArgs e)
  104.     {
  105.         var G = e.Graphics;
  106.         G.Clear(Color.White);
  107.  
  108.         if (IsMouseDown)
  109.         {
  110.             B = new LinearGradientBrush(new Point(0, 0), new Point(0, Height), G2, G1);
  111.         }
  112.         else
  113.         {
  114.             B = new LinearGradientBrush(new Point(0, 0), new Point(0, Height), G1, G2);
  115.             G.DrawLine(new Pen(Color.FromArgb(119, 142, 193)), new Point(1, 1), new Point(Width - 2, 1));
  116.         }
  117.  
  118.         G.FillPath(B, Static.RoundRect(new Rectangle(0, 0, Width - 1, Height), 2));
  119.         G.DrawPath(new Pen(Color.FromArgb(29, 56, 113)), Static.RoundRect(new Rectangle(0, 0, Width - 1, Height - 1), 2));
  120.  
  121.         G.DrawString(Text, Font, Brushes.White, Bounds, Static.Format);
  122.     }
  123.  
  124.     protected override void OnMouseDown(MouseEventArgs e)
  125.     {
  126.         IsMouseDown = true;
  127.         Invalidate();
  128.         base.OnMouseDown(e);
  129.     }
  130.  
  131.     protected override void OnMouseUp(MouseEventArgs e)
  132.     {
  133.         IsMouseDown = false;
  134.         Invalidate();
  135.         base.OnMouseUp(e);
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement