如何识别用户第一次或第二次单击按钮 [英] How can i Identify that User has Clicked a Button First Time Or second Time

查看:135
本文介绍了如何识别用户第一次或第二次单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何识别用户第一次或第二次点击按钮



as当他即将点击按钮时,它有文字---选择

和它有的时间--- UN选择

How can i Identify that User has Clicked a Button First Time Or second Time

as When he was about to click button FIRST TIME it has text --- Select
and Secnd Time it has --- UN Select

推荐答案

我想你甚至不需要你可以使用的计数器一个布尔也可以做多种方式:



I think you don''t even need a counter you can use a boolean as well and you can do it numerous ways:

public class MyProg 
{
   private int counter = 0;

   //Button click event
   private void myButton_click(object sender, EventArgs e) {
      counter++;
   }
}





= OR =

考虑你的按钮''文字是0.





=OR=
consider your button''s text is 0.

protected void myButton_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    btn.Text = (Int32.Parse(btn.Text) + 1).ToString();
}





====================== ====编辑==========================

这是一个更简化的代码。您可以将该函数写入MyButtonHandler。



==========================EDIT==========================
Here is a more simplified code for you. You can write that function to the MyButtonHandler.

Button b1 = CreateMyButton();
b1.Click += new EventHandler(this.MyButtonHandler);
...
void MyButtonHandler(object sender, EventArgs e) {
  ...
}




OI



Good luck,
OI


你好,

听起来你需要一个切换功能:



Hi,
Sounds like you need a toggle functions:

private bool _butonSelected = false;
private void button1_Click(object sender, EventArgs e)
{
   ToggleButtonText()
}

private void ToggleButtonText()
{
    if (_butonSelected)
    {
        button.Text = "Select";
        _butonSelected = false;
    }
    else
    {
 
        button.Text = "Un Select";
        _butonSelected = true;
    }
}





问候

Jegan



Regards
Jegan

private void btnWhatever_Click(object sender, EventArgs e)
        {
            if(btnWhatever.Text == "Select")
            {
                btnWhatever.Text = "UN Select";
            }
            else if (btnWhatever.Text == "UN Select")
            {
                btnWhatever.Text = "Select";
            }

            // Your code goes here...
        }


这篇关于如何识别用户第一次或第二次单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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