DataGridViewWithSerialNum.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. namespace UAS_LabelMachine.CustomControl
  4. {
  5. public partial class DataGridViewWithSerialNum : DataGridView
  6. {
  7. SolidBrush solidBrush;
  8. public DataGridViewWithSerialNum()
  9. {
  10. InitializeComponent();
  11. solidBrush = new SolidBrush(RowHeadersDefaultCellStyle.ForeColor);
  12. }
  13. protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
  14. {
  15. e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, solidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
  16. base.OnRowPostPaint(e);
  17. }
  18. private void DataGridViewWithSerialNum_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  19. {
  20. //bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  21. //if (e.RowIndex % 2 != 0 || e.ColumnIndex == -1)
  22. //{
  23. // solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  24. // e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightGray, e.CellBounds);
  25. // Rectangle border = e.CellBounds;
  26. // border.Width -= 1;
  27. // e.Graphics.DrawRectangle(Pens.White, border);
  28. // e.PaintContent(e.CellBounds);
  29. // e.Handled = true;
  30. //}
  31. }
  32. }
  33. }