日期:2014-05-19  浏览次数:21046 次

相对路径怎么获得?怎么引用相对路径下的资源
我的程序和图片资源不在同一个目录下,但是我生成.exe文件,想在别机子上用,图片不会出现
我想在别的机子运行程序,图片也能出现,应该用相对路径,相对路径怎么获得?该怎么写?在这样加载自己的图片资源??


比如用Application.StartPath来得到当前程序的运行路径,具体相对路径怎么得到?用这个路径来找到你的图片的路径,比如:

string   imgPath   =   Application.StartPath   +   @ "\image ";
更具体的怎么写?


------解决方案--------------------
您将您的图片放到项目中的BIN目录下的DEBUG目录
然后再用您的语句:string strPath=Application.StartPath+ "\\image ";
然后再您的构造函数中进行加载:
Image imgTest;
Private Point[] imgTestBounds;
public Form1()
{
InitializeComponent();
imgTest=Image.FromFile(strPath);
this.AutoScrollMinSize=imgTest.Size;
/*定义窗体上加载图片的三个点*/
imaTestBounds=new Point[3];
imgTestBounds[1]=new Point(20,20); //起始点
imgTestBounds[2]=new Point(imgTest.Width,20); //宽度
imgTestBounds[3]=new Point(20,imgTest.Height); //长度
}