单击一次,然后单击两次 [英] Clicked once do this, Click Twice do that

查看:119
本文介绍了单击一次,然后单击两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,我真的不知道该用几句话来解释这个问题!

我正在寻找一个按钮,它检查自从应用程序加载以来是否已经单击它.

基本上,如果是第一次单击,请让某人在启动应用程序期间再次单击相同的按钮来输入详细信息,我希望程序询问他们是否要在此编辑详细信息,而不是抛出相同的初始输入详细信息页面. br/>
我可以使用一个变量并在循环中对其进行递增,以便如果该变量大于0时执行此操作(如果它为0时),则必须首先访问该部分.这样的事情行得通吗,或者我有完全不同的方式忽略吗?

预先感谢

Sorry about the subject I didn''t really know how to explain this in a few words!

On a button I am looking to check if it has already been clicked since the application has been loaded.

Basically if clicked for the first time make someone enter there details if they click the same button again during the application being started I want the program to ask if they would like to edit there details rather than throwing up the same initial enter details page.

Could I use a variable and increment it in a loop so that if the variable is more than 0 do this if it is 0 then it must be there first visit to this section. Would something like that work or is there a totaly different way I am overlooking?

Thanks in advance

推荐答案

最简单的方法:使用按钮标签"字段,并将其设置为bool值:例如,FirstTime为true.然后在点击事件中:

Easiest way: Use the button Tag field, and set it to a bool value: FirstTime is true for example. Then in the click event:

private void button1_Click(object sender, EventArgs e)
    {
    Button b = sender as Button;
    if (b != null && (bool) b.Tag)
        {
        // It''s the first time.
        b.Tag = false;
        }
    }


一个非常奇特但极为通用的解决方案:请参阅我的文章希望您在这里……只有一次" [ ^ ].

—SA
A very exotic but extremely universal solution: see my article "Wish You Were Here… Only Once"[^].

—SA


嗨DanHodgson88,

您可以创建一个全局布尔变量,并使用Button_Click事件处理程序进行检查:

Hi DanHodgson88,

You can make a Global Boolean variable and using the Button_Click event handler you can check like this :

public static bool EvenClicks = true;

private void button1_Click(object sender, EventArgs e)
{
    EvenClicks = !EvenClicks;
    if (EvenClicks)
    {
        // add the code for clicking twice or for even number of clicks
    }
    else
    {
        // add the code for clicking once or for odd number of clicks
    }
}



希望对您有所帮助,
:)



I hope this help,
:)


这篇关于单击一次,然后单击两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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