成品展示
概述:点击dgv的任意列展现出当前点击列的图片
代码:
/// <summary>
/// 图片展示方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public class SetImg
{
public List<string> GetImgsrc()
{
List<string> listImgsrc = new List<string>();
string sql = "select imge from ws";
DataTable dt = DBHelper.Select(sql);//执行查询语句,返回一个表。
foreach (DataRow row in dt.Rows)
{
listImgsrc.Add(row["imge"].ToString());//将数据一条一条的加入的list中
}
return listImgsrc;//返回这个集合
}
}
SetImg st = new SetImg();
public System.Drawing.Image GetImage(string path)
{
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
fs.Close();
return result;
}
dgv点击事件:
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo();
//processStartInfo.FileName = "explorer.exe"; //资源管理器
//processStartInfo.Arguments = db.INIhelp.GetValue("DZ", "dz") + "\\" + list[e.RowIndex];
//System.Diagnostics.Process.Start(processStartInfo);
var list = st.GetImgsrc();
pic p = new pic(db.INIhelp.GetValue("DZ", "dz") + "\\" + list[e.RowIndex]);
p.ShowDialog();
}
form2窗体:图片使用prc控件
代码:
public partial class pic : Form //窗体之间传值
{
string imgstr = string.Empty;
public pic(string s)
{
InitializeComponent();
imgstr = s;
}
private void pic_Load(object sender, EventArgs e)
{
pictureBox1.ImageLocation = imgstr;
label1.Text = imgstr;
}
}