Csharp/C#教程:从Windows窗体中的相对路径加载图像分享


从Windows窗体中的相对路径加载图像

我的应用程序中有一个图像,我的winforms中有一张图片

public static string Correct_Icons = @"C:UsersxyzDocumentsVisual Studio 2008ProjectsFileShareMgmtFileShareMgmtResourcesCorrect.png"; public static string warning_Icon = @"C:UsersxyzDocumentsVisual Studio 2008ProjectsFileShareMgmtFileShareMgmtResourcesWarning.png"; cell.Value = Image.FromFile("Resources/warning_Icon); 

但我只想要相对路径,而不是完整路径。

我想要这个

 public static string Correct_Icons = "ResourcesCorrect.png"; 

和 …. /不工作

对于我的程序, Path.GetDirectoryName (Assembly.GetExecutingAssembly().Location)返回C:codetestJunkbinDebug

 cell.Value = Image.FromFile( Path.Combine ( Path.GetDirectoryName (Assembly.GetExecutingAssembly().Location), "Resources/warning_Icon")); 

当然,通常您会将资源嵌入到程序集中,除非您想在不重新编译的情况下更改它们。

在此解决方案之后我的问题得到解决

上述就是C#学习教程:从Windows窗体中的相对路径加载图像分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 string[] s = { "\bin" }; string path = Application.StartupPath.Split(s, StringSplitOptions.None)[0] + "\Images\On24.png"; 

www.ctvol.com true Article Csharp/C#教程:从Windows窗体中的相对路径加载图像分享

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/992290.html

(0)
上一篇 2021年12月24日 下午4:44
下一篇 2021年12月24日 下午4:45

精彩推荐