装订图片框

时间:2014-04-08 13:17:02

标签: c# winforms ado.net

我想知道我们是否可以绑定一个图片框作为这个例子:

Binding b = new Binding("Image", dataset, "Timage.imagee");
pictureBox1.DataBindings.Add(b);

1 个答案:

答案 0 :(得分:0)

尝试使用Binding对象的Format事件:

Binding b = new Binding("Image", dataset, "Timage.imagee", true);
b.Format += picFormat;
pictureBox1.DataBindings.Add(b);

private void pic_Format(object sender, ConvertEventArgs e)
{
  Bitmap bmp = null;
  byte[] img = (byte[])e.Value;
  using (MemoryStream ms = new MemoryStream()) {
    ms.Write(img, 0, img.Length);
    bmp = new Bitmap(ms);
  }
  if (bmp != null) {
    e.Value = bmp;
  }
}