Support for designing Windows Forms in IronPython is now
available in SharpDevelop 3.1. The
original IronPython forms designer was removed when
SharpDevelop 3.0 began supporting
IronPython 2.0
which had removed support for generating IronPython code from
Microsoft's CodeDOM. The forms designer has now been
re-implemented to use the IronPython
abstract syntax tree (AST) and no longer relies on the
CodeDOM.
Creating a Windows Application
To create a Windows Application open up the new project dialog
by selecting New then Solution from the File
menu. Select the Python category to show the available project
templates. Select the Windows Application project template, enter a
name and location and click the Create button.

Designing Windows Forms
The Windows Forms designer is not yet complete so be warned that
it could generate form code that will no longer compile.
The designer can be opened by opening a form in the text editor
and selecting the Design tab at the bottom of the editor.

Once open in the designer you can add controls to the form by
dragging the controls from the Tools window. In the screenshot
below a label, text box and a button have been added.

Click the Source tab at the bottom of the editor to view the
generated code in the InitializeComponents method.

Limitations
The IronPython forms designer is not yet complete and the
following are some of the known limitations.
- No support for project or local form resources.
- No support for icons.
- Incomplete support for ToolStripItems and menu strips.
- Incomplete support for ListViewItems.
- No support for TreeViewItems.
- Incomplete support for non-visual components (e.g.
Timers).
- Controls needed to be fully namespace qualified.
Forms Designer Internals
For those interested in how the forms designer actually works at
a high level we will now look at what the IronPython forms designer
does when loading and then generating code for a form.
To show the form in the designer the following steps are
executed.
- The form's code is parsed and an IronPython AST
(PythonAst object) is created.
- The AST is then visited and each control is added to the
forms designer and the control's properties are set.
- The form's properties are set in the designer and the
form is displayed.
To generate the code after the form has been designed the
following steps are executed.
- The form is obtained from the forms designer.
- Each of the child components of the form have their
properties checked to see if they need to be serialized. This can
be done by getting all the
property descriptors and then checking the
ShouldSerializeValue method. If they do need to be serialized
then code is generated for them and added to a StringBuilder.
- After all the child components are added the code for the
form is generated.
- Finally the generated code is inserted into the text editor
inside the InitializeComponent method, replacing any existing
code.