处理时禁用图片框点击 [英] Disable picturebox clicking while processing

查看:105
本文介绍了处理时禁用图片框点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,当单击一个图片框,然后暂停三个秒数并返回结果时,该表单将进行处理.但是在此过程中,您可以单击图片框,并且单击次数会堆积起来,从而导致它在3秒钟后再次单击.如何在此过程中禁用点击?

I have a form that will do a process when a picture box is clicked and then pause three secodnds and return the result. But during this process you can click the picture box and the clicks stack up, thus resulting in it clicking again after 3 seconds. How can I disable the click during the process?

private void DiceBox_Click(object sender, EventArgs e)
        {
            if (doClick)
            {
                return;
            }
            else
            {
                doClick = true;
            }
                int DiceRoll = Dice.DiceRoll(ref DiceBox, ref sound);
                Output.Text = "You rolled: " + DiceRoll + " \r\n";
                //Loads all actions for this session
                Game.LoadActions(Currtable, DiceRoll);
                //Executes Actions.
                Currtable = Game.GoToNextTable();

                Output.Text += TextFetch.ReturnActionText(Currtable, DiceRoll);
                this.Refresh();
                Thread.Sleep(3000);
                //see if checkpoint changes
                if (CheckPoint.Text != Game.GetCheckPoint().ToString())
                {

                    CheckPoint.Text = Game.GetCheckPoint().ToString();

                    //checkpoint sound
                    sound.test(int.Parse(CheckPoint.Text));
                    //map position
                    int maplocationx = map.mapPositionx(int.Parse(CheckPoint.Text));
                    int maplocationy = map.mapPositiony(int.Parse(CheckPoint.Text));
                    MapDot.Location = new Point(maplocationx, maplocationy);

                    CheckPoint.Text += " " + TextFetch.ReturnCheckpointText(int.Parse(CheckPoint.Text));

                }
                doClick = false;
        }



我已经在此方法的开头尝试向我们提供以下代码,然后在末尾使用+ =而不是-=,但是我得到的效果与上述代码相同,点击仍然堆积起来,等待三秒钟. br/>



I have tried to us the following code at the beginning of this method and then using += instead of -= at the end but i get the same result as with the above code, the clicks still stack up and wait the thre seconds.

DiceBox.Click -= new System.EventHandler(DiceBox_Click);




and

DiceBox.Click += new System.EventHandler(DiceBox_Click);


如何解决此问题?


How can i fix this issue?

Thanks

推荐答案

不要让您的生活变得比原来更辛苦,请不要使用-=".相反,添加对您可以作为声明类(Form类,Window类,无论如何)的成员引入的一些布尔标志的检查;假设您命名AllowDiceBoxClick.

在您的Click处理程序的最开始添加支票:
Don''t make your life harder than it can be, don''t use "-=". Instead, add a check of some Boolean flag you can introduce as a member of the declaring class (a Form class, a Window class, whatever); let''s say, you name AllowDiceBoxClick.

Add the check in the very beginning of you Click handler:
if (!AllowDiceBoxClick) return;

完成!

以防万一:



查看设计以查看是否确实需要PictireBox.对于您来说,这很可能很好,但是如果您需要更复杂的处理,请考虑我过去的回答:

and you are done!

Just in case:



Review your design to see if you really need PictireBox. Most likely, in your case this is fine, but if you need a bit more complex processing, take into account my past answer: How do I clear a panel from old drawing[^].

—SA


这篇关于处理时禁用图片框点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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