我有一个TabControl和一个TabPage里面。 BackgroundImage由附加点的线组成。所以我有一些多边形。所有这些点都保存在存储器中。每个点在绘制时都具有时间属性。所以我想使用点之间的延迟重新绘制图片。我有下一个代码TabPage不重画背景图片
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();”
我做错了什么?
我认为你试图使错误的矩形失效或我错号? :)如果您没有StartDot,那么您的StartDots和NewDots坐标将会相同。 – BigL
我使用if(startDot == null) startDot = new Dot(sX,sY,dot.time,dot.force); 继续; } ' –
哦,你是对的,我错过了继续; :)不,矩形也没关系,对不起,我错了。 – BigL