如何启动按钮后,点击一个循环,然后再停止它在同一个按钮点击 [英] How to start a loop upon button click, then stop it upon same button click again

查看:219
本文介绍了如何启动按钮后,点击一个循环,然后再停止它在同一个按钮点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以这是我第二次在这里发帖很抱歉,如果这个问题已经回答了,我不能找到任何东西。

所以基本上我有一个按钮,我想开始一个循环时pressed,我则希望循环不断重复,直到该按钮是pressed再说,我一直在努力的身影这一点了一会儿,我似乎无法得到这个工作。

因此​​在循环中,程序被改变内部几个图片框的图像,我想同样按钮被点击,直到程序继续在一个循环改变的图像

感谢您的帮助:)

如果您需要任何详细信息,只是让我知道

编辑:

 私人无效btnDance_Click(对象发件人,EventArgs的发送)
    {
        布尔点击;
        如果(点击==真)
        {
            timer1.Stop();
        }
        其他
        {
            点击= TRUE;
            timer1.Start();
        }
    }


解决方案

想想事件驱动...把计时器窗体上。在Tick事件做你的工作。然后,只需有按钮切换计时器是否激活...

 私人无效timer1_Tick(对象发件人,EventArgs的发送)
    {
        //此处更改您的形象
    }    私人无效的button1_Click(对象发件人,EventArgs的发送)
    {
        //切换定时器的启用状态
        timer1.Enabled = timer1.Enabled!;
    }

Okay so this is my second time posting here so sorry if this question has already been answered, I couldnt find anything on it.

So basically I have a button, which I want to start a loop when its pressed, I then want the loop to keep repeating until the same button is pressed again, I've been trying to figure this out for a while and I cant seem to get this to work.

So Inside the loop, the program is changing the image inside several picture boxes, I want the program to continue changing the images in a loop until the same button is clicked

Thanks for your help :)

If you need any more information just let me know

EDIT:

    private void btnDance_Click(object sender, EventArgs e)
    {
        bool clicked;
        if (clicked == true)
        {
            timer1.Stop();
        }
        else
        {
            clicked = true;
            timer1.Start();
        }
    }

解决方案

Think event-driven... put a timer on your form. In the tick event do your work. Then just have the button toggle whether the timer is active...

    private void timer1_Tick(object sender, EventArgs e)
    {
        // Change your image here
    }

    private void button1_Click(object sender, EventArgs e)
    {
        // Toggle the timer's enabled state
        timer1.Enabled = !timer1.Enabled;
    }

这篇关于如何启动按钮后,点击一个循环,然后再停止它在同一个按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆