为已发布的应用程序设置ImageLocation [英] Setting ImageLocation For A Published App
问题描述
嘿伙计,
我在运行时通过这样做设置PictureBox的ImageLocation属性:
I'm setting the ImageLocation property of a PictureBox at runtime by doing this:
myPictureBox.ImageLocation =" .. \\..\\ images \\ MyPicture.jpg";
myPictureBox.ImageLocation = "..\\..\\Images\\MyPicture.jpg";
或  ;
myPictureBox.ImageLocation =" ../../ Images / MyPicture.jpg";
myPictureBox.ImageLocation = "../../Images/MyPicture.jpg";
效果很好! 但是,一旦我通过ClickOnce发布应用程序并运行已发布的版本,我会在图片框中看到一个红色X,暗示它无法找到图像。 奇怪的是,如果我通过xaml执行它,它可以在已发布的
版本和调试版本中运行,但是在路径中只有一个.. \\。 当我在后面的代码中执行此操作时没有这样的运气。
Works well! However, once I publish the application through ClickOnce and I run the published version, I get a red X in the picture box implying it can't find the image. Strangely enough, if I do it through xaml it works in both the published version and the debugging version, however there is one less ..\\ in the path. No such luck when I do it in the code behind though.
如何在ClickOnce发布的应用程序的代码中设置ImageLocation?
How do I set the ImageLocation in code for a ClickOnce published app?
(注意: 图像是解决方案的一部分。 它的属性设置为资源并且不复制)
(note: The image is apart of the solution. It's properties are set to Resource and Do Not Copy)
谢谢!
推荐答案
您好,
在Project Property中添加图片 - >资源。
Add your image in Project Property -> Resources.
然后调用
myPicture.Image = my.settings.resources.ImageName
myPicture.Image=my.settings.resources.ImageName
然后发表........
and then publish........
这篇关于为已发布的应用程序设置ImageLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!