I have found problems with the exact approach that Matthew suggested. His original code has the background extending out a little beyond the right and bottom.
g.PenSize = BorderWidth
//Background
g.DrawingColor = BackgroundColor
g.FillRectangle(0,0,g.Width,g.Height)
//Borders
g.DrawingColor = BorderTopColor
g.DrawLine(0,0,g.Width -(1+ BorderWidth),0)
g.DrawingColor = BorderLeft
g.DrawLine(0,0,0, (g.Height - (1 + BorderWidth)))
g.DrawingColor = BorderBottom
g.DrawLine(1,g.Height - (1 + BorderWidth),g.Width - (1 + BorderWidth),g.Height - (1 + BorderWidth))
g.DrawingColor = BorderRight
g.DrawLine(g.Width - (1 + BorderWidth),1,g.Width - (1 + BorderWidth),g.Height - (1 + BorderWidth))
g.DrawingColor = BorderLeft
g.FillRectangle(0, BorderWidth, BorderWidth, g.Height)
g.DrawingColor = BorderBottom
g.FillRectangle(BorderWidth, g.Height - BorderWidth, g.Width, g.Height - 1)
g.DrawingColor = BorderRight
g.FillRectangle(g.Width - BorderWidth, 0, g.Width - 1, g.Height - BorderWidth)
End
As an alternative, I have used FillRectangle as my basic tool to create the border. The corners are treated differently. There are various ways to treat the corners that can be obtained by tweaking the code.
If BorderWidth > 0 Then
g.DrawingColor = BorderTopColor
g.FillRectangle(0, 0, g.Width, BorderWidth)
g.DrawingColor = BorderLeft
g.FillRectangle(0, BorderWidth, BorderWidth, g.Height)
g.DrawingColor = BorderBottom
g.FillRectangle(BorderWidth, g.Height - BorderWidth, g.Width, g.Height - 1)
g.DrawingColor = BorderRight
g.FillRectangle(g.Width - BorderWidth, 0, g.Width - 1, g.Height - BorderWidth)
End