A
A
Alina Primysheva2020-04-03 17:38:39
Windows Forms
Alina Primysheva, 2020-04-03 17:38:39

How to create a countdown timer in C#?

I have a code that displays text with a typewriter effect, I need the user to press the button where the countdown timer appears, but I pre-set the time (for example, 2 hours), to stop the timer, he needs to enter a password if the password matches then a message comes out. Part of the code that I was able to do myself.

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

namespace GoGoBoom_v2
{
public partial class Form1 : Form
{
public Form1()
{
string text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. of Lorem Ipsum.";
int countEntered = 0;
Timer t = new Timer() { Interval = 50 };
t.Tick += (s, _) =>
{
textBox1.Text = text.Substring(0, ++countEntered);

if(countEntered >= text.Length) t.Enabled = false;
};

t.Start();
InitializeComponent();
}




private void buttonYes_Click(object sender, EventArgs e)
{

}
}
}

Help me finish the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tesla2018, 2020-04-04
@Tesla2018

Add a textbox and check the entered text, if it matches the password then turn off the timer or do some other action.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question