using System.Drawing; using System.Windows.Forms; namespace UAS_LabelMachine.CustomControl { public partial class DataGridViewWithSerialNum : DataGridView { SolidBrush solidBrush; public DataGridViewWithSerialNum() { InitializeComponent(); solidBrush = new SolidBrush(RowHeadersDefaultCellStyle.ForeColor); } protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) { e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, solidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5); base.OnRowPostPaint(e); } private void DataGridViewWithSerialNum_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { //bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position)); //if (e.RowIndex % 2 != 0 || e.ColumnIndex == -1) //{ // solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255)); // e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightGray, e.CellBounds); // Rectangle border = e.CellBounds; // border.Width -= 1; // e.Graphics.DrawRectangle(Pens.White, border); // e.PaintContent(e.CellBounds); // e.Handled = true; //} } } }