gpt4 book ai didi

windows-8 - 在 Windows 8 应用程序中为 DispatcherTimer 的 Tick 事件定义事件处理程序

转载 作者:行者123 更新时间:2023-12-03 06:56:45 25 4
gpt4 key购买 nike

我正在 Windows 8 Visual studio 11 中开发一个应用程序,我想为 DispatcherTimer 实例定义一个事件处理程序,如下所示:

public sealed partial class BlankPage : Page
{

int timecounter = 10;
DispatcherTimer timer = new DispatcherTimer();
public BlankPage()
{
this.InitializeComponent();
timer.Tick += new EventHandler(HandleTick);
}

private void HandleTick(object s,EventArgs e)
{

timecounter--;
if (timecounter ==0)
{
//disable all buttons here
}
}
.....
}

但我收到以下错误:

Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<object>'

我是 widows 8 应用程序的新手开发人员。

你能帮我一下吗?

最佳答案

差不多了:)你不需要实例化一个新的eventhandler对象,你只需要指向处理事件的方法。因此,需要一个事件处理程序。

        int timecounter = 10;
DispatcherTimer timer = new DispatcherTimer();
public BlankPage()
{
this.InitializeComponent();

timer.Tick += timer_Tick;
}

protected void timer_Tick(object sender, object e)
{
timecounter--;
if (timecounter == 0)
{
//disable all buttons here
}
}

尝试阅读代表以了解事件 Understanding events and event handlers in C#

关于windows-8 - 在 Windows 8 应用程序中为 DispatcherTimer 的 Tick 事件定义事件处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10464374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com