簡體   English   中英

應用程序無法在Visual Studio 2010設計器中找到資源文件

[英]Application cannot locate resource file in Visual Studio 2010 designer

我制作了一個包含PictureBox的自定義用戶控件,該控件從資源文件夾渲染PNG圖像:

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
    //Overlay with the shape of well
    Image transparentImg = Image.FromFile("..\\..\\Resources\\reservoir_img.png");
    e.Graphics.DrawImage(transparentImg, new Point(0, 0));  
}

當我構建並運行該應用程序時,用戶控件的paint方法可以很好地渲染PNG(路徑必須正確),但是當我在Visual Studio 2010中預覽表單設計器時,它不會渲染。 它僅顯示異常:

FileNotFoundException

我可以開發和測試我的應用程序,但是當您只看到異常文本時,設計表單會很煩人。

解決方案是使用resources.resx文件:

e.Graphics.DrawImage(WindowsFormsApplication1.Properties.Resources.reservoir_img, new Point(0, 0));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM