Share via


how to refresh the picture box

Question

Thursday, October 21, 2010 6:26 AM

hello all my question might be repititive but i need help .

i've a picturebox , i try open a file to obtain an image with an enter button , i've another button to refresh the picture box ,

i tried picturebox.refresh() inside the button event , it didn't work , can anybody suggest me a method  how to refresh the picture box with a button   

All replies (13)

Thursday, October 21, 2010 1:00 PM ✅Answered

<yourPictureBoxName>.Image = System.Drawing.Image.FromFile("path to file");

and i think you don't even need to use the refresh method.


Thursday, October 21, 2010 1:39 PM ✅Answered

Your complete program

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
  public partial class Form1 : Form
  {
    private Image MainImage;
    public Form1()
    {
      InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
      using (OpenFileDialog openFileDialog = new OpenFileDialog())
      {
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
          MainImage = Image.FromFile(openFileDialog.FileName);
        }
      }
    }

    private void button2_Click(object sender, EventArgs e)
    {
      pictureBox1.Image = MainImage;
    }
  }
}

Success
Cor


Thursday, October 21, 2010 6:43 AM

Hello,

 

Just set again the property for the image, PictureBox.Image = ... or any other code you call to load the image in the first place.

 

Best Regards,

Emanuel Varga

If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


Thursday, October 21, 2010 6:46 AM

Application.DoEvents 'be aware you get many messages not to use it.

If you then get code returned, watch that code if it is maintainable and works.

 

Success
Cor


Thursday, October 21, 2010 6:48 AM

well im new to programming 

how do i set the properties of the picturebox.image

wat am i supposed to put their in order to refresh the picturebox using a button 

With Regards Sriram


Thursday, October 21, 2010 6:51 AM

Where are you setting the image for the picture box initially?

Just set the same property of the picturebox on button click and it will work.

Best Regards,
Emanuel Varga

If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


Thursday, October 21, 2010 7:02 AM

@ varga and @ligthert

private void pictureBox1_Paint(object sender, PaintEventArgs e)

        {

            pictureBox1.Refresh();

        }

 

it isn't working either . may be going in a wrong direction but the problem is i've no clue of the directions 

can u plz tell me if im doing things correctly 

With Regards Sriram


Thursday, October 21, 2010 7:29 AM

Hello again ram,

 

A couple of questions, are you developing a web or desktop application?

Are you setting the original image for the picture box in the designer?

What property are you using to set the image? Image?, ImageKey?

 

Best Regards,

Emanuel Varga

If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


Tuesday, November 9, 2010 11:39 AM

i've my own solution  

this is how i did it 

PictureBox.Image=null;

With Regards Sriram


Tuesday, November 9, 2010 12:34 PM

Did you read my post?

 

This is what I've suggested in the beginning to just set the image for the picture box again.

 

Best Regards,
Emanuel Varga

If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


Wednesday, November 10, 2010 5:09 AM

okay varga i couldn't understand ur post when i  only got the solution i realised u'd already suggested the same thing

 thanks :):) 

With Regards Sriram


Saturday, April 7, 2012 11:24 AM

Ram6030

You could also try the method Update() after your refresh. This has the effect that it redraws the control and all its child controls. e.g.

PictureBox1.image = yourimageBitmap;
PictureBox1.Refresh();
PictureBox1.Update();

Hope this helps and Keep programming!


Tuesday, April 25, 2017 2:35 PM

Thanks...its working for me