Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想WinForms根据结果更改图像。
WinForms
if(x == true) { // Show image 1 else { // show image 2
我看到我可以使用Image.Fromfile("Image path"). 但我必须使用类似这样的图像路径@"C:\test\test1.jpg"。
Image.Fromfile("Image path")
@"C:\test\test1.jpg"
那么,有什么方法可以提供动态文件路径吗?
例如,如果我从另一台计算机打开项目,则此文件路径可能会更改。
谢谢!
如果您使用的是 PictureBox 控件,请使用路径设置 ImageLocation 属性,例如:
pictureBox1.ImageLocation = @"C:\test\test1.jpg"