我在工程项目中已经添加了return.bmp的文件,可是在调试时却出现如下错误:
高人指点指点;
//******************************************************************
未处理的“System.ArgumentException”类型的异常出现在 system.drawing.dll 中。其他信息: 未能在类“BitmapRegionTest.Form1”中找到资源“return.bmp”。//******************************************************************出错代码:
private Bitmap bmpBob = new Bitmap(typeof(Form1), "return.bmp");
高人指点指点;
//******************************************************************
未处理的“System.ArgumentException”类型的异常出现在 system.drawing.dll 中。其他信息: 未能在类“BitmapRegionTest.Form1”中找到资源“return.bmp”。//******************************************************************出错代码:
private Bitmap bmpBob = new Bitmap(typeof(Form1), "return.bmp");
或者
private Bitmap bmpBob = new Bitmap(this.GetType().Assembly.GetManifestResourceStream("命名空间.return.bmp"));
using System.Bitmap;
如果你想了解你程序集中的资源名称,可以尝试使用下面的代码:(来自 ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cscon/html/vclrfcodefindingnamesofresourcesinassemblyvisualc.htm )Sub Main(){
System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
string [] resources = thisExe.GetManifestResourceNames();
string list = "";// Build the string of resources.
foreach (string resource in resources)
list += resource + "\r\n";
}设法查看到 list 的内容(Debug.Write, MessageBox, 或者赋值给一个 TextBox 等等,list 的内容就是程序集所有资源的名称。