-
Jun 18th, 2018, 10:14 AM
#1
Thread Starter
New Member
Using a variable in Timer name
This is basic I know but I'm stumped
I'm working on an app that has multiple buttons on the screen. The program is used on a touchscreen so I have a timer that flashes each active button. I need to be able to call each buttons timer to turn it off or on depending on if the pause button has been pressed for the program. The pause button would override the individual buttons time in a sense. I'm sure there may be a better way to do the button flashes without having a timer for each but I haven't figure that out.
I have a variable (ButtonSelected) that is an Integer. It gets set when 1 of 24 buttons is pressed. There's only 1 active button at a time. I simply want to call a timer based on what button is active. Something like
TmrBtn(ButtonSelected).enable = False
Any guidance is appreciated.
-
Jun 18th, 2018, 10:23 AM
#2
Re: Using a variable in Timer name
You really ought to consider redesigning this such that there is only one timer. It's possible. In your case, you'd just have to know which button should be flashed, but you DO know that, because you have that ButtonSelected variable. So, the Tick event of the timer can just flash whichever button was selected. If you use multiple timers, they could end up causing you trouble. From your description, I think it is unlikely that you'd end up with that kind of trouble, but order of execution can get confused with multiple timers. I won't say that they'll conflict with each other, but I won't say that they won't, either.
After re-reading your post, it sounds like multiple buttons can be flashed, which is also possible with just one timer, even if you want to flash them at different rates.
Also, in standard WinForms, there likely isn't a better way to flash a button than by using a timer.
My usual boring signature: Nothing
-
Jun 18th, 2018, 10:27 AM
#3
Re: Using a variable in Timer name
Create an array of the timers, eg:
Code:
Private TmrBtn() as Timer = {TmrBtn1, TmrBtn2, ... , TmrBtn24}
...and then you can refer to each of them as you wanted.
Note that using a single timer as suggested above could well be the better option.
-
Jun 18th, 2018, 10:56 AM
#4
Re: Using a variable in Timer name
Another option would be to add the timer to the button. The .Tag property of a button is essentially a storage area that can hold anything...including a timer. So, you could assign each timer to the .Tag property of the button, then get it back with:
Dim yourTimer = DirectCast(yourButtonHere.Tag,Timer)
However, I still prefer having only a single timer.
My usual boring signature: Nothing
-
Jun 18th, 2018, 01:41 PM
#5
Re: Using a variable in Timer name
Originally Posted by Shaggy Hiker
...However, I still prefer having only a single timer.
Great advice!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|