C# windows 窗体中的圆角
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18822067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rounded Corners in C# windows forms
提问by Hari krishnan
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?
我有一个没有边界的窗口。我在网上搜索圆角,但都带有边框。如何制作表格的圆角(not with borders)
?有没有办法做到这一点?
I am a newbie to c#, so please explain...
我是 c# 的新手,所以请解释一下...
Thanks
谢谢
采纳答案by AsfK
try this:
尝试这个:
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));
}
}
}
from here: Form with Rounded Borders in C#?
从这里开始:C# 中带有圆角边框的表单?
回答by Vinay Pratap Singh
The Region propery simply cuts off the corners. To have a true rounded corner you will have to draw the rounded rectangles.
Region 属性只是切断了角落。要获得真正的圆角,您必须绘制圆角矩形。
It might be easier to draw an image of the shape you want and put that on the transparent form. Easier to draw but cannot be resized.
绘制所需形状的图像并将其放在透明表单上可能更容易。更容易绘制但不能调整大小。
Also check this Another One
也检查这个另一个
回答by Moayad Myro
I found this code
我找到了这个代码
To come up with the rounded corners textbox, I started trying to work with the paint override event, but unfortunately without any result, which is due to the fact (I assume) that the textbox is derived from Windows. Therefore, I tried overriding the WM_PAINT API instead, which had the desired results
为了提出圆角文本框,我开始尝试使用绘制覆盖事件,但不幸的是没有任何结果,这是由于(我假设)文本框是从 Windows 派生的。因此,我尝试改写 WM_PAINT API,它得到了预期的结果
http://www.codeproject.com/Articles/17453/Textbox-with-rounded-corners
http://www.codeproject.com/Articles/17453/Textbox-with-rounded-corners
Thanks
谢谢