欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Winform在DataGridView中顯示圖片

 更新時間:2016年05月30日 11:51:57   作者:秦風  
本文主要介紹在DataGridView如何顯示圖片,簡單實用,需要的朋友可以參考下。

首先,要添加圖片列,綁定數(shù)據(jù)的時候會觸發(fā)CellFormatting事件,在事件中取出圖片路徑,讀取圖片賦值給當前單元格。

private void dataGridview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
  if (dataGridview1.Columns[e.ColumnIndex].Name.Equals("Image"))
  {
    string path = e.Value.ToString();
    e.Value = GetImage(path);
  }
}
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;

} 

以上就是DataGridView如何顯示圖片一些代碼片段,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論