我在工程项目中已经添加了return.bmp的文件,可是在调试时却出现如下错误:
高人指点指点;
//******************************************************************
未处理的“System.ArgumentException”类型的异常出现在 system.drawing.dll 中。其他信息: 未能在类“BitmapRegionTest.Form1”中找到资源“return.bmp”。//******************************************************************出错代码:
private Bitmap bmpBob = new Bitmap(typeof(Form1), "return.bmp");

解决方案 »

  1.   

    private Bitmap bmpBob = new Bitmap(Form1.GetType().Assembly.GetManifestResourceStream("命名空间.return.bmp"));
    或者
    private Bitmap bmpBob = new Bitmap(this.GetType().Assembly.GetManifestResourceStream("命名空间.return.bmp"));
      

  2.   

    添加引用
    using System.Bitmap;
      

  3.   

    请注意将这个文件“生成方式”设为“嵌入的资源”资源文件的名称是:命名空间.文件名如果命名空间和资源所在的目录不同,则为:根命名空间.路径名.文件名-------------------------
    如果你想了解你程序集中的资源名称,可以尝试使用下面的代码:(来自 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 的内容就是程序集所有资源的名称。