动态对象上的计时器事件 [英] timer events on dynamic objects

查看:87
本文介绍了动态对象上的计时器事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类设置,可以在收到信息时动态创建文本框。



我有处理事件和一切设置,但我想为文本框的每个新实例设置一个私有变量来保存时间值,但是我不知道我在哪里设置它?



我想要什么发生的事情是当计时器在文本框的实例上倒数到0时,前景/背景会改变颜色



有人可以纠正我关于它的概念应该工作吗?



我相信变量 - 让我们称之为分钟,应该放在create textbox类中。当这个类被激活时,它会在其分钟变量中设置时间。



当timer_tick事件运行时,它会从minutes变量中取走1的计数。 />


我知道我不能使用公共共享变量,因为无论何时创建新文本框,它都会重新写入分钟变量。所有实例都将使用相同的变量,这是不正确的。每个单独的文本框都应该有自己的分钟设置。

I've got a class setup that creates textboxes dynamically as information is received.

I've got the handling events and everything set to it, but I want to set a private variable for each new instance of the textboxes to hold a time value, but I'm not sure where I would set it?

What I want to happen is when the timer counts down to 0 on the instance of the textbox, the foreground/background changes colour

Could someone just correct me on the concept of how it should work?

I believe the variable - lets call it minutes, should be placed within the create textbox class. When this class is activated it sets the time within its minutes variable.

When the timer_tick event runs, it takes away a count of 1 from the minutes variable.

I know I can't use a public shared variable, as whenever a new textbox is created, it would then re-write the minutes variable. All instances would use the same variable, which isn't correct. Each separate textbox should have it's own minutes set to it.

推荐答案

是的,你会在文本框上使用tag属性。



在创建窗口标记倒计时时间

在WM_Timer消息上使用标签中的时间

每个文本框的本地时间不同控制的创建时间



关于它在VB中的使用背景的合理文章



http://www.coderslexicon.com/stash-data-away-in -controls-with-the-tag-property / [ ^ ]



如果你想深入了解VB只是将属性附加到窗口句柄和你可以从标准的windows API调用中获取概念



http://msdn.microsoft.com /en-us/library/windows/desktop/ms633561%28v=vs.85%29.aspx [ ^ ]
Yes you would use the tag property on the textbox.

Tag your countdown time to the window on creation
On your WM_Timer message use the time in the tag
Each textbox will have a different time local to creation time of the control

A reasonable article on the background on it's use in VB

http://www.coderslexicon.com/stash-data-away-in-controls-with-the-tag-property/[^]

If you want a deeper understanding VB is simply attaching properties to the window handle and you can pick up the concept from the standard windows API calls

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633561%28v=vs.85%29.aspx[^]


这篇关于动态对象上的计时器事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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