2
I have a Windows Form, on the control bar (where you have the Title, close and minimize) I also have the date and time:
this.hora.Text = DateTime.Now.ToShortTimeString();
this.data.Text = DateTime.Now.ToShortDateString();
But it is not updating alone, I tried to do taking the movement of the mouse and pressed key, but can not call the functions that perform this all the time..
I don’t know, I have no idea how to do it, I had only seen C# in Unity and there was the function ready Update
who played this role (kept updating and executing the commands within it), but how do I do this in Visual?
I’m calling it that:
public Interface()
{
InitializeComponent();
KeyPress += _keyPress;
MouseMove += _mouseMove;
}
public void _mouseMove(object sender, MouseEventArgs e)
{
this.mouseLocation = e.Location;
this.hora.Text = DateTime.Now.ToShortTimeString();
this.data.Text = DateTime.Now.ToShortDateString();
}
public void _keyPress(object sender, KeyPressEventArgs e)
{
this.hora.Text = DateTime.Now.ToShortTimeString();
this.data.Text = DateTime.Now.ToShortDateString();
}
This Form is what? WPF, XAML?
– Leonel Sanches da Silva
Windows Form, . Cs even
– Leonardo
When do you call both lines? At which Form event?
– Leonel Sanches da Silva
I put there in the post.. these functions are to capture pressed key or busy mouse
– Leonardo
They are called there at the beginning when I put them in the operation
– Leonardo
You need to insert a Timer in the form, and at the event tick timer put your code. Set the timer interval property to 1000 (milliseconds). I think the event calls tick, but double-clicking the timer is the event that the visual studio automatically creates.
– RSinohara
The timer serves exactly for this, it calls the event every N milliseconds.
– RSinohara
It worked perfectly, I didn’t know what Timer was doing well, thanks for the explanation, helped me even in another thing I was trying to do! Vlw
– Leonardo
event is nameTimer_Tick itself
– Leonardo