Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when I click the play button it show = System.FormatException: 'Input string was not in a correct format.'

pls try your best to help me

timer1 is a timer from the toolbox

totaltime is a name of my timer,
and a timer is on a label

What I have tried:

namespace my_first_app_dad
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            timer1.Start();
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            int number = Int32.Parse(totaltime.Text);
            number =+ 1;

        }
    }
}
Posted
Updated 10-Jul-19 22:21pm
v2
Comments
[no name] 10-Jul-19 20:26pm    
Maybe "totaltime.Text" ain't an int.

This happens because totaltime.Text it is not a compliant string representation of an integer. You might either or
 
Share this answer
 
Comments
Maciej Los 12-Jul-19 2:14am    
:thumbsup:
CPallini 13-Jul-19 3:40am    
Thank you, Maciej!
You can try this.

C#
If(Int.tryparse(totaltime.text, out int number))
{
 int num = number + 1;
 totaltime.text = $"{num}";
}


Let me know if it works for you.
 
Share this answer
 
v2

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