mounten1 Asked:2020-05-26 04:00:05 +0800 CST2020-05-26 04:00:05 +0800 CST 2020-05-26 04:00:05 +0800 CST 圆形 PictureBox 边缘 772 请告诉我如何制作带有圆边 PictureBox 的课程。我正在使用 Winforms。 c# 1 个回答 Voted Best Answer koshe 2020-05-26T14:12:21+08:002020-05-26T14:12:21+08:00 这是您问题的答案:https ://stackoverflow.com/questions/32987649/how-to-create-a-user-control-with-rounded-corners 。如果你在 PictureBox 下重新制作它,它会变成这样: public class PictureBoxEx:PictureBox { private int radius = 20; [DefaultValue(20)] public int Radius { get { return radius; } set { radius = value; this.RecreateRegion(); } } private GraphicsPath GetRoundRectagle(Rectangle bounds, int radius) { GraphicsPath path = new GraphicsPath(); path.AddArc(bounds.X, bounds.Y, radius, radius, 180, 90); path.AddArc(bounds.X + bounds.Width - radius, bounds.Y, radius, radius, 270, 90); path.AddArc(bounds.X + bounds.Width - radius, bounds.Y + bounds.Height - radius, radius, radius, 0, 90); path.AddArc(bounds.X, bounds.Y + bounds.Height - radius, radius, radius, 90, 90); path.CloseAllFigures(); return path; } private void RecreateRegion() { var bounds = ClientRectangle; bounds.Width--; bounds.Height--; using (var path = GetRoundRectagle(bounds, this.Radius)) this.Region = new Region(path); this.Invalidate(); } protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); this.RecreateRegion(); } }
这是您问题的答案:https ://stackoverflow.com/questions/32987649/how-to-create-a-user-control-with-rounded-corners 。如果你在 PictureBox 下重新制作它,它会变成这样: