Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace FormStyle
- {
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Text;
- using System.Runtime.CompilerServices;
- using System.Windows.Forms;
- internal class FlatButton : Control
- {
- private static List<WeakReference> __ENCList = new List<WeakReference>();
- private Color _BaseColor;
- private bool _Rounded;
- private Color _TextColor;
- private int H;
- private MouseState State;
- private int W;
- public FlatButton()
- {
- __ENCAddToList(this);
- this._Rounded = false;
- this.State = MouseState.None;
- this._BaseColor = Color.FromArgb(30, 30, 30);
- this._TextColor = Color.FromArgb(0xd3, 0xd3, 0xd3);
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
- this.DoubleBuffered = true;
- Size size2 = new Size(0x6a, 0x20);
- this.Size = size2;
- this.BackColor = Color.Transparent;
- this.Font = new Font("Segoe UI", 12f);
- this.Cursor = Cursors.Hand;
- }
- [DebuggerNonUserCode]
- private static void __ENCAddToList(object value)
- {
- List<WeakReference> list = __ENCList;
- lock (list)
- {
- if (__ENCList.Count == __ENCList.Capacity)
- {
- int index = 0;
- int num3 = __ENCList.Count - 1;
- for (int i = 0; i <= num3; i++)
- {
- WeakReference reference = __ENCList[i];
- if (reference.IsAlive)
- {
- if (i != index)
- {
- __ENCList[index] = __ENCList[i];
- }
- index++;
- }
- }
- __ENCList.RemoveRange(index, __ENCList.Count - index);
- __ENCList.Capacity = __ENCList.Count;
- }
- __ENCList.Add(new WeakReference(RuntimeHelpers.GetObjectValue(value)));
- }
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- this.State = MouseState.Down;
- this.Invalidate();
- }
- protected override void OnMouseEnter(EventArgs e)
- {
- base.OnMouseEnter(e);
- this.State = MouseState.Over;
- this.Invalidate();
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- this.State = MouseState.None;
- this.Invalidate();
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- base.OnMouseUp(e);
- this.State = MouseState.Over;
- this.Invalidate();
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- Helpers.B = new Bitmap(this.Width, this.Height);
- Helpers.G = Graphics.FromImage(Helpers.B);
- this.W = this.Width - 1;
- this.H = this.Height - 1;
- GraphicsPath path = new GraphicsPath();
- Rectangle rect = new Rectangle(0, 0, this.W, this.H);
- Graphics g = Helpers.G;
- g.SmoothingMode = SmoothingMode.HighQuality;
- g.PixelOffsetMode = PixelOffsetMode.HighQuality;
- g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- g.Clear(this.BackColor);
- switch (this.State)
- {
- case MouseState.None:
- if (!this.Rounded)
- {
- g.FillRectangle(new SolidBrush(this._BaseColor), rect);
- g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF);
- break;
- }
- path = Helpers.RoundRec(rect, 6);
- g.FillPath(new SolidBrush(this._BaseColor), path);
- g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF);
- break;
- case MouseState.Over:
- if (!this.Rounded)
- {
- g.FillRectangle(new SolidBrush(this._BaseColor), rect);
- g.FillRectangle(new SolidBrush(Color.FromArgb(20, Color.White)), rect);
- g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF);
- break;
- }
- path = Helpers.RoundRec(rect, 6);
- g.FillPath(new SolidBrush(this._BaseColor), path);
- g.FillPath(new SolidBrush(Color.FromArgb(20, Color.White)), path);
- g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF);
- break;
- case MouseState.Down:
- if (!this.Rounded)
- {
- g.FillRectangle(new SolidBrush(this._BaseColor), rect);
- g.FillRectangle(new SolidBrush(Color.FromArgb(20, Color.Black)), rect);
- g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF);
- break;
- }
- path = Helpers.RoundRec(rect, 6);
- g.FillPath(new SolidBrush(this._BaseColor), path);
- g.FillPath(new SolidBrush(Color.FromArgb(20, Color.Black)), path);
- g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF);
- break;
- }
- g = null;
- base.OnPaint(e);
- Helpers.G.Dispose();
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- e.Graphics.DrawImageUnscaled(Helpers.B, 0, 0);
- Helpers.B.Dispose();
- }
- [Category("Colors")]
- public Color BaseColor
- {
- get
- {
- return this._BaseColor;
- }
- set
- {
- this._BaseColor = value;
- }
- }
- [Category("Options")]
- public bool Rounded
- {
- get
- {
- return this._Rounded;
- }
- set
- {
- this._Rounded = value;
- }
- }
- [Category("Colors")]
- public Color TextColor
- {
- get
- {
- return this._TextColor;
- }
- set
- {
- this._TextColor = value;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement