datagridview 滚动条样式
时间: 2023-08-31 14:10:14 浏览: 156
DataGridView控件的滚动条样式可以通过修改其外观属性来进行自定义。以下是一些可供参考的示例代码:
1. 设置 DataGridView 的滚动条外观为默认样式
```
dataGridView1.ScrollBars = ScrollBars.Both;
```
2. 隐藏 DataGridView 的滚动条
```
dataGridView1.ScrollBars = ScrollBars.None;
```
3. 设置 DataGridView 的滚动条外观为 Office 2007 风格
```
dataGridView1.ScrollBars = ScrollBars.Both;
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(243, 243, 243);
dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black;
dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Segoe UI", 9, FontStyle.Bold);
dataGridView1.RowsDefaultCellStyle.BackColor = Color.White;
dataGridView1.RowsDefaultCellStyle.ForeColor = Color.Black;
dataGridView1.RowsDefaultCellStyle.Font = new Font("Segoe UI", 9);
dataGridView1.BorderStyle = BorderStyle.None;
dataGridView1.BackgroundColor = Color.FromArgb(243, 243, 243);
dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal;
dataGridView1.GridColor = Color.FromArgb(222, 222, 222);
```
4. 设置 DataGridView 的滚动条外观为 Metro 风格
```
dataGridView1.ScrollBars = ScrollBars.Both;
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(0, 174, 219);
dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Segoe UI", 9, FontStyle.Bold);
dataGridView1.RowsDefaultCellStyle.BackColor = Color.FromArgb(240, 240, 240);
dataGridView1.RowsDefaultCellStyle.ForeColor = Color.Black;
dataGridView1.RowsDefaultCellStyle.Font = new Font("Segoe UI", 9);
dataGridView1.BorderStyle = BorderStyle.None;
dataGridView1.BackgroundColor = Color.FromArgb(240, 240, 240);
dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
dataGridView1.GridColor = Color.FromArgb(204, 204, 204);
dataGridView1.RowsDefaultCellStyle.SelectionBackColor = Color.FromArgb(0, 174, 219);
dataGridView1.RowsDefaultCellStyle.SelectionForeColor = Color.White;
```
以上是一些示例代码,你可以根据自己的需求进行修改和调整。
阅读全文