重写DataGridView,添加序号列
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Data;
using System.Windows.Forms;
namespace PrintStock
{
public class DataGridViewEx : DataGridView
{
SolidBrush solidBrush;
public DataGridViewEx()
{
solidBrush = new SolidBrush(System.Drawing.Color.Red);
}
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
{
e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, solidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Y + 5);
base.OnRowPostPaint(e);
}
}
}
重新TextBox,实现回车代替tab键且只能输入数字
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace PrintStock
{
public class NumberTextBox:TextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
if (e.KeyChar == (char)13)
{
SendKeys.Send("{Tab}");
}
if (e.KeyChar != (char)8)
{
Regex reg = new Regex(@"\d");
if (!reg.IsMatch(e.KeyChar.ToString()))
e.Handled = true;
}
}
}
}