Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

Exploring Winforms
By Jim Joy C.

In this article, I've tried to explore some more on WinForms (sorry, now I cannot call them WinForms anymore, I guess) i.e., Windows Forms. Through this article I'll be taking you through the development of a simple Address Book application. This application was first developed in Beta 1.0 of the .NET framework, but before I could publish it, Beta 2.0 came out. So I decided to port the application and now I realize that it was really worth doing it !

I've not used a database to store the addresses in this application. I'm developing an address book that uses a backend database to store the addresses. This version of the address book uses a flat file (named AddressBook.data) to store the addresses.

You can do a few enhancements to this address book. For example, you can provide sorting of the addresses by using the ColumnClick event. You can also prevent duplicate entries from being added to the address book. I was feeling a little lazy, so didn't bother to add them :)

Now, let me take you through the code. The address book application consists of 3 files, Splash.cs, AddressList.cs, AddressEntry.cs.

Splash.cs creates the form that serves as a splash screen for the address book application. This form uses 2 link labels and a label. The 2 link lables are used to navigate to the next form and to provide the user an option to exit from the application.

AddressList.cs creates the form that serves as the main window for the address book application. This form houses a ListView class which belongs to the Systems.Windows.Forms namespace. This form also contains 4 Buttons for Adding, Editing Removing addresses and also for exiting out of the application.

AddressEntry.cs creates the form that is used by the address book application for adding and editing addresses. This form also performs some basic validation before adding / updating the addresses.

Let me also tell you about the changes that I made to the application to port it from Beta 1.0 to Beta 2.0 of the .NET framework.

The MessageBox button and icon enumeraters have changed - instead of using MessageBox.OK for the OK button in the MessageBox and Message.IconError for displaying the error icon in the message box (this was the way in Beta 1.0), Beta 2 uses 2 new enumarators names MessageBoxButtons and MessageBoxIcon (so now for the Ok button, it's MessageBoxButtons.OK and for the error icon, it's MessageBoxIcon.Error).

The ListView class and other related classes like The ListViewItem class, The ListViewSubItem classes have undergone a lot of changes.

Please note that this application will compile only with the Beta 2.0 version of the .NET framework.

For compiling, use the following command

csc /target:winexe /out:AddressBook.exe Splash.cs AddressList.cs AddressEntry.cs

This will create the fle named AddressBook.exe

The source code is listed below, file by file.

Source Code - I
File Name : Splash.cs

Source Code - II
File Name - AdressList.cs

Source Code - III
File Name - AddressEntry.cs

Please free to e-mail me with any comments / clarifications