12345678910111213141516171819202122232425262728293031323334353637 |
- 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(), new System.Drawing.Font("宋体", 8.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))), solidBrush, e.RowBounds.Location.X + 5, 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;
- //}
- }
- }
- }
|