void SetImage(DpCell cell, string strFileName) { if (this.dpTable_items.InvokeRequired) { this.Invoke(new Action <DpCell, string>(SetImage), cell, strFileName); return; } cell.OwnerDraw = true; ImageCellInfo info = new ImageCellInfo(); info.FileName = strFileName; cell.Tag = info; cell.Text = ""; // 迫使刷新 }
void SetImage(DpCell cell, string strFileName) { if (this.dpTable_browseLines.InvokeRequired) { this.Invoke(new Action<DpCell, string>(SetImage), cell, strFileName); return; } cell.OwnerDraw = true; ImageCellInfo info = new ImageCellInfo(); info.FileName = strFileName; cell.Tag = info; cell.Text = ""; // 迫使刷新 }
private void dpTable_items_PaintRegion(object sender, PaintRegionArgs e) { if (e.Action == "query") { // 测算图像高度 DpCell cell = e.Item as DpCell; // DpRow row = cell.Container; ImageCellInfo cell_info = (ImageCellInfo)cell.Tag; // string strFileName = (string)cell.Tag; if (cell_info == null || string.IsNullOrEmpty(cell_info.FileName) == true) { e.Height = 0; } else { try { using (Stream s = File.Open(cell_info.FileName, FileMode.Open)) { using (Image image = Image.FromStream(s)) { e.Height = image.Height; } } } catch (Exception ex) { // throw new Exception("read image error:" + ex.Message); if (cell_info.RetryCount < 5) { cell_info.RetryCount++; DpRow row = cell.Container; AddTraceItem(row); } else { e.Height = 0; cell.OwnerDraw = false; cell.Text = "read image error"; } return; } if (this.dpTable_items.MaxTextHeight < e.Height) { this.dpTable_items.MaxTextHeight = e.Height; } } return; } { Debug.Assert(e.Action == "paint", ""); DpCell cell = e.Item as DpCell; ImageCellInfo cell_info = (ImageCellInfo)cell.Tag; // string strFileName = (string)cell.Tag; if (cell_info != null && string.IsNullOrEmpty(cell_info.FileName) == false) { try { using (Stream s = File.Open(cell_info.FileName, FileMode.Open)) { using (Image image = Image.FromStream(s)) { // 绘制图像 e.pe.Graphics.DrawImage(image, (float)e.X, (float)e.Y); } } } catch (Exception ex) { // throw new Exception("read image error:" + ex.Message); if (cell_info.RetryCount < 5) { cell_info.RetryCount++; DpRow row = cell.Container; AddTraceItem(row); } else { cell.OwnerDraw = false; cell.Text = "read image error"; } } } else { // 绘制文字“正在加载” } } }