** I tried sending this much earlier but my message didn't go through **

Hi, Martin--

Here's a short example that might illustrate what you're trying to
accomplish:

require "System.Windows.Forms"
include System
include System::Windows::Forms

button = Button.new

click_event = button.GetType.get_event("Click")

on_click = EventHandler.new { |sender, e| puts "Click!" }

click_event.add_event_handler(button, on_click)

button.perform_click # Click!

click_event.remove_event_handler(button, on_click)

button.perform_click

More canonical examples of using events in IronRuby are found here:
http://www.ironruby.net/Documentation/.NET/Events

--Ray

On Mon, Aug 3, 2009 at 2:46 PM, Martin Smith <martin.smith...@gmail.com>wrote:

> Hello,
>
> I was wondering how I can get a delegate in IronRuby.
>
> One thing I was thinking about doing was trying to attach an event handler
> with an EventInfo and it requires a delegate.  It has a method called
> AddEventHandler(object, Delegate), and i wanted to attach an event handler.
>
> But I can't find any way to get a delegate in ruby.  How would you guys do
> it?
>
> I know i can also use:
>
> object.send(event_name) { |*e| ...... }
>
> In that case how would i remove that event handler?
>
> Thanks in advance,
> Martin
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core@rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to