如何使用计时器执行按钮代码 [英] how using timer to execute code for button

查看:70
本文介绍了如何使用计时器执行按钮代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让make timer自动执行按钮写的代码,而不是单击按钮,任何人都可以帮忙吗?

i want make timer to execute code written in button automatically instead of click the button, cauld any one help me ?

推荐答案

有两种方法可以做到这一点:糟糕的想法,但很简单的方法:执行Button.PerformClick方法,这将导致按钮作出反应,就像用户点击它一样。



更好方法是将按钮事件处理程序中的代码提取到方法中,并从两个位置调用它。这样,你可以随意删除按钮,或者在以后用不同的控件替换它,而不会影响定时器代码。
There are two ways to do this: the poor-idea-but-simple way: execute the Button.PerformClick method which will cause the button to react as if the user had clicked it.

The better way is to extract the code from your button event handler into a method, and call that from the two places. That way, you are free to remove the button, or replace it with a different control at a later date without affecting the timer code.


这篇关于如何使用计时器执行按钮代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆