Граница в DrawRectangle

Если вы хотите, чтобы внешние c-sharp границы прямоугольника были graphics ограничены во всех направлениях, вам c# нужно будет пересчитать его c#.net относительно ширины пера:

private void DrawRectangle(Graphics g, Rectangle rect, float penWidth)
{
    using (Pen pen = new Pen(SystemColors.ControlDark, penWidth))
    {
        float shrinkAmount = pen.Width / 2;
        g.DrawRectangle(
            pen,
            rect.X + shrinkAmount,   // move half a pen-width to the right
            rect.Y + shrinkAmount,   // move half a pen-width to the down
            rect.Width - penWidth,   // shrink width with one pen-width
            rect.Height - penWidth); // shrink height with one pen-width
    }
}

c#

graphics

2022-09-18T18:09:47+00:00