Public Class BorderCell Inherits DataGridViewTextBoxCell Protected Overrides Sub Paint(graphics As Graphics, clipBounds As Rectangle, cellBounds As Rectangle, rowIndex As Integer, cellState As DataGridViewElementStates, value As Object, formattedValue As Object, errorText As String, cellStyle As DataGridViewCellStyle, advancedBorderStyle As DataGridViewAdvancedBorderStyle, paintParts As DataGridViewPaintParts) MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts) 'Ignore if thickness is too small. if _borderThickness = 0 Then Return 'Specify size and position of the border. Dim borderRect = New Rectangle(cellBounds.X + 1, cellBounds.Y + 1, cellBounds.Width - 4, cellBounds.Height - 4) 'Draw border with specified thickness. graphics.DrawRectangle(New Pen(BorderColor, _borderThickness), borderRect) 'Create spacing between text and border. Me.Style.Padding = New Padding(1) End Sub Private _borderThickness As Integer = 1 Property BorderThickness As Integer Set(thickness As Integer) If thickness < 0 Then Throw New Exception($"Border thickness of {Me.GetType().Name} can't be smaller than 0.") _borderThickness = thickness End Set Get Return _borderThickness End Get End Property Public Property BorderColor As Color = Drawing.Color.Black End Class