Click here to Skip to main content
14,735,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
i want to increase the value to different label by input a number in textbox with a button.
like this:

(type in 1)
[Imgur] (https://i.imgur.com/ul4Syqj.png)[^]
(1st button click)
Imgur: The magic of the Internet[^]
(2nd button click)
Imgur: The magic of the Internet[^]
(3rd button click)
Imgur: The magic of the Internet[^]
...and continue to cycle between label 1 and label 2
(I type in the number by hand)

If someone can help me then please,pretty please,I'll be very grateful.

What I have tried:

I've tried all of the solve on the internet,but none of them fits my description.
Posted
Updated 14-Jun-20 23:21pm
Comments
jimmson 15-Jun-20 4:19am
   
Can you show us the code you have so far?

1 solution

There are a couple of ways:
1) Read the Label.Text value, and use int.TryParse to convert it to a number:
int x;
if (!int.TryParse(myLabel.Text, out x))
   {
   ... report problem to user - it's not a number ...
   return;

Or
2) Use the Label.Tag property to contain the actual value:
int x = (int) myLabel.Tag;


Either way, use int.TryParse (as shown above) to convert teh textbox value to an incrementer, and add it in:
int result = x + inc;

You can then set your labels with appropriate values (not forgetting to update the Tag if you are using them).
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900