.NET
Microsoft Technologies based on the .NET software framework.
3,398 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I am new to C# in designing some dynamic shapes. Finally, I completed a rounded corner rectangle which is Horizontal.
Now, I want to draw a similar but Vertical rectangle.
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);
}
}
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);
}
}