Visual C# 更改控件上的图像会出现异常

Visual C# changing image on control gives exception

我正在用 C# 编写一个插件,其中我有一个带有 linklabel 的用户控件,它控制一个显示为 tooltippicturebox 的表单标签旁边显示表单是可见还是隐藏的状态。

我有两张图片,是本书通过 Visual Studio PludingResources Designer 添加为资源的。 (我尝试将图像的持久性设置为在编译时链接和嵌入以解决问题。)

橡胶在以下代码中遇到了道路:

pictureBox1.Image = SubAsst.PluginResources.SubAsst_Enabled1;

当代码执行到这一行以显示图像时,我得到 System.Resources.MissingManifestResourceException 异常。例外情况如下:

"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "SubAsst.PluginResources.resources" was correctly embedded or linked into assembly "SubtitlingAssistant" at compile time, or that all the satellite assemblies required are loadable and fully signed."

我在 msdn 和其他所有我能找到的地方都找遍了,但我还没有找到解决方案。除非,如果我更改代码以使用内置系统图标,那就行得通了:

pictureBox1.Image = System.Drawing.SystemIcons.Information.ToBitmap();

到目前为止,这是我的解决方法。但是我想为插件使用我的自定义图像。

我怀疑API不允许使用图像资源,但这没有记录。我猜这是因为图标可以导入并显示在插件的默认按钮上。

如有任何建议,我将不胜感激。

似乎缺少某些资源文件,请检查这些

MSDN 链接

You may receive a "System.Resources.MissingManifestResourceException" error message when you access the .resources file of the form at run time A System.Resources.MissingManifestResourceException exception occurs when you try to access a localized resource

C#: What does MissingManifestResourceException mean and how to fix it?

解决方法如下:

缺少的是属性框中的 CustomToolNamespace:

  • 构建操作:嵌入式资源
  • 复制到输出目录:不要复制
  • 自定义工具:ResXFileCodeGenerator
  • 自定义工具命名空间:[myapplicationnamespace]

命名空间与我的应用程序的命名空间匹配。一旦我设置了它并重建了应用程序,错误就消失了,图像也显示出来了。

感谢 Meysam Tolouee 的回答中的 link,这导致了 this "off-topic" answer。这绝对不是题外话,我希望我早点找到它。

这个 StackOwerflow 是多么棒的工具!