namespace VaioxOnline { using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Windows.Forms; internal class FlatMax : Control { private Color _BaseColor = Color.FromArgb(0x2d, 0x2f, 0x31); private Color _TextColor = Color.FromArgb(0xf3, 0xf3, 0xf3); private MouseState State = MouseState.None; private int x; public FlatMax() { base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); this.DoubleBuffered = true; this.BackColor = Color.White; base.Size = new Size(0x12, 0x12); this.Anchor = AnchorStyles.Right | AnchorStyles.Top; this.Font = new Font("Marlett", 12f); } protected override void OnClick(EventArgs e) { base.OnClick(e); switch (base.FindForm().WindowState) { case FormWindowState.Normal: base.FindForm().WindowState = FormWindowState.Maximized; break; case FormWindowState.Maximized: base.FindForm().WindowState = FormWindowState.Normal; break; } } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); this.State = MouseState.Down; base.Invalidate(); } protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); this.State = MouseState.Over; base.Invalidate(); } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); this.State = MouseState.None; base.Invalidate(); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); this.x = e.X; base.Invalidate(); } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); this.State = MouseState.Over; base.Invalidate(); } protected override void OnPaint(PaintEventArgs e) { Bitmap image = new Bitmap(base.Width, base.Height); Graphics graphics = Graphics.FromImage(image); Rectangle rect = new Rectangle(0, 0, base.Width, base.Height); Graphics graphics2 = graphics; graphics2.SmoothingMode = SmoothingMode.HighQuality; graphics2.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics2.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; graphics2.Clear(this.BackColor); graphics2.FillRectangle(new SolidBrush(this._BaseColor), rect); if (base.FindForm().WindowState == FormWindowState.Maximized) { graphics2.DrawString("1", this.Font, new SolidBrush(this.TextColor), new Rectangle(1, 1, base.Width, base.Height), Helpers.CenterSF); } else if (base.FindForm().WindowState == FormWindowState.Normal) { graphics2.DrawString("2", this.Font, new SolidBrush(this.TextColor), new Rectangle(1, 1, base.Width, base.Height), Helpers.CenterSF); } switch (this.State) { case MouseState.Over: graphics2.FillRectangle(new SolidBrush(Color.FromArgb(30, Color.White)), rect); break; case MouseState.Down: graphics2.FillRectangle(new SolidBrush(Color.FromArgb(30, Color.Black)), rect); break; } graphics2 = null; base.OnPaint(e); graphics.Dispose(); e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.DrawImageUnscaled(image, 0, 0); image.Dispose(); } protected override void OnResize(EventArgs e) { base.OnResize(e); base.Size = new Size(0x12, 0x12); } [Category("Colors")] public Color BaseColor { get => this._BaseColor set { this._BaseColor = value; } } [Category("Colors")] public Color TextColor { get => this._TextColor set { this._TextColor = value; } } } }