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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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)

_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to