http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=31B18AB9-AA7E-4819-DFAE-A35C744F63AA

解决方案 »

  1.   

    编译时候不出错是因为编译的时候不会检查 wheelh.bmp 存不存在。执行的时候出错,是因为执行时候会找这个文件。图片和解决方案在一个目录里面 ??解决方案下还有好几层目录,图片只有一个层目录?? 
    你需要把图片和生成的exe 文件在一个目录下。不过推荐你在new Bitmap(GetType(),"wheelh.bmp"); 时候指明文件的绝对路径,而不是相对路径。获得当前应用程序的执行目录可以用下面的代码获得:string strPath = AppDomain.CurrentDomain.BaseDirectory.ToString();aImage=new Bitmap(GetType(),"wheelh.bmp");
    改成:
    string strPath = AppDomain.CurrentDomain.BaseDirectory.ToString();
    aImage=new Bitmap(GetType(),strPath+"/wheelh.bmp");
      

  2.   

    将wheelh.bmp 文件改成嵌入式编译
      

  3.   

    工程资源浏览器(右边的那个)右击wheelh.bmp 选属性将生成操作改成"嵌入的资源"
      

  4.   

    不过迁入的资源,再读取的时候,稍稍有点复杂。而且生成的文件会大。下面是从迁入的资源中读取内容的范例代码。
    这里只是简单的读取一个文本文件。/// <summary>
    /// 从资源中读取文件内容
    /// </summary>
    /// <param name="Name">文件名</param>
    /// <returns></returns>
    private  string GetSql(string Name) 

    Assembly Asm = Assembly.GetExecutingAssembly(); 
    Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "."+Name); 
    StreamReader reader = new StreamReader(strm,System.Text.Encoding.Default); 
    return reader.ReadToEnd()