VS 2015 [RESOLVED] Is it possible to make a textbox blinking with backColor?

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Is it possible to make a textbox blinking with backColor?

Re: Is it possible to make a textbox blinking with backColor?

As suggested, use a Timer. Basically, any time you want to do something after a specific amount of time, use a Timer. If you only want to do it once, Stop the Timer on the first Tick event, otherwise let it keep running. In your case, you could use an If...Else block to alternate the BackColor, or use an If operator, e.g.

Re: Is it possible to make a textbox blinking with backColor?

I would caution against quite the blink that JMC is showing. I'm known for using some garish colors, but even I wouldn't flash Red/Yellow. Try flashing two shades of the same color, like Red/Pink, or something like that.

Re: Is it possible to make a textbox blinking with backColor?

Originally Posted by Shaggy Hiker

I would caution against quite the blink that JMC is showing. I'm known for using some garish colors, but even I wouldn't flash Red/Yellow. Try flashing two shades of the same color, like Red/Pink, or something like that.

How do you expect to get people's attention if you're not offending their senses?

Re: Is it possible to make a textbox blinking with backColor?

Well, if you want to get the user's attention the ErrorProvider control's a little more idiomatic.

Flashing red/yellow or some other high-contrast colors can be dangerous depending on the rate. There are people with light and color sensitivities and at high cycle rates you could trigger a seizure. Not to mention it's just plain ugly unless you get some feedback from a designer on which colors aren't garish.

Considering that ErrorProvider exists and it's more like what people are used to seeing, that should be used instead.

This answer is wrong. You should be using TableAdapter and Dictionaries instead.

Re: Is it possible to make a textbox blinking with backColor?

Originally Posted by jmcilhinney

How do you expect to get people's attention if you're not offending their senses?

I play dirty noises.

Actually, I did do something like that. I wrote a program that was used in a loud and busy environment. A certain event needed to get everybodies attention right away, but it wasn't an emergency exactly (it dealt with fish, after all). So, the screen itself flashed three times and Homer Simpson's voice said "Hey, what the hell was that?". It worked pretty well. I wanted to use a Monty Python sound clip of "fish!", but it was too short to really work well.

@Sitten: I understood the OP to be just trying to draw the users attention to 'the first control they needed to address.', in which case the error provider doesn't strike me as quite as good. However, I just went and looked at it. It's got more versatility than I realized. As long as you can set the icon, which you can, it does seem like a viable alternative.

Re: Is it possible to make a textbox blinking with backColor?

1) Add a timer to the form with an interval set to whatever blink rate you want. Better make it around 500 to start with, and go from there.
2) Add an integer variable to the form.
3) In the timer tick event, add the code that JMC showed in #3.
4) Also in the tick event, increment the integer variable from step #2.
5) When the integer variable reaches 6, then stop the timer. If you have an interval of 500 ms, then this will count up six intervals, and stop it on the seventh.

Re: Is it possible to make a textbox blinking with backColor?

Got this code but doesn't work.

Code:

Private Sub Timer1_Timer()
Static bDummy As Boolean
Static i As Long
i = i + 1
If i < 100 Then
bDummy = Not bDummy
If bDummy Then
TextBox1.BackColor = Color.Red
Else
TextBox1.BackColor = Color.Yellow
End If
Else
Timer1.Enabled = False
i = 0
End If

Re: Is it possible to make a textbox blinking with backColor?

Step thru your code, you want to start a timer and when the timer ticks you want to toggle the TextBox control's BackColor up to 5 ticks. That would mean that you need to create a condition in your If/Then statement to check if your counter (i) equals 6 and if so then stop the timer. Rather than setting your counter back to 0 when it equals two, continue to increment it and use the MOD operator in place of the current conditional statements:

Code:

i += 1
If i = 6 Then
Timer1.Stop()
ElseIf i MOD 2 = 0 Then
TextBox1.BackColor = Color.GreenYellow
Else
TextBox1.BackColor = Color.Yellow
End If

Edit - Alternatively you could store the toggled color values into an Array and remove the conditional If/Then statement all together:

Re: Is it possible to make a textbox blinking with backColor?

You don't call the timer tick method. That is raised whenever the timer tick interval elapses. All you need to do is start the timer ticking. In your post #12, you enabled the timer in the Load event, which is what starts the flashing. You will need to set i back to 0, which you can do right after you stop the timer in the code that DDay provided. Alternatively, you can do it somewhere else, but that would be the most convenient place. Then, to get the control flashing again, you'd just enable the timer or call the .Start method of the timer.

Enabling the timer from btnGetData would be possible, the way you have it, so all you'd need to do is add:

frmSales.Timer1.Start()

You may want to do that as the very last line of the method, or it might be fine where you have the comment.

Re: Is it possible to make a textbox blinking with backColor?

Not there.

Essentially, you want it right before you start the timer. However, i is a private member of the form, so you can't get to it directly. So, what you will need to do is to add a method to the form, and you might as well have it do all the work. Therefore, on frmSales, you could add something like: