123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace Optimizer
- {
- public sealed class MoonButton : Button
- {
- private int _borderRadius = 5;
- public MoonButton()
- {
- BackColor = Color.White;
- ForeColor = Color.Black;
- FlatStyle = FlatStyle.Flat;
- FlatAppearance.BorderSize = 0;
- }
- private GraphicsPath GetFigurePath(Rectangle rect, int radius)
- {
- GraphicsPath path = new GraphicsPath();
- float curveSize = radius * 2F;
- path.StartFigure();
- path.AddArc(rect.X, rect.Y, curveSize, curveSize, 180, 90);
- path.AddArc(rect.Right - curveSize, rect.Y, curveSize, curveSize, 270, 90);
- path.AddArc(rect.Right - curveSize, rect.Bottom - curveSize, curveSize, curveSize, 0, 90);
- path.AddArc(rect.X, rect.Bottom - curveSize, curveSize, curveSize, 90, 90);
- path.CloseFigure();
- return path;
- }
- protected override void OnPaint(PaintEventArgs pevent)
- {
- base.OnPaint(pevent);
- pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- pevent.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
- pevent.Graphics.InterpolationMode = InterpolationMode.High;
- Rectangle rectSurface = ClientRectangle;
- Rectangle rectBorder = Rectangle.Inflate(rectSurface, 0, 0);
- using (GraphicsPath pathSurface = GetFigurePath(rectSurface, _borderRadius))
- using (GraphicsPath pathBorder = GetFigurePath(rectBorder, _borderRadius))
- using (Pen penSurface = new Pen(Parent.BackColor, 2))
- {
- Region = new Region(pathSurface);
- pevent.Graphics.DrawPath(penSurface, pathSurface);
- }
- }
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- if (_borderRadius > Height)
- _borderRadius = Height;
- }
- }
- }
|