Rounded panelCode
Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. diagnostics;
Using System. LINQ;
Using System. text;
Namespace Mycontrollibrary
{
Public Partial Class Roundpanel: system. Windows. Forms. Panel
{
Public Roundpanel ()
{
Initializecomponent ();
This . Padding = New System. Windows. Forms. Padding ( 0 , 0 , 0 , 0 );
This . Margin = New System. Windows. Forms. Padding ( 0 , 0 , 0 , 0 );
This . Backgroundimagelayout = System. Windows. Forms. imagelayout. Stretch;
}
// Rounded corner
// ========================================================== ========================================================== ====================
Private Int _ Radius; // Corner radian
/// <Summary> Rounded corner radians (0 indicates not rounded corner) </Summary>
[Browsable ( True )]
[Description ( " Rounded corner radians (0 indicates not rounded corner) " )]
Public Int _ Setroundradius
{
Get
{
Return _ Radius;
}
Set
{
If (Value < 0 ) {_ Radius = 0 ;}
Else {_ Radius = Value ;}
Base . Refresh ();
}
}
// Rounded corner code
Public Void Round (system. Drawing. region Region)
{
// Bytes -----------------------------------------------------------------------------------------------
// It is already the easiest way to modify the form Attributes provided by. Net (You have to call the API yourself before)
System. Drawing. drawing2d. graphicspath opath = New System. Drawing. drawing2d. graphicspath ();
Int X = 0 ;
Int Y = 0 ;
Int Thiswidth = This . Width;
Int Thisheight = This . Height;
Int Angle = _ Radius;
If (Angle > 0 )
{
System. Drawing. Graphics g = Creategraphics ();
Opath. addarc (X, Y, angle, angle, 180 , 90 ); // Upper left corner
Opath. addarc (thiswidth - Angle, Y, angle, angle, 270 , 90 ); // Upper right corner
Opath. addarc (thiswidth - Angle, thisheight - Angle, 0 , 90 ); // Bottom right corner
Opath. addarc (x, thisheight - Angle, 90 , 90 ); // Lower left corner
Opath. closeallfigures ();
Region = New System. Drawing. region (opath );
}
// Bytes -----------------------------------------------------------------------------------------------
Else
{
Opath. addline (x + Angle, Y, thiswidth - Angle, y ); // Top
Opath. addline (thiswidth, y + Angle, thiswidth, thisheight - Angle ); // Right side
Opath. addline (thiswidth - Angle, thisheight, X + Angle, thisheight ); // Bottom edge
Opath. addline (X, Y + Angle, X, thisheight - Angle ); // Left
Opath. closeallfigures ();
Region = New System. Drawing. region (opath );
}
}
// ========================================================== ========================================================== ====================
Public Roundpanel (icontainer container)
{
Container. Add ( This );
Initializecomponent ();
}
Protected Override Void Onpaint (system. Windows. Forms. painteventargs PE)
{
Base . Onpaint (PE );
Round ( This . Region ); // Rounded corner
}
Protected Override Void Onresize (eventargs)
{
Base . Onresize (eventargs );
Base . Refresh ();
}
}
}