Windows Form


#1

Hello,

i would like to play around with windows forms in rhino python.
First tries are working, but i cannot find out how to return to rhino in
a “clean” way. When closing the form either i cannot start python
scripteditor again without an error or I cannot run the script a second time.

import System.Windows.Forms    

class HelloWorldForm(System.Windows.Forms.Form):
    def __init__(self):
        self.Text = 'Hello World'
        self.Name = 'Hello World'
        self.Closing += self.OnClosingEvent
        System.Windows.Forms.Application.Run(self)
    def OnClosingEvent(self, sender, e):
        self.Close()

form = HelloWorldForm()

what am I missing?
Thank you in advance!


(Alain Cormier) #2

Hi,

You’re already running in the context of Rhino so instead of starting a message loop you probably just want to show the form. Something like this …

import System.Windows.Forms

class HelloWorldForm(System.Windows.Forms.Form):
    def __init__(self):
        self.Text = 'Hello World'
        self.Name = 'Hello World'

form = HelloWorldForm()
form.ShowDialog()

#3

Thanks for the hint - this solved some issues.
But is it possible to keep the form “alive” when the python script has finished?
Lets say I want to show a chart and keep its form open while returning
to rhino. ShowDialog also seems to wait for the form being closed before
the script continues.


(Dale Fugier) #4

http://msdn.microsoft.com/en-us/library/aa984358(v=vs.71).aspx


#5

Thanks Dale, .Show() did the trick.