本文共 670 字,大约阅读时间需要 2 分钟。
04-通过子线程来让坦克动起来public partial class Form1 : Form
{
int x = 50, y = 50;
public Form1()
{
InitializeComponent();
}
private void ReFlush()
{
while (true)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new InvokeDelegate(InvokeFuntion));
}
else
{
this.Refresh();
}
Thread.Sleep(100);
}
}
public delegate void InvokeDelegate();
private void InvokeFuntion()
{
this.Refresh();
}
private void Form1_Load(object sender, EventArgs e)
{
new Thread(new ThreadStart(ReFlush)) { IsBackground = true }.Start();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush brush = new SolidBrush(Color.Red);
g.FillEllipse(brush, x, y, 30, 30);
x += 5;
}
}
转载地址:http://wftnx.baihongyu.com/