Philip Lee Philip Lee - 10 months ago 49 Question

VB.Net Code in class and WithEvents issue

I've created a VB.Net application which consists of a form and a series of classes. One class (GUI) contains all of the routines that handle the logic associated with the controls on my form. These controls are placed at design time.

I've having a problem with a couple of the timers on the form. They are declared in the GUI class thus:

Private WithEvents timerScreenUpdate As Timer
Private WithEvents timerDebug As Timer

but I'm getting an error in this line:

Private Sub timerScreenUpdate_Tick(sender As System.Object, e As System.EventArgs) Handles timerScreenUpdate.Tick

The error is "Event 'Tick' cannot be found". I'm getting the same error for the other timer.

It's probably related but I'm also getting a similar error in this line:

Private Sub Monitor_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing

which is "Event 'FormClosing' cannot be found".

How can I make these events visible to my class ?

Answer Source

Make sure that the reference and the Namespace-Import of System.Windows.Forms is available in your project respectively class file.

Without it, VB will use a Timer from the namespace System.Timers which you don't want to use in your case.