Search code examples
pythonironpythonwindowsformsintegration

How to figure out what windows forms modules to import in ironpython?


I am trying to copy some of the code from the example included in this page and modify it to run on iron python using some help from these tutorials. But I'm stuck as when stepping outside the tutorials, I don't know what modules I need to be importing.

At the moment I have the following code

import clr
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")

from System.Windows.Forms import Application, Form, Button, Label, DockStyle, AnchorStyles, Panel, Screen, FlowLayoutPanel

class OKWindow(Form):
   def __init__(self,InfoTXT):
      newlines = 0
      screenSize = Screen.GetWorkingArea(self)
      STRwidth = 200
      STRheight = 30
      FORMheight = 160 
      FORMwidth = 300
      self.Text = 'Information'
      self.Height = FORMheight
      self.Width = FORMwidth


      self.flowPanel = FlowLayoutPanel()
      #self.flowPanel.AutoSize = true
      #self.flowPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink
      self.Controls.Add(flowPanel)

      label = Label()
      label.Text = InfoTXT
      label.Top = 30
      label.Left = 50
      label.Height = STRheight
      label.Width = STRwidth

      button = Button()
      button.Text = "OK"
      button.Width = 100
      button.Top = FORMheight - 80
      button.Left = (FORMwidth / 2) - 50
      print button.Anchor
      button.Anchor = AnchorStyles.Bottom

      button.Click += self.buttonPressed

      self.Controls.Add(label)
      self.Controls.Add(button)

   def buttonPressed(self, sender, args):
      Application.Exit()

def information(Message):
   Application.EnableVisualStyles()
   form = OKWindow(Message)
   Application.Run(form)

(Note: The code is not exact as it's currently running within OCTGN's iron python scripting engine. I call the information() function from elsewhere with some text such as information('Important Announcement').)

So the code aborts as soon as I try to execute this self.flowPanel = FlowLayoutPanel(). If I comment out the flowPanel lines, the windows form appears normally.

So it seems to me that I haven't imported the module that is needed properly. Unfortunately I have no idea what to load. I tried loading whatever I thought would be the right one, but none seem to work for me.

How can I figure out what module to import from System.Windows.Forms in order to create a FlowLayoutPanel in my code? And in general how does one figure out what to import in order to get the relevant functionality?


Solution

  • The answer seems to be that it's whatever is after the third dot '.' in System.Windows.Forms

    So to use System.Windows.Forms.Form, you need to import Form.