Firstly i click the start button then, the timer tick then the label will show up the time counted from 0s until the people solve the puzzle then the time will stop!
How am i gonna write the coding i facing problem on that? I had no idea how am i gonna do it?
Well, have you tried yet? It is pretty simple. The Timer class exposes an event called "Tick" which fires on every tick of the timer. So, set the timer duration, hook into the Tick event, start the timer. Now, in the Tick event handler method, update the label.
Yea i already try many times b4 i post but i still cant mange to do that!
I know is simple but its hard when come to the write code part!
Can u gv me some link where can i reference to?
Because i am a beginner in C# i am willing to learn it!
cant run its show error do i need to add something on it?
timer_timer1;
Error 1 'Timer' is a 'namespace' but is used like a 'type'
That would be a problem in your code. Why don't you post it so I can take a look. You should get used to handling errors like this so that you can learn the ins and outs of writing C# applications.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Timer_2
{
public partial class Form1 : Form
{
Timer _timer;
int _tickCount;
public Form1()
{
_tickCount = 0;
_timer = new Timer();
_timer.Interval = 1000; // ~1000 ms (1 second) between ticks
_timer.Tick += timer_Tick;
_timer.Start();
You did not do it like I said. You have some minor errors, and a namespace with a name of "Timer_2" is kind of weird. Here is one problem:
Code:
_timer.Tick += timer_Tick;
You are assigning a delegate method to the Tick event, namely, "timer_Tick". However, there is no such method because you have incorrectly declared the method as:
Code:
timer1_Tick
The signatures do not match. I am not sure where the namespace collision is occurring, but for good measure, change the name of your namespace to something other than "Timer_2". Just right click it and refactor.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace tutorial
{
public partial class Form1 : Form
{
Timer _timer;
int _tickCount;
public Form1()
{
_tickCount = 0;
_timer = new Timer();
_timer.Interval = 1000; // ~1000 ms (1 second) between ticks
_timer.Tick += timer1_Tick;
_timer.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text =(_tickCount++).ToString();
}
Now its show the error at label1.Text =(_tickCount++).ToString();
Error code:Null references exception was unhandled
Object reference not set to an instance of an object.
Bookmarks