i want to put an image to a picturebox when i click a button, the iage does not apear
this is the code i'm using:
private Bitmap MyImage ;
private void button9_Click(object sender, System.EventArgs e)
{
// Sets up an image object to be displayed.
if (MyImage != null)
{
MyImage.Dispose();
}
//openFileDialog1.ShowDialog();
MyImage = new Bitmap(@"c:\temp\print.bmp");
pictureBox1.Image = (Image) MyImage ;
pictureBox1.Refresh();
}
can someone help....
Jorge Rodrigues
Mike GoldRank #50 · 30.6K pointsPosted Aug 6, 2006, 9:23 AM EDT
Just tried it myself. I don't think you need to refresh. Here is the code i used:
using System.Drawing; using System.Text; using System.Windows.Forms; namespace TestPictureBox { public partial class Form1 : Form { public Form1() { InitializeComponent(); pictureBox1.Image = null; } private void button1_Click(object sender, EventArgs e) { if (pictureBox1.Image == null) { pictureBox1.Image = new Bitmap("test.jpg"); } } } }