[IronPython] modal dialog example

Martin Maly Martin.Maly at microsoft.com
Thu Jul 6 10:03:05 PDT 2006


import clr
clr.AddReference ('System.Windows.Forms')

from System.Windows import Forms


class MyDialog(Forms.Form):
    def __init__(self):
        self.Text ='Dialog'
        egg_button = Forms.Button(Text='Eggs', Visible=True)
        egg_button.Click += self.OnEgg
        spam_button = Forms.Button(Text='Spam', Visible=True, Left = 50)
        spam_button.Click += self.OnSpam
        print self.Controls.Add(egg_button)
        print self.Controls.Add(spam_button)

    def OnEgg(self, *args):
        self.result = "Eggs"
        self.DialogResult = Forms.DialogResult.OK
        self.Close()
    def OnSpam(self, *args):
        self.result = "Spam"
        self.DialogResult = Forms.DialogResult.OK
        self.Close()


class MyMainForm(Forms.Form):
    def __init__(self):
        self.Text = 'Main Form'
        my_button = Forms.Button(Text='Choose one!')
        my_button.Click += self.OnClick
        self.Controls.Add(my_button)
    def OnClick(self, *args):
        md = MyDialog()
        if md.ShowDialog() == Forms.DialogResult.OK: print md.result


app = MyMainForm()
Forms.Application.Run(app)

________________________________
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of jeff sacksteder
Sent: Thursday, July 06, 2006 9:43 AM
To: Discussion of IronPython
Subject: [IronPython] modal dialog example

I'm have trouble mentally translating the Vb and C# examples I found online. Could someone finish this trivial example of calling a modal dialog and returning the choice that was selected?

import clr
clr.AddReference ('System.Windows.Forms')

from System.Windows import Forms

class MyMainForm(Forms.Form):
    def __init__(self):
        self.Text = 'Main Form'
        my_button = Forms.Button(Text='Choose one!')

class MyDialog(Forms.Form):
    def __init_(self):
        self.Text ='Dialog'
        egg_button = Forms.Button(Text='Eggs')
        spam_button = Forms.Button(Text='Spam')

app = MyMainForm()
Forms.Application.Run(app)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/users-ironpython.com/attachments/20060706/7254a5f5/attachment.htm


More information about the users mailing list