Making a Custom Event Handler?

Hello all. I promise I have been through all PDF’s in the User guide along with many Google searches and I am not clear on how to create a custom Event Handler. I am on a quest to make my public classes very easy to use by others and if I had the ability to create a custom Event Handler I could pass method results to it.

Am I on the right track?

Thank you!

Choose the “+” button on the toolbar and select “Event Definition”.

Covered in User Guide Book 1: Fundamentals, Chapter 5: Classes, Section 3: Properties, Methods and Events.

Thank Paul. Yes I have been through that and I can create it, but it won’t let me type anything in the definition after I define it. I figured I wasn’t in the right spot. I am just not clear on how to use it after reading.

I am re-reading again :slight_smile:

Oh!! I was adding the Event Definitions after I created the Subclass!!! Oops that is why it never showed up properly!!! :slight_smile:

Phew got it now. Thanks Paul

That’s not a problem. You don’t put your code in the event definition itself. Once you add an instance of your class to a window, you need to create a new event. Your new event definition will be one of the possibilities shown. Put your code in that event, then call your event with raiseEvent myNewEvent

Thanks Roger!


  • I have a CustomCanvas class on the left of the IDE
  • I click right on it, select Add - Event definition
  • I name the event “myevent”
  • I drag CustomCanvas to my window
  • I go Insert / Event handler, and add myevent
  • I open myevent and add code (beep)

Now, how do I call myevent ? I tried to put RaiseEvent myevent in MouseEnter, I get “This item does not exist”, myevent is yellowed… Autocomplete did offer myevent though…

I could simply call a method and call it a night, but I want to understand.

Any step by step help will be welcome. Thank you in advance.

In your base class you use the RaiseEvent syntax and in your instance you add the event method and place your code there.

RaiseEvent calls the event in the instance, not in the base class itself.

Generally you create an event definition in your class to allow the instance to do something or react to something.

I use canvas a lot for creating custom buttons. I have an event definition called Click. In my MouseUp event in my base class I RaiseEvent Click. In my instance I add the Click event and add the code that I want to execute when the user clicks the button.

RaiseEvent goes into the CustomCanvas class itself, not in the instance on the window. Go back to the CustomCanvas class on the left of the IDE. Right click it and select Add - Event Handler. Choose MouseDown. Put RaiseEvent in that event handler. It will now trigger myEvent in the instance on your window.

The event can only be called by the class. The event can only be implemented by an instance of the class.

Allright. Now I understand better. Thank you.

Ok, I got it now. I know how to raise a custom event. My next question is this: If a custom event HAVE TO be raised by another event, what is special about custom event from a normal method then? I can call a method from an event instead of a custom event. Hope someone can lead me to a practical answer. Thank you.

an event can only be called from inside the class, as it’s scope is private.
an event cannot be overriden, but it can go on to the same event or fire other events.

Thank you, Jean.

Hi Mike,

Just interested in what kind of custom event one might want to add, I thought the events listed were complete.


I created a custom ComboBox and added the following events:

[code]Event InvalidSelection(Text as String) 'fires when the entered text does not match any of the items in the list.

Event ListClose() 'fires when the dropdown list is closed/hidden

Event ListOpen() As Boolean 'fires when the dropdown list is about to be shown. Returning true keeps the list from being shown.

OK, thanks.