如何在Windows应用程序中使用路径 [英] how to take path in Windows application

查看:90
本文介绍了如何在Windows应用程序中使用路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是Windows应用程序的新手,并且已经创建了一个Windows应用程序.在此,我想显示项目中img文件夹中的图像.现在如何从img文件夹中获取图像?我尝试使用"Application.ExecutablePath",但它采用的是bin \ Debug目录的路径.我将img文件夹放在bin \ Debug文件夹中,但是当我创建安装项目并将其安装到计算机中时,它无法正常工作.

请告诉我如何使用C#在Windows应用程序中获取img文件夹的路径?

谢谢与问候,
Yogesh

Hello everyone,

I am new in windows application and I have created one windows application. In this I want to show images from img folder which is in my project. Now how can I get the images from img folder? I tried with "Application.ExecutablePath", but it is taking path of bin\Debug directory. I put my img folder in bin\Debug folder but when I create a setup project and install it in my computer its not working.

Please tell me how can I take the path of the img folder in windows application using C#?

Thanks & Regards,
Yogesh

推荐答案

这是我对一个非常类似的问题的详细解答:
Here is my detailed answer to a very similar question: how to get image in picturebox from existing Solution explorer Folder in windows application[^].

—SA


u使用此行
u use this line
string path =System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
to get application path
& in the start of application check if your image folder is not exists create it
if (!Directory.Exists(path + @"\Images"))
{
Directory.CreateDirectory(path+ @"\Images");
}


因此,当您创建u安装项目时没问题
每次您打开解决方案时,它都会检查文件夹路径


so when you creat u setup project no problem
every time u open your solution it check for folder path


Public Function App_Path() As String
     Return System.AppDomain.CurrentDomain.BaseDirectory()
 End Function


这篇关于如何在Windows应用程序中使用路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆