如何通过点击标签c#打开图像(图像名称是在sqlite数据库中)?

时间:2017-03-07 06:15:14

标签: c# image sqlite label

我有一个带有sqlite数据库的项目。 我将图像保存在文件夹中#34;照片" (进入调试文件夹)&他们在数据库中的名字(列" docpic")。 当我单击一行时,相关的图像名称为label10.text .. 通过单击label10我如何通过Windows Photo Viewer打开图像?

1 个答案:

答案 0 :(得分:0)

在属性中,在事件Click上添加eventHandler 或者通过表单构造函数将监听器添加到标签

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
}

P.S。如何找到相对路径: 让你拥有这种文件夹结构的成像

/Project
    /Bin
        /Debug
            THIS_IS_YOUR.EXE
        /Images
            Image1.jpg
            Image2.jpg            
    /Obj
    /Properties

然后文件夹的路径为

string dirPath = @"../Images/";

有关详细信息,请访问https://en.wikipedia.org/wiki/Cd_(command)