D
doug
I’m using VSTO 2005 to add some code to an Excel worksheet that allows the
user to click a button and select an image file to display in a picturebox
control. It seems successful, but when I save/close/reopen the worksheet,
the image displays briefly, then goes blank. Also, after saving the file
with an image it does increase the file size, so it appears that it is
embedded in the file.
Can someone tell my why the image disappears and/or what I need to do to
make the image persist???
Thanks.
Here is my code:
private void cmdInsertPicture_Click(object sender, EventArgs e)
{
string strImgFileFormat = "Image Files (*.bmp; *.jpg)|*.bmp;
*.jpg|Windows Bitmap (*.bmp)|*.bmp|JPEG File Interchange Format
(*.jpg)|*.jpg|All files (*.*)|*.*";
this.openFileDialog1.Filter = strImgFileFormat;
this.openFileDialog1.FileName = "";
this.openFileDialog1.InitialDirectory = Globals.ThisWorkbook.Path;
this.openFileDialog1.ShowDialog();
try
{
this.pictureBox1.Locked = false;
this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
// this.pictureBox1.Load(openFileDialog1.FileName); //both
methods work…
this.pictureBox1.Height = 275;
this.pictureBox1.Width = 275;
this.pictureBox1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show("An image must be selected");
}
}
user to click a button and select an image file to display in a picturebox
control. It seems successful, but when I save/close/reopen the worksheet,
the image displays briefly, then goes blank. Also, after saving the file
with an image it does increase the file size, so it appears that it is
embedded in the file.
Can someone tell my why the image disappears and/or what I need to do to
make the image persist???
Thanks.
Here is my code:
private void cmdInsertPicture_Click(object sender, EventArgs e)
{
string strImgFileFormat = "Image Files (*.bmp; *.jpg)|*.bmp;
*.jpg|Windows Bitmap (*.bmp)|*.bmp|JPEG File Interchange Format
(*.jpg)|*.jpg|All files (*.*)|*.*";
this.openFileDialog1.Filter = strImgFileFormat;
this.openFileDialog1.FileName = "";
this.openFileDialog1.InitialDirectory = Globals.ThisWorkbook.Path;
this.openFileDialog1.ShowDialog();
try
{
this.pictureBox1.Locked = false;
this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
// this.pictureBox1.Load(openFileDialog1.FileName); //both
methods work…
this.pictureBox1.Height = 275;
this.pictureBox1.Width = 275;
this.pictureBox1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show("An image must be selected");
}
}