97 lines
1.8 KiB
C#
97 lines
1.8 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Windows.Forms;
|
|
|
|
namespace FontPreview;
|
|
|
|
internal class RoundPanel : Panel
|
|
{
|
|
private bool mouseOver;
|
|
|
|
public int Radius { get; set; }
|
|
|
|
public Color BorderColor { get; set; }
|
|
|
|
public Color HoverBorder { get; set; }
|
|
|
|
public RoundPanel()
|
|
{
|
|
DoubleBuffered = true;
|
|
Radius = 10;
|
|
BorderColor = Color.FromArgb(226, 230, 235);
|
|
HoverBorder = Color.FromArgb(98, 137, 200);
|
|
BackColor = Color.White;
|
|
SetStyle((ControlStyles)139266, true);
|
|
}
|
|
|
|
protected override void OnResize(EventArgs eventargs)
|
|
{
|
|
base.OnResize(eventargs);
|
|
if (Width > 0 && Height > 0)
|
|
{
|
|
GraphicsPath path = GetPath();
|
|
try
|
|
{
|
|
Region = new Region(path);
|
|
}
|
|
finally
|
|
{
|
|
path?.Dispose();
|
|
}
|
|
}
|
|
Invalidate();
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
base.OnPaint(e);
|
|
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
GraphicsPath path = GetPath();
|
|
try
|
|
{
|
|
Pen val = new Pen(mouseOver ? HoverBorder : BorderColor, 1.5f);
|
|
try
|
|
{
|
|
e.Graphics.DrawPath(val, path);
|
|
}
|
|
finally
|
|
{
|
|
val?.Dispose();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
path?.Dispose();
|
|
}
|
|
}
|
|
|
|
protected override void OnMouseEnter(EventArgs e)
|
|
{
|
|
mouseOver = true;
|
|
Invalidate();
|
|
base.OnMouseEnter(e);
|
|
}
|
|
|
|
protected override void OnMouseLeave(EventArgs e)
|
|
{
|
|
mouseOver = false;
|
|
Invalidate();
|
|
base.OnMouseLeave(e);
|
|
}
|
|
|
|
private GraphicsPath GetPath()
|
|
{
|
|
int radius = Radius;
|
|
int num = Width - 1;
|
|
int num2 = Height - 1;
|
|
GraphicsPath val = new GraphicsPath();
|
|
val.AddArc(0, 0, radius * 2, radius * 2, 180f, 90f);
|
|
val.AddArc(num - radius * 2, 0, radius * 2, radius * 2, 270f, 90f);
|
|
val.AddArc(num - radius * 2, num2 - radius * 2, radius * 2, radius * 2, 0f, 90f);
|
|
val.AddArc(0, num2 - radius * 2, radius * 2, radius * 2, 90f, 90f);
|
|
val.CloseFigure();
|
|
return val;
|
|
}
|
|
}
|