【发布时间】:2017-03-07 17:45:44
【问题描述】:
我有一个带有 sqlite 数据库的项目。 我将图像保存在文件夹“pics”中(进入调试文件夹)和它们的名称在数据库中(列“docpic”)。 当我连续单击时,相关图像名称位于 label10.text .. 通过点击label10我如何通过Windows Photo Viewer打开图像??
【问题讨论】:
-
Process.Start
我有一个带有 sqlite 数据库的项目。 我将图像保存在文件夹“pics”中(进入调试文件夹)和它们的名称在数据库中(列“docpic”)。 当我连续单击时,相关图像名称位于 label10.text .. 通过点击label10我如何通过Windows Photo Viewer打开图像??
【问题讨论】:
Process.Start
在属性中添加事件处理程序Click
或者在表单构造函数中手动添加监听器到标签
label10.Click += LoadImage;
和写方法
string ImagePath = @"c:\ImagesPath\";
private void LoadImage(object sender, EventArgs e)
{
// cast sender to label so we can get access to it properties
var label = (Label)sender;
// compose path from folder path and image name
var imgPath = ImagePath+label.Text;
//Load image
}
附言如何找到相对路径: 让我们想象一下你有这种文件夹结构
/Project
/Bin
/Debug
THIS_IS_YOUR.EXE
/Images
Image1.jpg
Image2.jpg
/Obj
/Properties
那么文件夹的路径就是
string dirPath = @"../Images/";
欲了解更多信息,请访问https://en.wikipedia.org/wiki/Cd_(command)
【讨论】:
exe file 和pic folder,那么只需pic//。