在游戏中,使人物攻击需要不停地点击攻击键,但是开了连发程序后,只需要按住攻击键不放,就可以连续攻击,也就是说连发程序等于帮你不停地安你需要按的按键
引用命名空间using System.Threading下面是窗体的二个事件,和鼠标按住时的方法,很简单
bool isMoseDown = true
private void Test()
{
int i = 0
while (isMoseDown)
{
this.BeginInvoke(new MethodInvoker(delegate
{
textBox1.Text = (i++).ToString()
}))
Thread.Sleep(200)
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMoseDown = true
Thread td = new Thread(new ThreadStart(Test))
td.IsBackground = true
td.Start()
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
isMoseDown = false
}
或者:
bool isMoseDown = true
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMoseDown = true
int i = 0
while (isMoseDown)
{
textBox1.Text = (i++).ToString()
Application.DoEvents()
Thread.Sleep(200)
}
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
isMoseDown = false
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)