C # developing a rounded corner control (form)

Source: Internet
Author: User

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,          }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.