C#(winform)窗体展示图片

成品展示

概述:点击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;
		}
}

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值