using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
namespace SomeCompanyName
{
public static class Gfx
{
/// <summary>
/// Draws a border around a rectangle maximising the width of the pen
/// to make the border as large as the pen width.
/// </summary>
/// <remarks>
/// The reason we faff around with drawing the border at an offset to the pen width
/// is to ensure the border is infact drawn at the size of the pen.
/// If you have a Pen width of 6 and you just perform DrawRectangle on the ClientRectangle
/// you'll actually get a border of 3 as the width of the pen is from the central point
/// it draws (so the other 3 is drawn OFF screen).
///
/// The reason we minus one from the end of the width and height is due to CE
/// performing DrawRectangle as rect inclusive (counting zero as 1).
/// See: http://blogs.msdn.com/oldnewthing/archive/2004/02/18/75652.aspx for further information.
/// </remarks>
/// <param name="graphics"></param>
/// <param name="rect"></param>
/// <param name="pen"></param>
public static void PaintBorderAroundRectangle(Graphics graphics, Rectangle rect, Pen pen)
{
int offSet = (int)Math.Round(pen.Width / 2);
// outline
graphics.DrawRectangle(pen, new Rectangle(
rect.X + offSet,
rect.Y + offSet,
rect.Width - (offSet * 2) - 1,
rect.Height - (offSet * 2) - 1));
}
}
}