Home > OS >  Drawing a filled rectangle in C# .NET Core
Drawing a filled rectangle in C# .NET Core

Time:06-18

I want to make a rectangle with a custom filled colour (background colour) and a line

private void FooMethod(Graphics graph)
{
   // Draw a simple rectangle in C#, not filled.
   Rectangle rect = new Rectangle(0, 0, 100, 45);
   graph.DrawRectangle(Pens.Black, rect);
   
   // "Make"? a filled rectangle (it doesn't work)
   graph.FillRectangle(Brushes.White); // I don't know how to proceed to draw a filled rectangle.
}

But It doesn't work and I tried scr1

    void FooMethod(Graphics graph)
    {
        using(GraphicsPath path = new GraphicsPath())
        {
            Rectangle rectangle = new Rectangle(5, 5, 100, 45);
            path.AddRectangle(rectangle);
            rectangle.Inflate(-5, -5);
            path.AddEllipse(rectangle);
            graph.FillPath(Brushes.White, path);
            graph.DrawPath(Pens.Black, path);
        }
    }
  • Related