Articles in this section
Category / Section

What is the difference between BorderMargins and TextMargins in WinForms GridControl?

2 mins read

Difference between text and border margins

TextMargins

This specifies the space that should be left for margins to the left or right or top or bottom. That is, the area between the text rectangle and the client rectangle of the cell without borders.

C#

// Apply Header text for col 1
this.gridControl1[0, 1].Text = "TextMargins";
// setting the text margins for cells
this.gridControl1.Model.ColStyles[1].TextMargins.Left = 10;
this.gridControl1.Model.ColStyles[1].TextMargins.Top = 10;
this.gridControl1.Model.ColStyles[1].TextMargins.Right = 10;
this.gridControl1.Model.ColStyles[1].TextMargins.Bottom = 10;
// set cell text
this.gridControl1.Model.ColStyles[1].Text = "Text Magin is applied from the cell's rectangle";
// apply color for the inner text box.
this.gridControl1.Model.ColStyles[1].Interior = new BrushInfo(60, new BrushInfo(Color.SkyBlue));

VB

' Apply Header text for col 1
Me.gridControl1(0, 1).Text = "TextMargins"
' setting the text margins for cells
Me.gridControl1.Model.ColStyles(1).TextMargins.Left = 10
Me.gridControl1.Model.ColStyles(1).TextMargins.Top = 10
Me.gridControl1.Model.ColStyles(1).TextMargins.Right = 10
Me.gridControl1.Model.ColStyles(1).TextMargins.Bottom = 10
' set cell text
Me.gridControl1.Model.ColStyles(1).Text = "Text Magin is applied from the cell's rectangle"
' apply color for the inner text box.
Me.gridControl1.Model.ColStyles(1).Interior = New BrushInfo(60, New BrushInfo(Color.SkyBlue))

The following screenshot illustrates the Grid control with Text Margin.

Text margin in GridControl

Figure 1: Text margin in grid Control

BorderMargins

This property is used to reserve more space for the borders in cases like drawing custom borders. This specifies the area between the cell rectangle and the inner rectangle of the cell.

You can refer to the CustomBorders sample in the Grid.Windows\Samples\In Depth\CustomBorders folder that is shipped with the product to get more information about the custom borders.

C#

// Set the Border Margin for the cells
this.gridControl1.Model.ColStyles[2].BorderMargins.Left = 10;
this.gridControl1.Model.ColStyles[2].BorderMargins.Top = 10;
this.gridControl1.Model.ColStyles[2].BorderMargins.Right = 10;
this.gridControl1.Model.ColStyles[2].BorderMargins.Bottom = 10;
// set the cell text.
this.gridControl1.Model.ColStyles[2].Text = "Border Margins";
// apply the color for the inner text box of the grid cell
this.gridControl1.Model.ColStyles[2].Interior = new BrushInfo(60, new BrushInfo(Color.Pink));

VB

' Set the Border Margin for the cells
Me.gridControl1.Model.ColStyles(2).BorderMargins.Left = 10 
Me.gridControl1.Model.ColStyles(2).BorderMargins.Top = 10
Me.gridControl1.Model.ColStyles(2).BorderMargins.Right = 10
Me.gridControl1.Model.ColStyles(2).BorderMargins.Bottom = 10
' set the cell text.
Me.gridControl1.Model.ColStyles(2).Text = "Border Margins"
' apply the color for the inner text box of the grid cell
Me.gridControl1.Model.ColStyles(2).Interior = New BrushInfo(60, New BrushInfo(Color.Pink))

The following screenshot illustrates the Grid control with Border Margin.

Border margin in GridControl

Figure 2: Border Margin in Grid Control

Samples:

C#: TextAndBorderMargin-CS.zip

VB: TextAndBorderMargin-VB.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied