Re: Minimalist fruit basket program in C# 3.0

  • From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 21 Nov 2007 17:37:25 +0200

Hmm, it looks closer and closer to perl. :-)

I've seen constructs like:

var btnAdd = new Button {Text = "&Add", Parent = tlp};

Isn't possible in .net 2.0 to do this?
Anyway, I think in .net 2.0 is not possible to not define the type of vars...

I think the biggest advantages is that it is not needed to specify the types of vars, and now it allows that hash-style of calling the methods with parameters, that's also great.

The accessibility of WinForms is not so good though.

I've tried with Jaws 6 and 8, and with Jaws 6 after deleting the fruit from the list using alt+D, Jaws still thought that the fruit is there on the list if it was the latest fruit.

With Jaws 8 is a little bit worse because if there is nothing on the list, it doesn't say anything when pressing Insert+tab. At least Jaws 6 says that the focus is on a list box...

Does anyone know if VS.net 2008 is accessible?

Octavian

----- Original Message ----- From: "Jamal Mazrui" <empower@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, November 21, 2007 3:42 PM
Subject: Minimalist fruit basket program in C# 3.0


From the archive at
http://www.EmpowermentZone.com/cs3_fruit.zip

This fruit basket program is written in C# 3.0:  a language update
officially released by Microsoft along with the .NET Framework 3.5 and
Visual Studio 2008.  Visual C# 2008 Express is a free download that
includes the new .NET Framework and SDK.

The archive includes a batch file, compile.bat, which invokes the
command-line compiler to create an executable, cs3_fruit.exe, which is
about 6K in size.  No other files are needed to run the program -- as long
as .NET 3.5 is installed.

Language enhancements to C# 3.0 include functional and dynamic programming
constructs, in-line data queries, inferred typing of local variables, and
property initialization when calling an object constructor.  A technical
overview is at
http://msdn2.microsoft.com/en-us/library/bb308966.aspx

This program uses new language features to be minimalist in the code
required to meet the fruit basket specification at
http://FruitBasketDemo.AlacornComputer.com

No variable types are explicitly declared, each control is specified in a
single statement, and lambda expressions are used for event handlers.  The
included source code is also pasted below.

Jamal

/*
content of cs3_fruit.cs
Fruit Basket program in C# 3.0
Public domain by Jamal Mazrui
*/

// Import namespaces
using System;
using System.Windows.Forms;

// Define class
class FruitBasket {

// Define entry point of program
static void Main() {
// Create controls;
var tlp = new TableLayoutPanel {ColumnCount = 3, RowCount = 2};
var lblFruit = new Label {Text = "&Fruit:", Parent = tlp};
var txtFruit = new TextBox {Parent = tlp};
var btnAdd = new Button {Text = "&Add", Parent = tlp};
var lblBasket = new Label {Text = "&Basket:", Parent = tlp};
var lstBasket = new ListBox {Parent = tlp};
var btnDelete = new Button {Text = "&Delete", Parent = tlp};

// Define Add event handler;
btnAdd.Click += (o, e) => {
var sFruit = txtFruit.Text.Trim();
if (sFruit == "") MessageBox.Show("No fruit to add!", "Alert");
else {
lstBasket.Items.Add(sFruit);
txtFruit.Clear();
lstBasket.SelectedIndex = lstBasket.Items.Count - 1;
}
};

// Define Delete event handler;
btnDelete.Click += (o,e) => {
var iFruit = lstBasket.SelectedIndex;
if (iFruit == -1) MessageBox.Show("No fruit to delete!", "Alert");
else {
lstBasket.Items.RemoveAt(iFruit);
if (iFruit == lstBasket.Items.Count) iFruit--;
lstBasket.SelectedIndex = iFruit;
}
};

// Finalize dialog;
var dlg = new Form {Text = "Fruit Basket", AcceptButton = btnAdd,
StartPosition = FormStartPosition.CenterScreen, AutoSize = true,
AutoSizeMode = AutoSizeMode.GrowAndShrink};
dlg.Controls.Add(tlp);
// Define closing event handler
dlg.Closing += (o, e) => e.Cancel = (MessageBox.Show("Close program?",
"Confirm", MessageBoxButtons.YesNo) == DialogResult.No);
dlg.ShowDialog();
} // Main method
} // FruitBasket class

// End of cs3_fruit.cs

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


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

Other related posts: