问题
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