我里面有一个 TabControl 和一个 TabPage。BackgroundImage 由连接点的线组成。所以我有一些多边形。所有这些点都保存在存储中。每个点在绘制时都有时间属性。所以我想使用点之间的延迟重新绘制图片。我有下一个代码
Page pg;
if (storage.book.TryGetValue(currTPage.Name, out pg))
{
currTPage.BackgroundImage = new Bitmap(currTPage.Width, currTPage.Height);
Graphics grap = Graphics.FromImage(currTPage.BackgroundImage);
grap.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
foreach (Sequence seq in pg.pageSeq)
{
Dot startDot = null;
Pen pen = new Pen(Color.FromArgb(seq.r, seq.g, seq.b), 1);
foreach (Dot dot in seq.seq)
{
int sX;
int sY;
if (filter.getPageParameters(currentPattern).orientation == Orientation.Landscape)
{
if (this.currTPage.Width / (double)this.currTPage.Height >= 1.4)
{
sX = (int)(dot.x * this.currTPage.Height / pageHeight) + (currTPage.Width - Convert.ToInt32(this.currTPage.Height * Math.Sqrt(2))) / 2;
sY = (int)(dot.y * this.currTPage.Height / pageHeight);
}
else
{
sX = (int)(dot.x * this.currTPage.Width / pageWidth);
sY = (int)(dot.y * this.currTPage.Width / pageWidth) + (currTPage.Height - Convert.ToInt32(this.currTPage.Width / Math.Sqrt(2))) / 2;
}
}
else
{
if (this.currTPage.Width / (double)this.currTPage.Height <= 1 / 1.4)
{
sX = (int)(dot.x * this.currTPage.Width / pageWidth);
sY = (int)(dot.y * this.currTPage.Width / pageWidth) + (currTPage.Height - Convert.ToInt32(this.currTPage.Width * Math.Sqrt(2))) / 2;
}
else
{
sX = (int)(dot.x * this.currTPage.Height / pageWidth) + (currTPage.Width - Convert.ToInt32(this.currTPage.Height / Math.Sqrt(2))) / 2;
sY = (int)(dot.y * this.currTPage.Height / pageWidth);
}
}
if (startDot == null)
{
startDot = new Dot(sX, sY, dot.time, dot.force);
continue;
}
Dot newDot = new Dot(sX, sY, dot.time, dot.force);
grap.DrawLine(pen, startDot.x, startDot.y, newDot.x, newDot.y);
Thread.Sleep((int)(newDot.time - startDot.time));
currTPage.Invalidate(new Rectangle(Math.Min(startDot.x, newDot.x) - 1, Math.Min(startDot.y, newDot.y) - 1, Math.Abs(startDot.x - newDot.x) + 1, Math.Abs(startDot.y - newDot.y) + 1));
startDot = newDot;
}
}
currTPage.Invalidate();
}
但在重绘开始时,画面甚至没有消失。当我执行“currTPage.Invalidate();”时,它最终会闪烁
我做错了什么?