2013-07-10 58 views
1

我有問題的圖像,我已經創造了我稱爲gridBg.png應用背景,我已經以這種方式閱讀:麻煩背景

 string currentDir = Directory.GetCurrentDirectory(); 

     if (File.Exists((currentDir + @"/Images/gridBg.png"))) 
     { 
      bgAnimated.StopAnimation(); 
      bgAnimated.GifSource = currentDir + @"/Images/gridBg.png"; 
      bgAnimated.NormalLoopFrameCount = 20; 
      bgAnimated.SpecialLoopFrameCount = 20; 
      bgAnimated.TotalLoopFrameCount = 40; 
      bgAnimated.NormalLoopRepeatCount = 1; 
      bgAnimated.SpecialLoopRepeatCount = 1; 
      bgAnimated.StartAnimation(); 
     } 

在調試模式下,它的所有工作正常。我已經在安裝項目中添加了圖像,並且已經給了它圖像路徑。當我安裝並嘗試應用程序時,它也能正常工作,但問題是我的一些朋友沒有看到圖像,但圖像位於正確的位置,即Images文件夾。任何人都有建議?

SOLVED:string currentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly()。Location);

+0

當前工作目錄你說的'形象的意思是在右邊place'?圖像是否顯示,但座標不同?或者他們甚至沒有被顯示? – Shaharyar

+0

@Shaharyar,如果你看過他的問題 - 他朋友的機器上沒有圖像。 –

+0

@ Moo-Juice你是對的!一點誤會。 – Shaharyar

回答

2

我甚至可以想到會發生這種情況的唯一方法是Working Directory,因爲您的朋友沒有設置爲安裝目錄。這會導致currentDir錯誤。

MSDN documentationGetCurrentDirectory做到這一點:

獲取應用程序

+0

+1,我的想法正好。也許'Assembly.GetExecutingAssembly()。Location'是爲了? –

+0

@ Moo-Juice,這是一種可能的解決方法。我想知道,「工作目錄」是如何設置錯誤的?也許他們的捷徑有問題? –

+0

不確定,因爲我們沒有訪問/信息的OPs朋友電腦。但是,如果我引用一些資源,相對於我的可執行文件,我總是使用執行位置,所以我不必擔心這種情況。 –