Click here to Skip to main content
14,603,916 members
Rate this:
Please Sign up or sign in to vote.
See more:
Let Say i have a form with label named(Number) then a textbox and Button(Save)

How to Increment a number in a textbox by 1?

I mean if i click the button save the number "1" in the textbox it will increment by 1 then if i don't save it and close the program the last number i left will be still remain (if it is not used for saving like what i have said earlier.)

Can someone give me a sample code for this in Than You
What's the problem? so far?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You need to parse the text to some integer type. For example:
int value;
if (int.TryParse(myTextBox.Text, out value))
   myTextBox.Text.Text = (++value).ToString();
   // do something when the text cannot be parsed as integer


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100