Rellenar octágono en C #
He creado un método que dibuja un octágono, y funciona bien, siempre que el tamaño sea 200 o superior.
public static void FillOctagon(PaintEventArgs e, Color color, int x, int y, int width, int height)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
var points = new []
{
new Point(((x + width) / 2) - (width / 4), y), //side 1
new Point(x, ((y + height) / 2) - (height / 4)), //side 2
new Point(x, ((y + height) / 2) + (height / 4)), //side 3
new Point(((x + width) / 2) - (width / 4), y + height), //side 4
new Point((x + width) - (width / 4), y + height), //side 5
new Point(x + width, ((y + height) / 2) + (height / 4)), //side 6
new Point(x + width, ((y + height) / 2) - (height / 4)), //side 7
new Point((x + width) - (width / 4), y) //side 8
};
using (var br = new SolidBrush(color))
{
using (var gpath = new GraphicsPath())
{
gpath.AddPolygon(points);
e.Graphics.FillPath(br, gpath);
}
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
FillOctagon(e, Color.DodgerBlue, 20, 20, 50, 50);
}
Bueno, mi problema es que si el tamaño es inferior a 200 o si el ancho es diferente de la altura y viceversa, la figura se deforma. Mi objetivo es crear una figura autoadaptable, que conserve su forma cuando el ancho y la altura sean inferiores a 200 o que el ancho sea diferente de la altura
Esto es lo que sucede si, por ejemplo, configuro el tamaño en 50x50: