//dgvVisitor 是DataGridView的名称 dgvVisitor.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; //单元格居中显示 private void dgvVisitor_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; }
//设置第3行第3列的单元格内容居中显示 dgvVisitor.Rows[2].Cells[2].Style.Alignment = DataGridViewContentAlignment.MiddleCenter