C# 使用DGV单元绘制。在单元格中输入数字,确定。然后我移动到另一个单元格,用不同的数字重复,好的,但第一个数字消失了

C# 使用DGV单元绘制。在单元格中输入数字,确定。然后我移动到另一个单元格,用不同的数字重复,好的,但第一个数字消失了,c#,C#,私有void dataGridView1_CellPainting_1(对象发送方,DataGridViewCellPaintingEventArgs e) { 您是否检查了多个单元格(我的意思是,不仅是正在编辑的单元格,而且同时还有其他单元格)是否触发了事件(仅使用断点计算事件)。我将尝试一下,谢谢。 { string number = txtNumber.Text; if(number != "" &

私有void dataGridView1_CellPainting_1(对象发送方,DataGridViewCellPaintingEventArgs e) {


您是否检查了多个单元格(我的意思是,不仅是正在编辑的单元格,而且同时还有其他单元格)是否触发了事件(仅使用断点计算事件)。我将尝试一下,谢谢。
        {
            string number = txtNumber.Text;
            if(number  != "" && X == e.ColumnIndex && Y == e.RowIndex)
            {
                Rectangle r = new Rectangle(e.CellBounds.X + 2, e.CellBounds.Y + 2, e.CellBounds.Width - 4, e.CellBounds.Height - 4);
                e.Graphics.FillRectangle(Brushes.White, r);
                Font f = new Font(e.CellStyle.Font.FontFamily, 6);
                e.Graphics.DrawString(number, f, Brushes.Black, r);
                e.PaintContent(e.ClipBounds);
                e.Handled = true;
            }

        }
    }