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:
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!
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.