C#窗体中的圆角

Har*_*nan 11 c# windows winforms

我有一个没有边框的窗户.我搜索网的圆角,但都有边框.如何制作表格的圆角(not with borders)?有没有办法做到这一点?

我是c#的新手,所以请解释一下......

谢谢

Asf*_*sfK 36

试试这个:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
        private static extern IntPtr CreateRoundRectRgn
        (
            int nLeftRect,     // x-coordinate of upper-left corner
            int nTopRect,      // y-coordinate of upper-left corner
            int nRightRect,    // x-coordinate of lower-right corner
            int nBottomRect,   // y-coordinate of lower-right corner
            int nWidthEllipse, // height of ellipse
            int nHeightEllipse // width of ellipse
        );

        public Form1()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.None;
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

从这里:C#中带圆角的表格?

  • 尝试在面板上使用它。它只圆化其中一个边缘(左上)! (2认同)
  • 切角的原因是该区域未随窗口调整大小,您需要重新创建它并在调整大小时重新分配 (2认同)