Fruit basket program in Ruby.NET

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Fri, 4 Jan 2008 23:59:22 -0500 (EST)

From the archive
http://www.EmpowermentZone.com/rbn_fruit.zip

This fruit basket program is written in Ruby.NET:  a version of the Ruby
language hosted at
http://rubydotnet.googlegroups.com/web/Home.htm

The official home of Ruby is
http://ruby-lang.org

Ruby.NET was originally developed at a university in Australia, supported
by a grant from Microsoft Future Technologies.  Later, the open source
model was adopted, and development continues as a collaborative effort of
the Ruby community.

Note that another Ruby version based on the .NET platform is IronRuby,
being developed in-house at Microsoft, with a web presence at
http://ironruby.rubyforge.org/

That version is a younger and less complete implementation of Ruby so far.

A batch file in this archive, compile.bat, creates the executable
rbn_fruit.exe, which is about 24 KB in size.  Several related DLL files
are also needed -- placed either in the program directory or global
assembly cache -- for a combined size of about 1.5 MB.

Jamal

# content of rbn_fruit.rb
# Fruit Basket program in Ruby.NET
# Public domain by Jamal Mazrui

# Import namespaces
require "mscorlib.dll"
require "System.dll"
require "System.Deployment.dll"
require "System.Drawing.dll"
require "System.Windows.Forms.dll"

# Create controls
tlp = System::Windows::Forms::TableLayoutPanel.new
tlp.ColumnCount = 3
tlp.RowCount = 2

lblFruit = System::Windows::Forms::Label.new
lblFruit.Text = "&Fruit:"

txtFruit = System::Windows::Forms::TextBox.new

btnAdd = System::Windows::Forms::Button.new
btnAdd.Text = "&Add"

lblBasket = System::Windows::Forms::Label.new
lblBasket.Text = "&Basket:"

lstBasket = System::Windows::Forms::ListBox.new

btnDelete = System::Windows::Forms::Button.new
btnDelete.Text = "&Delete"

[lblFruit, txtFruit, btnAdd, lblBasket, lstBasket, btnDelete].each {|ctl|
tlp.Controls.Add(ctl)}

# Define Add event handler
btnAdd.add_Click do
sFruit = txtFruit.Text.Trim
if sFruit.Length == 0
System::Windows::Forms::MessageBox.Show("No fruit to add!", "Alert")
else
lstBasket.Items.Add(sFruit)
txtFruit.Clear
iFruit = lstBasket.Items.Count - 1
lstBasket.SelectedIndex = iFruit
end
end

# Define Delete event handler
btnDelete.add_Click do
iFruit = lstBasket.SelectedIndex
if iFruit == -1
System::Windows::Forms::MessageBox.Show("No fruit to delete!", "Alert")
else
lstBasket.Items.RemoveAt(iFruit)
iFruit -= 1 if iFruit = lstBasket.Items.Count
lstBasket.SelectedIndex = iFruit
end
end

# Finalize dialog
dlg = System::Windows::Forms::Form.new
dlg.Text = "Fruit Basket"
dlg.AcceptButton = btnAdd
dlg.StartPosition = System::Windows::Forms::FormStartPosition.CenterScreen
dlg.AutoSize = true
dlg.AutoSizeMode = System::Windows::Forms::AutoSizeMode.GrowAndShrink
dlg.Controls.Add(tlp)
dlg.ShowDialog

# End of rbn_fruit.rb


__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: