private void frmPhisical_Load(object sender, EventArgs e)
{
Bitmap bitmap = new Bitmap(100, 100);
Graphics gra = Graphics.FromImage(bitmap);
Brush bru = new SolidBrush(Color.Green);
new Thread(() =>
{
double x = 0;//开始位置
double y = 90;
double addx = 1;//开始速度
double addy = -3;//开始速度
double addx2 = 0;//加速度x
double addy2 = 0.1;//加速度y
while (true)
{
addx += addx2;
addy += addy2;
if (x >= 0 && x <= 90)
{
x += addx;
}
if (y >= 0 && y <= 90)
{
y += addy;
}
//gra.Clear(Color.White);
gra.FillRectangle(bru, (float)x, (float)y, 1, 1);
System.Threading.Thread.Sleep(30);
try
{
this.Invoke(new Action(() =>
{
pbPyhsical.Image = bitmap;
}));
}
catch (Exception)
{
return;
}
}
}).Start();
}