# .Net Events in IR

**URL:** <https://www.ruby-forum.com/t/net-events-in-ir/171929>\
**Category:** IronRuby\
**Created:** [July 11, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/net-events-in-ir/171929 "2009-07-11T17:17:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shayfriedman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@shayfriedman](https://www.ruby-forum.com/u/shayfriedman)\
**Post date:** [July 11, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/net-events-in-ir/171929/1 "2009-07-11T17:17:45Z")

</div>

Hi there,

I know that I can register and handle .Net events in IronRuby in the  
following way:  
klass.some\_event { |sender, args| puts “Hello!” }

Is this the only way of doing so or are there more ways?

## Thanks! Shay.

Shay F.  
[http://www.ironshay.com](http://www.ironshay.com)  
Follow me: [http://twitter.com/ironshay](http://twitter.com/ironshay)

---

<div class="post-metadata">

**Author:** ![shayfriedman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@shayfriedman](https://www.ruby-forum.com/u/shayfriedman)\
**Post date:** [July 12, 2009, 1:43am UTC](https://www.ruby-forum.com/t/net-events-in-ir/171929/2 "2009-07-12T01:43:14Z")

</div>

Shay F. wrote:

> Hi there,
> 
> I know that I can register and handle .Net events in IronRuby in the  
> following way:  
> klass.some\_event { |sender, args| puts “Hello!” }
> 
> Is this the only way of doing so or are there more ways?
> 
> ## Thanks! Shay.
> 
> Shay F.  
> [http://www.ironshay.com](http://www.ironshay.com)  
> Follow me: [http://twitter.com/ironshay](http://twitter.com/ironshay)

What are you looking to do currently, is there something specific you  
want to accomplish?

You are sending a block, so this could be multi-line with do/end . Also,  
(depending on the context of your program), you could forgo the |sender,  
args| :

button.click do  
puts “Something…”  
puts “Very interesting…”  
end

I’ve attached a very simple Windows Forms app which shows this method of  
hooking up an event, firing it manually through code, and then bringing  
up the GUI…

---

<div class="post-metadata">

**Author:** ![shayfriedman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@shayfriedman](https://www.ruby-forum.com/u/shayfriedman)\
**Post date:** [July 12, 2009, 1:46am UTC](https://www.ruby-forum.com/t/net-events-in-ir/171929/3 "2009-07-12T01:46:06Z")

</div>

I couldn’t attach the specified file, as the forum would give me an  
Application Error, will try to send to Shay directly…

Please feel free to direct message me if anyone else comes across this  
and wants a copy of the file.

Otherwise, I’d suggest a better resource for writing windows apps with  
IronRuby is Thibaut BarrÃ¨re’s “magic”:

> **[GitHub - thbar/magic: IronRuby sugar for WPF, Silverlight and Windows Forms.](https://github.com/thbar/magic/tree/master)**
>
> master
