如何在点击时增加标签中的一个数字 [英] How to increase one number in label on click

查看:95
本文介绍了如何在点击时增加标签中的一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,伙计们,我想知道如何在点击标签上增加一个数字我在win表单中有一个标签我想点击这个标签,所以这个标签增加1个数字,例如label.text = o;所以当我点击它所以它使1,然后2,然后3很快就可以请帮助我

谢谢



< b>我尝试了什么:



Hello, Guys, I want to know how to increase one number in the label on click I have a label in my win form I want when I click on this label so 1 number increase in this label for example if label.text = o; so when I click it so it make 1, then 2, then 3 soon is it possible please help me about it
Thanks

What I have tried:

for (int i = 0; i =< label1.Text; i++)
            { 
                
            }

推荐答案

作为解决方案1的替代方案,这里有一个解决方案,查看标签的当前内容并增加已经存在的内容(此代码将出现在按钮的Click事件中)

As an alternative to Solution 1, here is a solution that looks at the current contents of the label and increments whatever is already there (This code would be in your button's Click event)
var curr = 0;
if(int.TryParse(label1.Text, out curr))
    curr++;
label1.Text = curr.ToString();


在代码隐藏的根目录中声明一个整数变量...
Have an integer variable declared in the root of the code-behind...
int Count = 0;

然后当你想要更新标签:

then when you want to update the label:

label.Text = ++Count.ToString();


这篇关于如何在点击时增加标签中的一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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