我用 aDataGridView来显示一些数据。我更改了RowTemplate.DividerHeight属性以使行之间具有良好的可见性。DataGridView但是 Header of和第一行之间的距离是零。我可以将这个距离增加到与值相同的RowTemplate.DividerHeight值吗?编辑:这是我的定义DataGridViewmyGridView.GridColor = Color.Black;myGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;myGridView.Location = new System.Drawing.Point(12, 57);myGridView.Size = new System.Drawing.Size(641 - myGridView.Location.X - 10 - System.Windows.Forms.SystemInformation.VerticalScrollBarWidth, 490);myGridView.Name = "myGridView";myGridView.EnableHeadersVisualStyles = false;myGridView.Font = new System.Drawing.Font("Tahoma", 14);myGridView.ColumnCount = 4;myGridView.Columns[0].HeaderText = "NR REC";myGridView.Columns[0].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight;myGridView.Columns[1].HeaderText = "RECORD NAME";myGridView.Columns[2].HeaderText = "REG. NO";myGridView.Columns[2].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;myGridView.Columns[3].HeaderText = "VIEWER";myGridView.Columns[3].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;myGridView.Columns[0].Width = 60;myGridView.Columns[2].Width = 60;myGridView.Columns[3].Width = 80;myGridView.Columns[1].Width = myGridView.Width - myGridView.Columns[0].Width - myGridView.Columns[2].Width - myGridView.Columns[3].Width;foreach (DataGridViewColumn col in myGridView.Columns) { col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; col.HeaderCell.Style.BackColor = Color.FromArgb(20, 20, 20); col.HeaderCell.Style.SelectionBackColor = Color.FromArgb(20, 20, 20); col.HeaderCell.Style.ForeColor = Color.LightGray; col.DividerWidth = 0; col.SortMode = DataGridViewColumnSortMode.NotSortable; }谢谢。
2 回答
慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
作为一个选项,您可以自己处理CellPainting事件DataGridView并绘制底部边框。例如:
private void DataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1)
{
e.Paint(e.ClipBounds, e.PaintParts);
using (var pen = new Pen(Color.Red, 10))
e.Graphics.DrawLine(pen, e.CellBounds.Left, e.CellBounds.Bottom,
e.CellBounds.Right, e.CellBounds.Bottom);
e.Handled = true;
}
}
明月笑刀无情
TA贡献1828条经验 获得超4个赞
我认为你可以通过添加行代码来改变距离:
dgv.Columns["col1"].HeaderCell.Style.Padding = new Padding(0, 5, 0, 0) dgv.Columns["col2"].HeaderCell.Style.Padding = new Padding(0, 5, 0, 0)
- 2 回答
- 0 关注
- 103 浏览
添加回答
举报
0/150
提交
取消