3
Answers

display images from picturebox one at a time

Ron

Ron

14y
8.2k
1

Hello
I have been working on this problem for awhile, I finally got my binary images to load into a picturebox, the user will select from a  combobox and then that selection will pull a picture or pictures from a category, the problem I am having is if the category has more then one picture it will go through the row count and the last count will show the picture. I would like to have the first picture displayed and then when the user is through looking can click a button and the next picture  will show and so on, I can't seem to bind the picturebox or trying to use bindingmanager base , here is my code I have
public
void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedItem.ToString() != "")
{
string instrPic = comboBox1.SelectedItem.ToString();
SqlConnection roy1 = new SqlConnection(@"server=CAPTSISKO-PC\SQLEXPRESS;Initial Catalog=cable;Integrated Security=True");
roy1.Open();
string newPic = "Select * from guidePic WHERE picTitle = '" + instrPic + "'";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(newPic, roy1);
//_guidePic = BindingContext[da, "Pic"];
da.Fill(ds,
"newPic");
ArrayList imagelist = new ArrayList();
int i = 0;
foreach (DataRow dataRow in ds.Tables["newPic"].Rows)
{
Byte[] byteRoy = new Byte[0];
DataRow myRow;
myRow = ds.Tables[
"newPic"].Rows[1];
byteRoy = (
byte[])myRow["Pic"];
MemoryStream stimRoy = new MemoryStream(byteRoy);
// pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
int originalW = Image.FromStream(stimRoy).Width;
int orignalH = Image.FromStream(stimRoy).Height;
int resizedW = (int)(originalW * .370);
int resizedH = (int)(orignalH * .370);
Bitmap bmp = new Bitmap(resizedW, resizedH);
Graphics graphic = Graphics.FromImage((Image)bmp);
graphic.DrawImage(
Image.FromStream(stimRoy), 0, 0, resizedW, resizedH);
graphic.Dispose();
bmp.RotateFlip(
RotateFlipType.Rotate90FlipNone);
bmp.Save(
"RoyNew");
PictureBox PictureBox2 = new PictureBox();
PictureBox2.Name =
string.Format("pictureBox{0}", i.ToString());
// PictureBox2.Image = ((Image)bmp);
pictureBox1.Image = ((
Image)bmp);
imagelist.Add(PictureBox2);
i++;






}
roy1.Close();
 
I have some other code in there where I tried to create a picturebox array but that is not working, I tried bindingsource also  but apparently when I click the button that will not work.
any suggestions

Answers (3)