SHARE
TWEET

Untitled

a guest Sep 17th, 2017 1,819 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using System.Drawing;
  8.  
  9. namespace NewButton
  10. {
  11.     public class FlatButton : Button
  12.     {
  13.         public FlatButton()
  14.         {
  15.             BackColor = Color.DodgerBlue;
  16.             ForeColor = Color.White;
  17.             CurrentBackColor = BackColor;
  18.         }
  19.  
  20.         private Color CurrentBackColor;
  21.  
  22.         private Color onHoverBackColor = Color.DarkOrchid;
  23.         public Color OnHoverBackColor
  24.         {
  25.             get { return onHoverBackColor; }
  26.             set { onHoverBackColor = value; Invalidate(); }
  27.         }
  28.  
  29.         protected override void OnMouseEnter(EventArgs e)
  30.         {
  31.             base.OnMouseEnter(e);
  32.             CurrentBackColor = onHoverBackColor;
  33.             Invalidate();
  34.         }
  35.  
  36.         protected override void OnMouseLeave(EventArgs e)
  37.         {
  38.             base.OnMouseLeave(e);
  39.             CurrentBackColor = BackColor;
  40.             Invalidate();
  41.         }
  42.  
  43.         protected override void OnMouseDown(MouseEventArgs mevent)
  44.         {
  45.             base.OnMouseDown(mevent);
  46.             CurrentBackColor = Color.RoyalBlue;
  47.             Invalidate();
  48.         }
  49.  
  50.         protected override void OnMouseUp(MouseEventArgs mevent)
  51.         {
  52.             base.OnMouseUp(mevent);
  53.             CurrentBackColor = BackColor;
  54.             Invalidate();
  55.         }
  56.  
  57.         protected override void OnPaint(PaintEventArgs pevent)
  58.         {
  59.             base.OnPaint(pevent);
  60.             pevent.Graphics.FillRectangle(new SolidBrush(CurrentBackColor), 0, 0, Width, Height);
  61.             TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter;
  62.             TextRenderer.DrawText(pevent.Graphics, Text, Font, new Point(Width + 3, Height / 2), ForeColor, flags);
  63.         }
  64.     }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top