[IronPython] Making A Windows Form App

Martin Maly martmaly at exchange.microsoft.com
Wed Jul 6 22:13:17 CEST 2005


Hi Freddie,

Below is the working code. I would be interested to hear what you had
most problems with. Common difficulty is the LoadAssemblyByName
function. Feel free to post feedback to this discussion alias. We are
interested to hear what roadblocks developers encounter as they try to
use IronPython.

Martin

import sys
sys.LoadAssemblyByName("System.Drawing")
sys.LoadAssemblyByName("System.Windows.Forms")

import System
from System.Drawing import Point
from System.Windows.Forms import Form, Button, Application

def on_click(*args):
    Application.Exit()

frm = Form(Text = "Hello World")
btn = Button(Text = "Goodbye", Location = Point(50,50))

btn.Click += on_click
frm.Controls.Add(btn)

Application.Run(frm)



 

> Freddie Witherden Wrote:
> 
> Hi, I am trying to convert a very simple C# windows form test 
> that I made into IronPython (to see that it can be done). 
> However I have tried over 20 different ways with no luck. Can 
> anyone help me? There is very very little documentation on 
> IronPython, which I think needs to be addressed. The code
> is:
> using System;
> using System.Drawing;
> using System.Windows.Forms;
> 
> namespace WinForms
> {
> 	public class HelloWorld : System.Windows.Forms.Form
> 	{
> 
> 		private Button btn;
> 
> 		public HelloWorld()
> 		{
>             Text = "Hello World";
> 
> 			btn = new Button();
> 			btn.Location = new Point(50,50);
> 			btn.Text = "Goodbye";
> 			btn.Click += new System.EventHandler(btn_Click);
> 
> 			Controls.Add(btn);
> 		}
> 
> 		static void Main()
> 		{
> 			Application.Run(new HelloWorld());
> 		}
> 
> 		private void btn_Click(object sender, EventArgs e)
> 		{
> 			Application.Exit();
> 		}
> 	}
> }



More information about the Ironpython-users mailing list