访问 IronPython 中的嵌入式资源
我正在 IronPython Studio 中开发 Windows 窗体应用程序。 我想为我的项目选择一个图标,但这两个都失败了: 1- 表单属性窗口 -> 图标(选择 *.ico 文件) 发生编译时错误并且与 IronPython.targets 文件相关
“IronPythonCompilerTask”任务 出乎意料地失败了。 System.ArgumentNullException:值 不能为空。
2-我将 *.ico 文件添加到项目(项目 -> 添加 -> 现有项目),并在其属性中,将“构建操作”更改为“嵌入资源” 现在我无法使用 System.Reflection.Assembly 来访问此资源 我的代码:
self.Icon = Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream('IronPythonWinApp.myIcon.ico'))
在运行时会引发异常:
被调用的成员在动态程序集中受机器人支持
有谁知道向 IronPython WinForms 添加图标的更好(最好?)的方法吗?
谢谢
I'm developing a Windows Forms Application in IronPython Studio.
I want to choose an Icon for my project but both of these fail:
1- Form Properties window -> Icon (choose a *.ico file)
a compile-time error occurs and is related to IronPython.targets file
The "IronPythonCompilerTask" task
failed unexpectedly.
System.ArgumentNullException: Value
cannot be null.
2- I add a *.ico file to Project (Project -> Add -> Existing Item) and in its properties, change the 'Build Action' to 'Embedded Resource'
now I cannot use System.Reflection.Assembly to gain access to this resource
my code:
self.Icon = Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream('IronPythonWinApp.myIcon.ico'))
in runtime it throws an exception:
The invoked member is bot supported in a dynamic assembly
Does anyone know a better (best?) way to add an icon to an IronPython WinForms ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IronPython 是一种动态脚本语言; 它在运行时从脚本文件本身进行解释,而不是编译成程序集。 由于没有编译的程序集,因此您无法拥有嵌入式资源。 以下是在 IronPython 中向表单添加图标的两种方法:
首先,您可以将图标作为松散文件与 python 脚本一起包含在内。 然后,您可以通过将图标文件名传递给 System.Drawing.Icon 构造函数来创建图标对象。 下面是此场景的一个示例,其中主 python 脚本和图标部署在同一目录中。 该脚本使用此处找到的解决方案找到目录。
或者,您可以加载一个图标,该图标作为嵌入资源包含在用 C# 编写的 .NET 程序集中。
IronPython is a dynamic scripting language; it is interpreted at runtime from the script files themselves, rather than being compiled into an assembly. Since there is no compiled assembly, you cannot have an embedded resource. Here are two ways of adding an icon to a form in IronPython:
First, you could include the icon as a loose file alongside the python scripts. You can then create the icon object by passing the icon filename to the System.Drawing.Icon constructor. Here is an example of this scenario, where the main python script and the icon are deployed in the same directory. The script uses the solution found here to find the directory.
Alternatively, you can load an icon that is included as an embedded resource in a .NET assembly that is written in C#, for instance.