I got this timer tick function:
Private Sub controlTick(ByVal sender As Object, ByVal e As EventArgs)
Label2.Text = (Control.ModifierKeys = Keys.Control)
End Sub
That is supposed to make my label say “True” if I am currently holding down the Control key, and “False” if I am not.
But, how come my label is always “False”? What is interesting is that if I press the Control key at lighting speed a bunch of times I can see for a fraction of a second “True”, but immediately turns to “False”.
Timer ticks every 50ms.
I do not understand…. any ideas?
I can’t reproduce the behavior you describe… I tried creating a new WinForms project, placed a Label control on the middle of the form, and added a Timer control.
Whenever I press the Ctrl key, the label reads
True. Otherwise, it readsFalse. Exactly the behavior you would expect to see. I don’t have to press anything at lightning speed.(Edit: It doesn’t break when more controls are placed on the form either. What are you doing differently?)
My code looks like this:
Only difference is that you’re apparently compiling without type checking enabled (Option Strict Off).
I always prefer to code in VB.NET with this turned on (check your project’s Properties window), in which case you have to explicitly convert the boolean type to a string type using
ToString.