)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 19, 2019
Tags: styling

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon