IronPython & Windows Forms
A Tutorial Series

Contents
Windows Forms
Windows Forms is the most common GUI toolkit for the .NET framework. Windows Forms for .NET 1.1 and some of .NET 2.0 is also supported by Mono.
Windows Forms is generally a straightforward API, and through IronPython allows you to create professional looking applications with uncomplicated and readable code.
This tutorial series introduces Windows Forms, illustrates how to read the Microsoft API Documentation from an IronPython point of view. It demonstrates GUI layout and the common controls.
There is also a sample application, Tabbed Image Viewer, which illustrates using a range of controls including a tabcontrol, toolbar, menu, context menu, file dialogs, message boxes, forms as dialogs and more...
The Tutorials
- Introduction to IronPython
A general introduction to IronPython.
- Hello World with IronPython
Starting the application loop and displaying a form.
- Widgets & Event Handlers
Basic controls (the Label and the Button) and event handlers.
- Panels and Styles
GUI layout with Windows Forms.
- The TextBox Widget
Another .NET control, the TextBox.
- CheckBoxes & RadioButtons
- Dock & Anchor
More layout with Dock, Anchor and the Z-Order.
- C# and the Clipboard
Extending IronPython with C# and using the clipboard.
- Background Worker Threads
The Windows Forms BackgroundWorker class.
- Unmanaged Code, Screenshots and IronPython
- Towards a Richer GUI: The TabControl, Splitter & the PictureBox
Looking at some more sophisticated GUI controls.
Tabbed Image Viewer
This application demonstrates Windows Forms, using a variety of controls in 18k of source code, including a really funky about dialog.
There is also source C# illustrating creating a custom executable by embedding the IronPython engine. It also shows creating a class in C# and accessing it from IronPython.
It views multiple images inside tabpages in a tabcontrol. In can load images in several formats and allows you to resave them in a different format. It has two view modes for images, a menu, context menu and toolbar and can copy images to the clipboard.
Most of the code is pretty straightforward. There is one part of voodoo magic in there, which implements a nice feature. This is everything associated with the SetClipboardViewer which uses the win32api (so Windows only for this feature, sorry). When an image is set on the clipboard, it is automatically pasted into a new tab in the image viewer.
My favourite feature is the about dialog. Move the mouse over our names.
Tabbed Image Viewer does run under Mono (tested with 1.2.3 on Windows), but there are a few bugs and oddities. Patches welcomed.
Developing with IronPython & Windows Forms
Developing with IronPython and Windows Forms
An S5 presentation on developing with Windows Forms. Presented (in short form) at PyCon 2007 by myself and a colleague. You can either view this as slides, or as a single longer page with lots of notes.
The IronPython Cookbook
There are also several extra Windows Forms samples in the IronPython Cookbook. This includes an example of data-binding with a DataGridView. It shows the results of any SQL query in the grid.
For buying techie books, science fiction, computer hardware or the latest gadgets: visit The Voidspace Amazon Store.

Last edited Fri Nov 27 18:32:35 2009.
Counter...