2017-03-13 10 views
1

私は非常に単純なIron Python/Windowsフォームアプリケーションを持っています。アプリケーションは、それは、アレイ内のラベルの選択を追加する開始すると(これは、CSVファイルから取り組んでいる)コード内のラベルプロパティを修正する

#Create Label for each Site 
 
for s in sites: 
 
    
 
    if lasty == 682: 
 
     lasty = 0 
 
     lastx = lastx + 125 
 

 
    sitename = str(s) #Convert Name into a String 
 
    elementname = sitename.replace(" ","") + "Label" 
 
    element = Label() 
 
    element.Name = elementname 
 
    element.Text = str(sitename) 
 
    element.Parent = self 
 
    element.Location = Point(lastx,lasty) 
 

 
    labels.append(element) #add each element to the list 
 

 
    lasty = lasty + 22 
 
    pass

これは正常に動作しています。次に、別のループを実行する定義があり、結果に応じてラベルの色を変更したいと思っています。失敗の場合は赤、OKの場合は緑、警告の場合は黄色としましょう。

しかし、私は、私はSiteNameLabel.ForeColor = Color.Greenは、そのラベルの緑を回すと思うだろう、私は例えば、彼らに

を与えた要素名でこれらのラベルにリンクするように見えることはできません。しかし、これは失敗し、プログラムを停止します。

アイデア?おそらく簡単な質問ですが、私はこれについてオンラインで何かを見つけることはできません。

'ipyw64.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Program Files (x86)\IronPython 2.7\ipyw64.exe'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Dynamic\v4.0_1.1.1.21__7f709c5b713576e1\Microsoft.Dynamic.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Scripting\v4.0_1.1.1.21__7f709c5b713576e1\Microsoft.Scripting.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IronPython\v4.0_2.7.6.3__7f709c5b713576e1\IronPython.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\IronPython.Modules\v4.0_2.7.6.3__7f709c5b713576e1\IronPython.Modules.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Program Files (x86)\IronPython 2.7\DLLs\IronPython.SQLite.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Program Files (x86)\IronPython 2.7\DLLs\IronPython.Wpf.dll'. Cannot find or open the PDB file. Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in IronPython.Modules.dll Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'Snippets.scripting'. Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in IronPython.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in IronPython.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in IronPython.Modules.dll Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in IronPython.Modules.dll Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in IronPython.Modules.dll Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in IronPython.Modules.dll Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in IronPython.Modules.dll Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.Exceptions.ImportException' in Microsoft.Dynamic.dll 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'Snippets.debug.scripting'. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_64\ISymWrapper\v4.0_4.0.0.0__b03f5f7f11d50a3a\ISymWrapper.dll'. Cannot find or open the PDB file. Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Cannot find or open the PDB file. Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Cannot find or open the PDB file. 'ipyw64.exe' (CLR v4.0.30319: ipyw64.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'. Cannot find or open the PDB file. Exception thrown: 'IronPython.Runtime.UnboundNameException' in IronPython.dll Exception thrown: 'IronPython.Runtime.UnboundNameException' in Snippets.debug.scripting Exception thrown: 'IronPython.Runtime.UnboundNameException' in Microsoft.Dynamic.dll Exception thrown: 'IronPython.Runtime.UnboundNameException' in Snippets.debug.scripting Exception thrown: 'IronPython.Runtime.UnboundNameException' in Snippets.debug.scripting The program '[9416] ipyw64.exe' has exited with code 1 (0x1).

+0

ラベルの色を変更しようとしたときに表示されるエラーメッセージを投稿できますか? – David

+0

元の質問にエラーを追加しました –

答えて

0

あなたは、オブジェクト参照としてSiteNameLabelを使用することはできません。ここで

はエラーです。フォームのControlsコレクションからLabelへの参照を取得する必要があります。

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

from System.Drawing import * 
from System.Windows.Forms import * 

class MyForm(Form): 
    def __init__(self): 
     myLabel = Label() 
     myLabel.Location = Point(10, 10) 
     myLabel.Text = "EXAMPLE LABEL" 
     myLabel.Name = "myLabel" 
     self.Controls.Add(myLabel) 

     # later you can find label by name this way: 
     self.Controls["myLabel"].ForeColor = Color.Green 

Application.EnableVisualStyles() 
Application.SetCompatibleTextRenderingDefault(False) 

form = MyForm() 
Application.Run(form) 

注:あなたは(C#プロジェクトの例では)リサイズデザイナーを使用するときにしようとしたとして、あなたがそれらにアクセスできるように、それは、コントロール名とフォームのメンバーを生成し、次のコードを参照してください。ただし、これは設計時に追加されたコントロールにのみ適用されます。

関連する問題