Skip to content

Picturebox problem

jorge Rodrigues

Asked Aug 4, 2006, 1:20 PM EDT1 answer
Share
LinkedInX

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

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    should be fine.

    Just tried it myself.  I don't think you need to refresh.  Here is the code i used:

    C#
    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");
      }
    
    }
    }
    }
    0