mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-17 02:43:08 +12:00
74 lines
2 KiB
C#
74 lines
2 KiB
C#
// <copyright file="RoundedRectangle.cs" company="PlaceholderCompany">
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
// </copyright>
|
|
|
|
namespace SystemTrayMenu.UserInterface
|
|
{
|
|
using System;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Drawing.Imaging;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows.Forms;
|
|
using SystemTrayMenu.DataClasses;
|
|
using SystemTrayMenu.DllImports;
|
|
using SystemTrayMenu.Helper;
|
|
using SystemTrayMenu.Utilities;
|
|
|
|
public static class RoundedRectangle
|
|
{
|
|
public static GraphicsPath RoundedRect(Rectangle bounds, int radius)
|
|
{
|
|
int diameter = radius * 2;
|
|
Size size = new(diameter, diameter);
|
|
Rectangle arc = new(bounds.Location, size);
|
|
GraphicsPath path = new();
|
|
|
|
if (radius == 0)
|
|
{
|
|
path.AddRectangle(bounds);
|
|
return path;
|
|
}
|
|
|
|
// top left arc
|
|
path.AddArc(arc, 180, 90);
|
|
|
|
// top right arc
|
|
arc.X = bounds.Right - diameter;
|
|
path.AddArc(arc, 270, 90);
|
|
|
|
// bottom right arc
|
|
arc.Y = bounds.Bottom - diameter;
|
|
path.AddArc(arc, 0, 90);
|
|
|
|
// bottom left arc
|
|
arc.X = bounds.Left;
|
|
path.AddArc(arc, 90, 90);
|
|
|
|
path.CloseFigure();
|
|
return path;
|
|
}
|
|
|
|
public static void FillRoundedRectangle(Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius)
|
|
{
|
|
if (graphics == null)
|
|
{
|
|
throw new ArgumentNullException("graphics");
|
|
}
|
|
|
|
if (brush == null)
|
|
{
|
|
throw new ArgumentNullException("brush");
|
|
}
|
|
|
|
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
|
|
{
|
|
graphics.FillPath(brush, path);
|
|
}
|
|
}
|
|
}
|
|
}
|