C# 如何在WF中不按日期时间值而更新日期时间值?
在Windows窗体(VS13)中,我添加了一个计时器,但只有在按下时才会更新。如何使其在不按的情况下更新值C# 如何在WF中不按日期时间值而更新日期时间值?,c#,windows-forms-designer,C#,Windows Forms Designer,在Windows窗体(VS13)中,我添加了一个计时器,但只有在按下时才会更新。如何使其在不按的情况下更新值 private void label17_Click(object sender, EventArgs e) { DateTime d = DateTime.Now; this.label17.Text = d.Hour + ":" + d.Minute; } 您可以使用以下代码: private void
private void label17_Click(object sender, EventArgs e)
{
DateTime d = DateTime.Now;
this.label17.Text = d.Hour + ":" + d.Minute;
}
您可以使用以下代码:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
this.label17.Text=(DateTime.Now.Hour.ToString() + ":" +
DateTime.Now.Second.ToString());
}
您可以使用以下代码:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
this.label17.Text=(DateTime.Now.Hour.ToString() + ":" +
DateTime.Now.Second.ToString());
}
您可以使用以下代码:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
this.label17.Text=(DateTime.Now.Hour.ToString() + ":" +
DateTime.Now.Second.ToString());
}
您可以使用以下代码:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
this.label17.Text=(DateTime.Now.Hour.ToString() + ":" +
DateTime.Now.Second.ToString());
}
那不是计时器。您已经将其添加到标签的click事件处理程序中,因此它当然只在您单击它时更新。您需要实现一个
计时器
对象,并更新其tick事件上的标签。这不是计时器。您已经将其添加到标签的click事件处理程序中,因此它当然只在您单击它时更新。您需要实现一个计时器
对象,并更新其tick事件上的标签。这不是计时器。您已经将其添加到标签的click事件处理程序中,因此它当然只在您单击它时更新。您需要实现一个计时器
对象,并更新其tick事件上的标签。这不是计时器。您已经将其添加到标签的click事件处理程序中,因此它当然只在您单击它时更新。您需要实现一个计时器对象,并更新其tick事件上的标签。请注意设置答案的格式-您现在已经有足够的堆栈溢出经验(近100篇文章!)我们不需要像那样修改格式…谢谢下次注意请多注意格式问题-你现在已经有足够的关于堆栈溢出的经验了(近100篇文章!)我们不需要像那样修改格式…谢谢下次注意请多注意格式问题-你现在已经有足够的关于堆栈溢出的经验了(近100篇文章!)我们不需要像那样修改格式…谢谢下次注意请多注意格式问题-你现在已经有足够的经验处理堆栈溢出(近100篇文章!),我们不需要像那样修改格式…谢谢下次注意