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 ();
}
}
}