Browse DevX
Sign up for e-mail newsletters from DevX


Developing Windows Forms Applications on Mono  : Page 2

Developing cross-platform programs that rely on Windows Forms takes a big step forward with the latest release of the Mono platform.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Testing Mono's Windows Forms
One good way to test the progress of Mono's Windows Forms is to compile and run some of the sample code from Microsoft's Visual Studio help files. I gave this a shot for a number of different examples, including one for the DataGrid. Running the DataGrid demo confirmed that it still doesn't work—although it doesn't crash, and you can examine some of its properties.

Another good test is to try out some of the open source projects out on the net. The Mono guys did just this for a demonstration at the recent Brainshare conference in Salt Lake City. To give it a good test they downloaded the TerraDemo Windows Forms demonstration program, made a few changes to accommodate non-working controls (such as the DataGrid by changing it to a ListView), compiled the source with Mono, and ran the project. The result was a pretty amazing demonstration of multiple controls including the TabControl, ImageList, StatusBar, and more. TerraDemo also makes heavy use of Web services to communicate with Microsoft's TerraServer Web site. Fortunately, the ASP.NET portion of Mono, including Web services support, has been solid for some time already. You can download the changed TerraDemo files here.

But unless you can quantify everything your applications need, perhaps the best testing method is to just start coding and see what happens. That approach can be frustrating with this release if you don't know where the holes are. For example, creating the sample code for this article required more than a few hours trying to work around some of the limitations of the controls as implemented. The goal was to build a simple program with a few controls using VB.NET in Visual Studio 2003, generate an EXE file, copy it over to the Linux machine, and see if it ran. To help ease the pain, you can check the Mono Windows Forms status page to find out the status of your favorite control.

Build a Sample App
The Mono Windows Forms Web site has a section dedicated to tracking the implementation progress of the various controls. You'll also find a link to download the latest version of the System.Windows.Forms.dll file for Linux. To use the new file you must execute the following commands as root from a terminal window:

# gacutil -u System.Windows.Forms # gacutil -i System.Windows.Forms.dll

This method should work as long as none of the supporting file versions have changed, which typically happens only after a point release.

Data binding to most controls works fine (with the exception of the DataGrid). To test this out I created a simple program that reads a list of birthdays from an XML file, binds the last names to a list box, and displays the first name and date in separate combo boxes when users select a name (see Figure 1). This application also uses the FileDialog control to open and save the XML file.

Figure 1. Birthdays GUI: The birthday tracker application has a pretty simple interface and functions almost identically on Windows or Linux.

Public Class Form1 Inherits System.Windows.Forms.Form Public dsBirthdays As New DataSet Private Sub btnReadXML_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnReadXML.Click Dim openFileDialog1 As New OpenFileDialog openFileDialog1.Filter = "XML Files|*.xml" openFileDialog1.Title = "Select an XML File" ' Show the Dialog. ' If the user clicked OK in the dialog and ' an .XML file was selected, open it. If openFileDialog1.ShowDialog() = _ DialogResult.OK Then dsBirthdays.ReadXml(openFileDialog1.FileName) lstNames.DataSource = dsBirthdays.Tables(0) lstNames.DisplayMember = "LastName" End If End Sub Private Sub lstNames_SelectedIndexChanged( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles lstNames.SelectedIndexChanged cmbName.DataSource = dsBirthdays.Tables(0) cmbName.DisplayMember = "FirstName" cmbBirthday.DataSource = dsBirthdays.Tables(0) cmbBirthday.DisplayMember = "Birthday" End Sub Private Sub btnQuit_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnQuit.Click Application.Exit() End Sub End Class

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date