728x90
728x170
private void DataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
var grid = sender as DataGridView;
var rowIdx = (e.RowIndex + 1).ToString();
var centerFormat = new StringFormat()
{
// right alignment might actually make more sense for numbers
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);
}
{
var grid = sender as DataGridView;
var rowIdx = (e.RowIndex + 1).ToString();
var centerFormat = new StringFormat()
{
// right alignment might actually make more sense for numbers
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);
}
위 방법이 제일 깔끔하게 표현이 되는것 같다.
728x90
그리드형
'C# > Winform' 카테고리의 다른 글
[C#)네이버 카페 API 이용하여 사진 포함 글 등록하기 (0) | 2018.09.26 |
---|---|
[C#]TensorCamera (0) | 2018.09.01 |
[링크]ProfessionalCSharp (0) | 2018.07.17 |
git hub(깃헙) username 변경하기 (0) | 2018.07.04 |
DataGridView Drag & Drop Row Move (마우스 드래그로 행 이동하기) (0) | 2018.05.15 |