tags:

views:

181

answers:

2

Given this:

Public Sub timReminder_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    If DateTime.Now() > g_RemindTime Then
        Reminders.ShowDialog()
        timReminder.Enabled = False
    End If
End Sub

I want to be able to say this (as I would in Delphi):

timReminder.Tick = timReminder_Tick

But I get errors when I try it.

Does anyone know how I can assign a custom event to a timer's on-tick event at runtime in VB.NET?

+4  A: 

Use the 'AddHandler' and 'AddressOf' keywords to add a handler to the Tick event.

AddHandler timeReminder.Tick, AddressOf timeReminder_Tick
DaveK
A: 

The add handler is a very powerful tool.

Try using it to add an event to a series of controls within a collection.

Th handler can add validation or error checking to all types of controls and will work with whatever you add to the form.

Jon Winstanley