如何通过连续点击按钮更改内容?

时间:2013-09-10 05:32:41

标签: c# windows-phone-7 windows-phone-8 windows-phone

我需要按按钮更改文本框内容。例如,

首次点击按钮时,a应为内容。要再次单击某个按钮,b应为内容。比如T9 Keyboard

我的代码,只显示a没有显示其他字母。

我的代码;

private void buttonFor1(object sender, EventArgs e)
    {
        var count = 0;
        count++;
        if (count == 1)
        {
            messageText.Text = "a";
        }
        else if (count == 2)
        {
            messageText.Text = "b";
        }
        else if (count == 3)
        {
            messageText.Text = "c";
        }
    }

2 个答案:

答案 0 :(得分:0)

在JavaScript中

<html>
<script type="text/javascript">
var count=0;
    function Button_Click()
        {
            count++;            
            var txtBox=document.getElementById('txtAlpha');
            if(count==1)
            {   
                txtBox.value="a";
            }
            else if(count==2)
            {
                txtBox.value="b";
            }
            else if(count==3)
            {
                txtBox.value="c";
            }
        }
</script>
<input type="button" value="click" onclick="Button_Click()"/>
<input type="text" id="txtAlpha"/>
</html>

这是你想要的。如果这是你想要实现的,你可以替换if else子句相应地使用a / b / c的ascii值,

1将转换为a,2将转换为b等。

根据您的要求在C#中:

 static int count=0;// Global Variable declare somewhere at the top 

protected void Button1_Click(object sender, EventArgs e)
        {
            count++;
            if (count == 1)
            {
                TextBox1.Text = "a";
            }
            else if (count==2)
            {
                TextBox1.Text = "b";
            }
            else if (count == 3)
            {
                TextBox1.Text = "c";
            }
        }

希望你明白我的观点!!

干杯!!!

答案 1 :(得分:0)

public void button1_Click(object sender, EventArgs e)
    {
        if (messageText.Text == "")
            messageText.Text = "a";
        else if(messageText.Text == "a")
        {
            messageText.Text = "b";
        }
        else if (messageText.Text == "b")
        {
            messageText.Text = "c";
        }
        else
        {
            messageText.Text = "";
        }
    }