Control Instance override Menu Handlers?

I have a Canvas subclass which implements menuHandlers for EditCopy & EditPaste. I have an instance of this control on a window, and I’d like to be able to override these two menu handlers. It seems like I can’t do this - there’s no way to add a menuHandler to a control instance in the IDE directly.

Is there an elegant way to do this? I suppose the subclass could define an DoEditCopy event which returns a boolean - if the control instance returns true then the superclass will ignore it.

Bounce the menu handler to the window instance with an event first…

[code]Class MyCanvas

Event EditCopy() As Boolean //Event Definition

Function EditCopy() As Boolean //Menu Handler
if RaiseEvent EditCopy then return true //skip if ‘subclass’ handled
Msgbox “EditCopy handled by MyCanvas”
Return True
End Function

End Class

//Event Handler
Function EditCopy() As Boolean
MsgBox “EditCopy handled by WindowInstanceOfMyCanvas”
return true
End Function[/code]

Be sure to return True or the Canvas subclass will process the menu action too.

Thanks, that’s what I was thinking myself. It’s a little weird that you can add a menuHandler to a class, but not to an instance, but not a big deal.

[quote=24348:@Michael Diehr]
Is there an elegant way to do this? I suppose the subclass could define an DoEditCopy event which returns a boolean - if the control instance returns true then the superclass will ignore it.[/quote]

Bingo

ha ha, I only read the first paragraph :stuck_out_tongue: