datagrid设置单元格边框_更改 DataGridView 控件中的边框和网格线样式 - Windows Forms .NET Framework | Microsoft Docs...

如何:更改 Windows 窗体 DataGridView 控件中的边框和网格线的样式How to: Change the Border and Gridline Styles in the Windows Forms DataGridView Control

03/30/2017

本文内容

在 DataGridView 控件中,您可以自定义控件的边框和网格线的外观,以改善用户体验。With the DataGridView control, you can customize the appearance of the control's border and gridlines to improve the user experience. 除了控件中单元格的边框样式外,还可以修改网格线颜色和控件边框样式。You can modify the gridline color and the control border style in addition to the border styles for the cells within the control. 对于普通单元格、行标题单元格和列标题单元,还可以应用不同的单元格边框样式。You can also apply different cell border styles for ordinary cells, row header cells, and column header cells.

备注

The gridline color is used only with the Single, SingleHorizontal, and SingleVertical values of the DataGridViewCellBorderStyle enumeration and the Single value of the DataGridViewHeaderBorderStyle enumeration. 这些枚举的其他值使用操作系统指定的颜色。The other values of these enumerations use colors specified by the operating system. 此外,当通过方法在 Windows XP 和 Windows Server 2003 家族上启用视觉样式时 Application.EnableVisualStyles , GridColor 不使用属性值。Additionally, when visual styles are enabled on Windows XP and the Windows Server 2003 family through the Application.EnableVisualStyles method, the GridColor property value is not used.

以编程方式更改网格线颜色To change the gridline color programmatically

Set the GridColor property.

this.dataGridView1.GridColor = Color.BlueViolet;Me.dataGridView1.GridColor = Color.BlueViolet

以编程方式更改整个 DataGridView 控件的边框样式To change the border style of the entire DataGridView control programmatically

Set the BorderStyle property to one of the BorderStyle enumeration values.

this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;Me.dataGridView1.BorderStyle = BorderStyle.Fixed3D

以编程方式更改 DataGridView 单元格的边框样式To change the border styles for DataGridView cells programmatically

this.dataGridView1.CellBorderStyle =

DataGridViewCellBorderStyle.None;

this.dataGridView1.RowHeadersBorderStyle =

DataGridViewHeaderBorderStyle.Single;

this.dataGridView1.ColumnHeadersBorderStyle =

DataGridViewHeaderBorderStyle.Single;With Me.dataGridView1

.CellBorderStyle = DataGridViewCellBorderStyle.None

.RowHeadersBorderStyle = _

DataGridViewHeaderBorderStyle.Single

.ColumnHeadersBorderStyle = _

DataGridViewHeaderBorderStyle.Single

End With

示例Example

private void SetBorderAndGridlineStyles()

{

this.dataGridView1.GridColor = Color.BlueViolet;

this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;

this.dataGridView1.CellBorderStyle =

DataGridViewCellBorderStyle.None;

this.dataGridView1.RowHeadersBorderStyle =

DataGridViewHeaderBorderStyle.Single;

this.dataGridView1.ColumnHeadersBorderStyle =

DataGridViewHeaderBorderStyle.Single;

}Private Sub SetBorderAndGridlineStyles()

With Me.dataGridView1

.GridColor = Color.BlueViolet

.BorderStyle = BorderStyle.Fixed3D

.CellBorderStyle = DataGridViewCellBorderStyle.None

.RowHeadersBorderStyle = _

DataGridViewHeaderBorderStyle.Single

.ColumnHeadersBorderStyle = _

DataGridViewHeaderBorderStyle.Single

End With

End Sub

编译代码Compiling the Code

此示例需要:This example requires:

另请参阅See also

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值