C#线程动画(闪电)
我想为使用线程的Windows窗体应用程序创建闪电。屏幕应该像闪电(DC漫画超级英雄)身体上的闪电一样运行。到现在为止,我的身体里有线条在画和消失。我为此使用了一个线程,因为我将不得不添加更多的动画与此闪电边C#线程动画(闪电),c#,multithreading,animation,C#,Multithreading,Animation,我想为使用线程的Windows窗体应用程序创建闪电。屏幕应该像闪电(DC漫画超级英雄)身体上的闪电一样运行。到现在为止,我的身体里有线条在画和消失。我为此使用了一个线程,因为我将不得不添加更多的动画与此闪电边 public void Animate() { Point xy1; Point xy2; Random rand=new Random(); for (int ctr = 1; ctr < 110; c
public void Animate()
{
Point xy1;
Point xy2;
Random rand=new Random();
for (int ctr = 1; ctr < 110; ctr++)
{
xy1 = new Point(rand.Next(0, this.Width),rand.Next(0, this.Height));
xy2 = new Point(rand.Next(0, this.Width),rand.Next(0, this.Height));
CreateGraphics().DrawLine(new Pen(Brushes.Yellow, 1),xy1,xy2);
Thread.Sleep(100);
this.Invalidate();
}
}
public void Animate()
{
xy1点;
xy2点;
Random rand=新的Random();
对于(int ctr=1;ctr<110;ctr++)
{
xy1=新点(rand.Next(0,this.Width),rand.Next(0,this.Height));
xy2=新点(rand.Next(0,this.Width),rand.Next(0,this.Height));
CreateGraphics().抽绳(新笔(画笔.黄色,1),xy1,xy2);
睡眠(100);
这个。使无效();
}
}
那么问题是什么?您的代码可能会因为尝试从后台线程绘制而被破坏。或者因为冻结UI线程。