Я спросил chatGPT, и я последовал его советам, поэтому компилятор не предупредил, но элемент управления был не чем иным, как черным квадратом, вот так: (https://i.sstatic.net/CU8uoQfr.png)
Мой первый источник код здесь:
Код: Выделить всё
using System;
using System.Drawing;
using System.Windows.Forms;
public class RoundedButton : Button
{
public int CornerRadius { get; set; } = 20;
protected override void OnPaint(PaintEventArgs pevent)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddArc(0, 0, CornerRadius, CornerRadius, 180, 90);
path.AddArc(Width - CornerRadius, 0, CornerRadius, CornerRadius, 270, 90);
path.AddArc(Width - CornerRadius, Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
path.AddArc(0, Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
path.CloseFigure();
this.Region = new Region(path);
}
using (SolidBrush brush = new SolidBrush(BackColor))
{
pevent.Graphics.FillPath(brush, path);
}
TextRenderer.DrawText(pevent.Graphics, Text, Font, ClientRectangle, ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
}
}
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BookMs
{
public partial class RoundButton : Button
{
private float radius;
public RoundButton()
{
InitializeComponent();
}
[Description("The radius of the arc.")]
[Category("Behavior")]
public float CornerRadius
{
set
{
this.radius = value;
}
get
{
return this.radius;
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (CornerRadius
Подробнее здесь: [url]https://stackoverflow.com/questions/79147436/user-control-is-so-hard[/url]