与自定义边框和圆滑的边缘C#形式 [英] C# Form with custom border and rounded edges

查看:335
本文介绍了与自定义边框和圆滑的边缘C#形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这code,使我的表格(FormBorderStyle =无)与圆滑的边缘:

I am using this code to make my form (FormBorderStyle=none) with rounded edges:

[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();
    Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
}

和这个设置自定义边框的Paint事件:

And this to set a custom border on the Paint event:

    ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid);

但看到这个

But see this .

内部形式矩形不具有圆形的边缘。

The inside form rectangle doesn't have rounded edges.

我怎样才能让里面的蓝色长方形的形式有圆形边缘也因此它不会像截图?

How can I make the blue inside form rectangle to have rounded edge too so it wont look like the screenshot?

推荐答案

该地区属性格式简单地切断角落。为了有一个真正的圆角,你将不得不绘制圆角矩形。

The Region propery simply cuts off the corners. To have a true rounded corner you will have to draw the rounded rectangles.

<一个href=\"http://stackoverflow.com/questions/1967944/how-to-draw-a-rounded-rectangle-with-winforms-net\">Drawing圆角矩形

这可能更容易吸引你想要的形状的图像,并把那个透明的形式。容易得出,但不能调整大小。

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.

这篇关于与自定义边框和圆滑的边缘C#形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆