Home > Net > With rounded corners for WInForm modify button shape, only the top left corner is rounded
With rounded corners for WInForm modify button shape, only the top left corner is rounded
Time:10-10
using System; Using System. Collections. Generic; Using System.Com ponentModel; Using System. The Data; Using System. Drawing; Using System. Linq; Using System. The Text; Using System. The Threading. The Tasks; Using System. Windows. Forms; Using System. Drawing. Drawing2D;
The namespace WindowsFormsApplication6. Button. _03 {
Public partial class Form1: Form {
Public _click () { InitializeComponent (); } Private void button1_Click (object sender, EventArgs e) { } Private void Form1_Load (object sender, EventArgs e) { } Protected override void OnPaint (PaintEventArgs PE) { GraphicsPath path=new GraphicsPath (); A Rectangle the rect=new Rectangle (0, 22, this Width, enclosing Height - 22). Path=GetRoundedRectPath (the rect, 20); Region reg=new Region (path); This. For. Region=reg; Base. The OnPaint (PE); } Private GraphicsPath GetRoundedRectPath (a Rectangle the rect, radius, int) { Int diameter=radius; A Rectangle arcRect=new Rectangle (the rect. The Location, the new Size (diameter, diameter)); GraphicsPath path=new GraphicsPath (); //the top left corner Path. AddArc (arcRect, 180, 90); //the top right corner ArcRect. X=the rect. Right - diameter; Path. AddArc (arcRect, 270, 90); //at the bottom right ArcRect. Y=the rect. Bottom - 0; Path. AddArc (arcRect, 0, 90); //left corner ArcRect. X=the rect. Left; Path. AddArc (arcRect, 90, 90); Path. CloseFigure (); Return path. } Private void SetWindowRegion (object sender, EventArgs e) { } Private void OnPaint (object sender, EventArgs e) { } }
}
CodePudding user response:
Clearly set enclosing. For the Region this is wrong,
CodePudding user response:
Every time when painting the rounded with a Rectangle arcRect? Position does not change?