17

I have a window without borders. I searched net for rounded corners but all with borders. How can i make rounded corners of the form(not with borders) ? Is there a way to do that?

I am a newbie to c#, so please explain...

Thanks

4

3 回答 3

57

尝试这个:

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, // width of ellipse
            int nHeightEllipse // height of ellipse
        );

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

从这里开始:C# 中带有圆角边框的表单?

于 2013-09-16T07:08:18.583 回答
1

Region 属性只是切断了角落。要获得真正的圆角,您必须绘制圆角矩形。

绘制圆角矩形

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

还要检查这个另一个

于 2013-09-16T07:04:06.483 回答
0

我找到了这段代码

为了提出圆角文本框,我开始尝试使用绘制覆盖事件,但不幸的是没有任何结果,这是由于(我假设)文本框是从 Windows 派生的事实。因此,我尝试改写 WM_PAINT API,得到了预期的结果

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

谢谢

于 2014-05-28T00:49:03.103 回答