繁体   English   中英

我怎样才能使图像路径更短

[英]How can I make shorter imagepath

我试图在按下按钮时更改imagebox图片。

if (label1.Text=="1")
{
    pictureBox1.Image=Image.FromFile("C:/Users/Usr/Documents/Visual Studio 2010/Projects/randomly/randomly/Resources/dice1.jpg");
} 

如何缩短图像路径?

要嵌入资源并按如下方式访问它:

pictureBox1.Image = Resources.dice;

要获得位于程序运行目录的图片,请执行以下操作:

string pathToProgramDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
string pathToPicture = Path.Combine(pathToProgramDirectory, "dice1.jpg");
pictureBox1.Image = Image.FromFile(pathToPicture);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM