在C#7.3版本中是否可以编写一个圆角矩形按钮?我试过这个:
public class RoundCorneredButton : Button
{
protected override void OnPaint(PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath();
int cornerRadius = 10; // Adjust this value to control the roundness of the corners.
// Define the points to create a parallelepiped shape.
Point[] points =
{
new Point(0, Height / 2),
new Point(cornerRadius, 0),
new Point(Width - cornerRadius, 0),
new Point(Width, Height / 2),
new Point(Width - cornerRadius, Height),
new Point(cornerRadius, Height)
};
// Add the points to the GraphicsPath.
path.AddPolygon(points);
// Create a rounded rectangle using the GraphicsPath.
Region roundedRectangle = new Region(path);
// Draw the button's text and focus rectangle.
base.OnPaint(e);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DoubleBuffered = true;
_customButton = new RoundCorneredButton();
_customButton.Text = "Custom Button";
_customButton.Size = new Size(200, 100);
_customButton.Location = new Point(50, 50);
_customButton.FlatStyle = FlatStyle.Standard;
Controls.Add(_customButton);
}
private RoundCorneredButton _customButton;
}
程序将运行并显示一个按钮。问题是角没有倒圆。
1条答案
按热度按时间lymnna711#