C#自定义圆角按钮后,按钮上的text无法显示在按钮上

ANDREGAO0815 2020-03-27 06:27:17
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace CustomerUI
{
public partial class RundEckelButton : Button
{
private int radius; //半径

[CategoryAttribute("布局"), BrowsableAttribute(true), ReadOnlyAttribute(false)]
public int Radius
{
set
{
radius = value;
}
get
{
return radius;
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaintBackground(e);
GraphicsPath path = new GraphicsPath();
path.AddArc(0, 0, radius, radius, 180f, 90f);
path.AddArc(this.Width - radius-1, 0, radius, radius, 270f, 90f);
path.AddArc(this.Width-radius-1, this.Height - radius-1, radius, radius, 0f, 90f);
path.AddArc(0 , this.Height - radius-1, radius, radius, 90f, 90f);
path.CloseFigure();
this.Region = new System.Drawing.Region(path);

}

public RundEckelButton()
{
radius = 10;
this.FlatStyle = FlatStyle;
this.FlatAppearance.BorderSize = 1;
}

private void RundEckelButton_Load(object sender, EventArgs e)
{

}
}
}
...全文
351 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoid 2020-04-13
  • 打赏
  • 举报
回复
文本是需要你自己绘的, 你在画完了圆角图形后,再画文字就好了。
graphics.DrawString方法。

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧