GraphicPath: Draw a customizable vertical rounded edge rectangle

Kumar, Thrainder (MIND) 176 Reputation points
2021-04-15T19:11:14.887+00:00

Hi,

I am new to C# in designing some dynamic shapes. Finally, I completed a rounded corner rectangle which is Horizontal.

88287-vertical.jpg

Now, I want to draw a similar but Vertical rectangle.

88343-vertical.jpg

I have tried some manual values and it kinda looks similar but it is not customizable (resizable - increment, decrement, stretched, stressed) like my already completed horizontal one.

My Horizontal shape

protected override void OnPaint(PaintEventArgs e)  
        {  
            this.OnPaintBackground(e);  
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;  
            using (var path = new GraphicsPath())  
            {  
                var d = Padding.All;  
                var r = this.Height - 2 * d;  
                path.AddArc(d, d, r, r, 90, 180);  
                path.AddArc(this.Width - r - d, d, r, r, -90, 180);  
                path.CloseFigure();  
                e.Graphics.FillPath(Checked ? Brushes.DarkGray : Brushes.LightGray, path);  
            }  
        }  
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,364 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,229 questions
0 comments No comments
{count} votes

Accepted answer
  1. Kumar, Thrainder (MIND) 176 Reputation points
    2021-04-16T21:11:49.337+00:00

    Here I Finally made this.

    protected override void OnPaint(PaintEventArgs e)
            {
                this.OnPaintBackground(e);
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                using (var path = new GraphicsPath())
                {
                    var d = Padding.All;
                    var r = this.Width - 2 * d;
                    var h = this.Height - r - d;
                    //(||<, V -, >=, V_, z, z)
    
                    path.AddArc(1, d, this.Width - d*2 + 1, r, -360, -180);
                    path.AddArc(1, h, this.Width - d*2 + 1, r, 180, -180);
                    path.CloseFigure();
    
                    e.Graphics.FillPath(Checked ? Brushes.DarkGray : Brushes.DarkGray, path);
                    r = Width - 1;
                    var rect = Checked ? new Rectangle(0, Height - r - 1, r, r)
                                       : new Rectangle(0, 0, r, r);
                    e.Graphics.FillEllipse(Checked ? Brushes.LightSeaGreen : Brushes.LightSeaGreen, rect);
                    //var rect2 = Checked ? new Rectangle(0, 0, r, r)
                    //                   : new Rectangle(0, Height - r - 1, r, r);
                    //e.Graphics.FillEllipse(Checked ? Brushes.WhiteSmoke : Brushes.WhiteSmoke, rect2);
    
                }
            }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful