0

I was wondering if there was any way to change the border of a FlatStyle.Flat button (how it paints). I want to change the border of a Flat button to look like it is rounded, like so:

enter image description here

I want button2 to have a similar border to button1, how the pixels in each corner have been removed. I have no idea how to do this or where to begin. If anyone could help me or put me in the right direction, please post here. Thanks!

4

2 回答 2

1

You could try using a GraphicsPath with rounded edges as border for that button. You'd have to draw it yourself though - WinForms doesn't have WPF's Border control.

于 2012-09-15T11:02:25.243 回答
1

Import a dll like:

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()
    { etc.....................

Then in your button's paint event add:

button1.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, button1.Width, button1.Height, 7, 7));

You can change the 'sevens' to the radius you like.

于 2013-02-21T13:51:52.510 回答