我有一个 DataGridView,其中第一列可以保存动画 gif(动画加载圈)。为了使动画部分工作,我使用了每 100 毫秒滴答一次的 Forms.Timer 并调用此方法
private void timGifAnimation_Tick(object sender, EventArgs e)
{
if(this.dataGridView1.Rows.Count > 0 && current >= 0 && current < this.dataGridView1.Rows.Count)
{
this.dataGridView1.Rows[current].Cells[0].Value = this.picProcessing.Image;
this.dataGridView1.InvalidateCell(0, current);
}
}
在我将 DataGridView 放入 SplitContainer 之前,这很有效。不再通过调用 InvalidateCell 重新绘制单元格,gif 动画唯一起作用的时间是现在调整窗口大小或将鼠标悬停在按钮上时(悬停重新绘制一次,将鼠标从按钮上移开重新绘制再次)。调试时,上面的方法仍然被调用,它根本不重绘单元格。