English 中文(简体)
C#中与四舍五入的边界形成?
原标题:Form with Rounded Borders in C#? [duplicate]

我正在使用这一法典,使表格没有边界风格:

this.FormBorderStyle = FormBorderStyle.None;

我需要在表格上进行四舍五入。

是否容易? 我如何这样做?

问题回答

I know the question was already answered, I would like to add an alternative and silly BUT a not really recommended practice since your question does not restrict the answer into being codes...

  • Create a blank, square image with your background color as fill, then erase the top-left rounded corners to be transparent, repeat this to all corners
  • Set a very unlikely color as your form background color
  • Set this color as the TransparencyKey on your form
  • Add the images as PictureBox and put them to the corresponding corners

Viola!

    public static void RoundBorderForm(Form frm)
    {

        Rectangle Bounds = new Rectangle(0, 0, frm.Width, frm.Height);
        int CornerRadius = 20;
        System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
        path.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90);
        path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90);
        path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
        path.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
        path.CloseAllFigures();

        frm.Region = new Region(path);
        frm.Show();
    }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签