Question Windows Forms Timer

RW2539

New member
Joined
Jan 27, 2009
Messages
2
Programming Experience
10+
I used to do a lot of progamming in the dark ages, I know Basic pretty well, and recently began writing in VB.NET. So, I'm far from a novice, but new to this language.

Anyway, I have a prgram in whcih I run a loop until the capslock key is detected to be on. The problem is, the loop blows past the test and I am convinced I am losing keyboard focus somewhere. I read that I might be better off running the loop and creating a timer that checks for the event and, if found, sets a variable to false that will end the loop.

So, I literally clipped the sample code from the help topic in VB 2008 Express and put it in my program and it won't compile. I get this error:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types. I cannot understand from the help system what I need to do.

Alternatively, why would a simple loop cause me to lose the ability to see the keyboard? I don;t change forms, I simply grab a message off a web page and copy it to a textbox. Over and over as the message changes.

I'm all too happy to share the code.

Thx!

RW
 
It sounds like you've copied a Timer.Tick event handler into your code but you don't have a Timer on your form whose Tick event you can handle. Your event handler probably looks something like this:
VB.NET:
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) [B][U]Handles Timer1.Tick[/U][/B]
The error message is saying that if you don't have a variable named Timer1 that is declared WithEvents then you cannot handle its Tick event. If you add a Timer to your form in the designer it will generate code including a declaration like this:
VB.NET:
Private WithEvents Timer1 As System.Windows.Forms.Timer
 
Answer

Thank you. My problem was not letting the designer do the work and, instead, writing my own codefrom scratch. Your fix worked.
RW
 
Back
Top