Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am designing Winforms.....I need curved edges at four corners of groupbox using c#.net...pls give some idea ji..

What I have tried:

I need curved edges at four corners of groupbox using c#.net
Posted
Updated 7-Feb-21 0:49am

You don't have any direct control over how a Groupbox is displayed - there is no "curved edges" option to the delimiting lines.

You have two options: create your own custom control that emulates a Groupbox but with rounded corners, or handle the Paint event and draw them yourself (this may require a derived control: rounded corners will encroach on the space the control uses for it's contained controls, so you may well have to modify quite a few things to get it to work).

This may help: Reference Source[^] - but don't expect this to be a trivial change!
 
Share this answer
 
v2
 
Share this answer
 
Comments
Member 15028582 9-Feb-21 6:14am    
Actually I went to above Site you mentioned ji...It shows 404 error found..
Member 15028582 9-Feb-21 6:18am    
class CustomGrpBox: GroupBox
{
public CustomGrpBox()
{
this.DoubleBuffered = true;
this.BackColor = Color.Transparent;
this.Radious = 25;
this.TitleHatchStyle = HatchStyle.Percent60;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
GroupBoxRenderer.DrawParentBackground(e.Graphics, this.ClientRectangle, this);
var rect = ClientRectangle;
using (var path = GetRoundRectagle(this.ClientRectangle, Radious))
{

if (this.BackColor != Color.Transparent)
using (var brush = new SolidBrush(BackColor))
e.Graphics.FillPath(brush, path);
using (var brush = new HatchBrush(TitleHatchStyle,
TitleBackColor, ControlPaint.Light(TitleBackColor)))
e.Graphics.FillPath(brush, path);

}
}
public Color TitleBackColor { get; set; }
public HatchStyle TitleHatchStyle { get; set; }
public int Radious { get; set; }
private GraphicsPath GetRoundRectagle(Rectangle b, int r)
{
GraphicsPath path = new GraphicsPath();
path.AddArc(b.X, b.Y, r, r, 180, 90);
path.AddArc(b.X + b.Width - r - 1, b.Y, r, r, 270, 90);
path.AddArc(b.X + b.Width - r - 1, b.Y + b.Height - r - 1, r, r, 0, 90);
path.AddArc(b.X, b.Y + b.Height - r - 1, r, r, 90, 90);
path.CloseAllFigures();
return path;
}
}
Member 15028582 9-Feb-21 6:19am    
This is my code...Actually I got curved edges but inside the groupbox I need blank space it shows some cross marks fully how to resolve it....Pls give some idea ji

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900