Recently, I am working on the card view program, which requires that the control be made with rounded corners. below is the information I searched online. After testing, I confirmed that the function can be implemented. Method 3 is applicable to both controls and forms.
Upload first:
Method 1:
Add namespace: using System. Drawing. Drawing2D;
The method is as follows: Of course, the points of each angle can be determined as needed.
Type(Control sender, p_1, GraphicsPath oPath = Point(, sender.Height / Point(sender.Width / p_1, Point(sender.Width - sender.Width / p_1, Point(sender.Width, sender.Height / Point(sender.Width, sender.Height - sender.Height / Point(sender.Width - sender.Width / Point(sender.Width / Point(, sender.Height - sender.Height / ( sender.Region = }
Add: Type (this, 20, 0.1) to the form paint and resize events );
Parameters 20 and 0.1 can also be adjusted to the best effect as needed
Method 2:
FormPath = Rectangle rect = Rectangle(, , .Width, .Height - ); FormPath = GetRoundedRectPath(rect, .Region = GraphicsPath GetRoundedRectPath(Rectangle rect, diameter = Rectangle arcRect = Rectangle(rect.Location, GraphicsPath path = path.AddArc(arcRect, , arcRect.X = rect.Right - path.AddArc(arcRect, , arcRect.Y = rect.Bottom - path.AddArc(arcRect, , arcRect.X = path.AddArc(arcRect, , }
Add SetWindowRegion () in the resize event of the form ();
Method 3: Use the number of API lines in the Window system to modify the control and form to an elliptical shape. The Code is as follows:
[System.Runtime.InteropServices.DllImport( [System.Runtime.InteropServices.DllImport( SetBkMode(IntPtr hdc, TRANSPARENT = [System.Runtime.InteropServices.DllImport( [System.Runtime.InteropServices.DllImport( [System.Runtime.InteropServices.DllImport( Ellipse(IntPtr hdc, x1, y1, x2, [System.Runtime.InteropServices.DllImport( IntPtr SetWindowRgn(IntPtr hwnd, IntPtr hRgn, [System.Runtime.InteropServices.DllImport( IntPtr GetDC(IntPtr hwnd);
dc = GetDC( Ellipse(dc, , , .Width - , .Height - region = SetWindowRgn(.Handle, region, }