Binding Picture box

天大地大妈咪最大 提交于 2019-12-25 02:47:14

问题


I want to know if we can bind a picturebox as this example :

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

回答1:


Try using the Format event of the Binding object:

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;
  }
}


来源:https://stackoverflow.com/questions/22938274/binding-picture-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!