F
F
fjaerj122021-10-17 23:40:31
C++ / C#
fjaerj12, 2021-10-17 23:40:31

Why is the form not displaying text?

Why is the text not displayed in the window on the right every time.
616c890bef14e549830690.png
This is what happens when you run the program and press the "Start" button, the timer should also show more than 0 seconds.
616c89d1b6287075001679.png
Here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Task4
{
    public partial class Task4 : Form
    {
        Random rand = new Random();
        int seconds = 0;
        string alphabet = "abcdefghijklmnopqrstuvwxyz";
        int countMistakes = 0, countMissLetters = 0, count10 = 0, countCorrect = 0;
        char letter;
        bool less11 = true, inputIncorrect = true;

        public Task4()
        {
            InitializeComponent();
            EasyRadioButton.Checked = true;
        }

        private void startButton_Click(object sender, EventArgs e)
        {            
            if (EasyRadioButton.Checked)
            {
                timerGeneral.Enabled = true;
                timeLabel.Text = seconds.ToString();

                for (int i = 0; i < 10; i++) //  проблема в этом цикле
                {
                    letter = alphabet[rand.Next(0, 26)];
                    symbolsTextBox.Text = $"{letter}";

                    DateTime start = DateTime.Now;
                    DateTime finish = DateTime.Now;
                    TimeSpan difference = finish - start;
                    while ((difference.TotalMilliseconds < 1000) && (inputIncorrect))
                    {
                        finish = DateTime.Now;
                        difference = finish - start;
                    }

                    if (inputIncorrect == true) countMissLetters++;
                    inputIncorrect = true;
                }
                
                timerGeneral.Enabled = false;

                MessageBox.Show($"{timeLabel.Text} {countMissLetters} {countMistakes}");
            }
        }

        private void Task4_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != letter) countMistakes++;
            else inputIncorrect = false;
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            seconds++;
            timeLabel.Text = seconds.ToString();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Lenchenkov, 2021-10-18
@iversooon

the timer does not go, because your timer_Tick method is written, but it is not called anywhere, but even so you will only have seconds, and there will be no minutes, something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question