加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-8 – 在Windows 8应用程序中为DispatcherTimer的Tick事

发布时间:2020-12-14 04:11:09 所属栏目:Windows 来源:网络整理
导读:我正在 Windows 8 Visual Studio 11中开发一个应用程序,我想为DispatcherTimer实例定义一个事件处理程序,如下所示: public sealed partial class BlankPage : Page { int timecounter = 10; DispatcherTimer timer = new DispatcherTimer(); public BlankPa
我正在 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#

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读