the blog
Back to -Blog

IronRuby Visual Form Designer (preview)

A Taste of Things To Come
by Huw Collingbourne
Wednesday 31 October 2007.

We’ve been following the development of Microsoft’s IronRuby project (Ruby for the CLR) with interest and we thought some people might like to take a look at the IronRuby form-designer we’ve been working on. Bear in mind that IronRuby itself is in the early stages of development - and so is our form designer. The shipping versions of both are likely to change quite a bit over time. Our form designer is not currently publically available but we may decide to release a beta at a later date.

Anyway, here is a simple walkthrough showing how we can use our form designer to do ‘visual programming’ with IronRuby. Here I shall be creating a simple file browsing tool.

First I start a new project in Visual Studio and select the IronRuby template.

This creates a basic application with this minimal Ruby code defining a form...

To do the form design, I just need to click the Form1.rb[Design] tab and start dragging and dropping controls onto a form. Here, I have dragged a button, a textbox, two labels and a List Box...

I want to be able to browse to select a directory so I have also dropped on a FolderBrowserDialog which docks itself into the area beneath the form.

I now want to alter some properties. I can do that using the Properties panel. Here I am changing the caption (the Text property) of the form.

I can move and resize the components on the form itself in exactly the same way that I might do so in C# or VB. Here for example, I am aligning label2 with the help of the form designer’s alignment guides (the blue lines showing the edges of adjacent controls)...

As I make all these changes, behind the scenes the Ruby In Steel form designer is writing all the details as Ruby-syntax form-definition code...

Now comes the time to do some programming. I double click the button to create its default (click) event-handler. This is generated automatically and my cursor is placed into the editor ready for me to add some code...

I’ll add code to show the folder dialog and retrieve an array of file names from the folder which the user selects. This array is then processed using a Ruby block to iterate through the files names and display them in the list box:

Now I want to add an event-handler to the List Box so that file information (supplied by the .NET FielInfo class) can be displayed in the text box and labels when a list box item (a file name) is double clicked. Here’s my code:

The current version of IronRuby does not fully support the delegate/event handler mechanism which is normally used to ‘wire up’ events to methods. In our current beta, we have therefore had to use a different technique. We’ve used a ‘block’ (the code below between do and end which contains a call to the actual event-handler (listBox1_DoubleClick) when an event occurs. This is a reasonable approximation of delegation but when IronRuby provides true delegate/event-handlers we shall alter the form designer to support them...

Now comes the proof of the pudding. I press CTRL+F5 to run the IronRuby program and this is what I see - my form with all the components just as I positioned them at design time. I click the button...

...and up pops the folder browser. I now browse to a folder and click OK...

...and, sure enough, my IronRuby code uses a .NET class to get a list of file names in the selected directory, I iterate through them using a Ruby block and populate the list box with their names. I have double-clicked a file name in the list box which has triggered the listBox1_DoubleClick method to show the file creation date and size in bytes in the two labels.

Bear in mind that, as I said earlier on, this is a very early ‘in house’ alpha of our form designer. As IronRuby progresses, we shall refine and adapt the form designer to take full advantage of IronRuby’s features. We’ll have a lot more to say about visual design in the months ahead, so, if this is of interest to you, be sure to visit our blog regularly...

Bookmark and Share   Keywords:  .NET  IronRuby
© SapphireSteel Software 2013