简体   繁体   English

如何找出IronPython中要导入的Windows窗体模块?

[英]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 . 我正在尝试从此页面中包含的示例中复制一些代码,并使用这些教程中的一些帮助将其修改为在Iron python上运行。 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') .) (注意:该代码不准确,因为它当前在OCTGN的Iron python脚本引擎中运行。我从其他地方使用一些文本(例如information('Important Announcement') )调用information()函数。)

So the code aborts as soon as I try to execute this self.flowPanel = FlowLayoutPanel() . 因此,一旦我尝试执行此self.flowPanel = FlowLayoutPanel() ,代码就会中止。 If I comment out the flowPanel lines, the windows form appears normally. 如果我注释掉flowPanel行,则Windows窗体将正常显示。

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? 我如何找出要从System.Windows.Forms导入哪个模块以便在我的代码中创建FlowLayoutPanel? And in general how does one figure out what to import in order to get the relevant functionality? 通常,如何弄清楚要导入什么才能获得相关功能?

The answer seems to be that it's whatever is after the third dot '.' 答案似乎是第三个点“。”之后的内容。 in System.Windows.Forms 在System.Windows.Forms中

So to use System.Windows.Forms.Form, you need to import Form. 因此,要使用System.Windows.Forms.Form,您需要导入Form。

All answers wrong. 所有答案都是错误的。 AutoSizeMode is missing in the import, then the code works 导入中缺少AutoSizeMode,则代码有效

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,AutoSizeMode

#from System.Windows.Forms import *



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


        flowPanel = FlowLayoutPanel()
        flowPanel.AutoSize = True
        flowPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink

        print(AutoSizeMode)
        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)

information('laber')    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM