C#窗体中的圆角

时间:2013-09-16 06:59:44

标签: c# windows winforms

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

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

由于

3 个答案:

答案 0 :(得分:33)

试试这个:

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));
        }
    }
}

从这里开始:Form with Rounded Borders in C#?

答案 1 :(得分:1)

地区专业只是切断角落。要拥有真正的圆角,您必须绘制圆角矩形。

Drawing rounded rectangles

绘制所需形状的图像并将其放在透明表格上可能更容易。更容易绘制但无法调整大小。

同时检查此Another One

答案 2 :(得分:0)

我找到了这段代码

为了提出圆角文本框,我开始尝试使用绘制覆盖事件,但遗憾的是没有任何结果,这是由于(我假设)文本框派生自Windows的事实。因此,我尝试重写WM_PAINT API,它具有所需的结果

http://www.codeproject.com/Articles/17453/Textbox-with-rounded-corners

由于