C # winform rounded panel

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Windows. forms;
Using system. drawing;
Using system. Drawing. drawing2d;

Namespace roundpanel
{
Class roundpanel: Panel
{
Private int mmatrixround = 8;
Private color mback;

Public color back
{
Get {return mback ;}
Set
{
If (value = NULL)
{
Mback = control. defaultbackcolor;
}
Else
{
Mback = value;
}
Base. Refresh ();
}
}

Public int matrixround
{
Get {return mmatrixround ;}
Set
{
Mmatrixround = value;
Base. Refresh ();
}
}

Private graphicspath createround (rectangle rect, int radius)
{
Graphicspath roundrect = new graphicspath ();
// Top
Roundrect. addline (rect. Left + radius-1, rect. Top-1, rect. Right-radius, rect. Top-1 );
// Upper right corner
Roundrect. addarc (rect. Right-radius, rect. Top-1, radius, radius, 270, 90 );
// Right
Roundrect. addline (rect. Right, rect. Top + radius, rect. Right, rect. Bottom-radius );
// Bottom right corner

Roundrect. addarc (rect. Right-radius, rect. Bottom-radius, 0, 90 );
// Bottom edge
Roundrect. addline (rect. Right-radius, rect. Bottom, rect. Left + radius, rect. Bottom );
// Lower left corner
Roundrect. addarc (rect. Left-1, rect. Bottom-radius, 90, 90 );
// Left
Roundrect. addline (rect. Left-1, rect. Top + radius, rect. Left-1, rect. Bottom-radius );
// Upper left corner
Roundrect. addarc (rect. Left-1, rect. Top-1, radius, radius, 180, 90 );
Return roundrect;
}

Protected override void onpaint (painteventargs E)
{
Int width = base. Width-base. Margin. Left-base. Margin. Right;
Int Height = base. Height-base. Margin. Top-base. Margin. bottom;
Rectangle rec = new rectangle (base. Margin. Left, base. Margin. Top, width, height );
Graphicspath round = createround (REC, mmatrixround );
E. Graphics. smoothingmode = smoothingmode. antialias;
E. Graphics. fillpath (Brush) (new solidbrush (mback), round );
}

Protected override void onresize (eventargs)
{
Base. Refresh ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.