Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PictureBox visible property does not work... help please

Tags:

c#

picturebox

I am using window app and C#.. i have a picture which is invisible at the start of the app.. when some button is clicked, the picture box has to be shown..

i use this coding but the picture box is not visible

private void save_click(object sender, EventArgs e)

{

      pictureBox1.Visible = true;
      pictureBox1.Show();

      //does the work here 
      //storing and retreiving values from datadase

     pictureBox1.Visible = false;
     pictureBox1.Hide();
}

P.S... in the picture box i am showing a gif.. so the user will know that some work is going on in the background.. It will take long time for the function to finish...

like image 861
Vincent Avatar asked Dec 02 '11 12:12

Vincent


People also ask

How do you use PictureBox?

The PictureBox control is used for displaying images on the form. The Image property of the control allows you to set an image both at design time or at a runtime. Specifies whether the picture box accepts data that a user drags on it. Gets or sets the path or the URL for the image displayed in the control.


1 Answers

Assuming that the saving to the database takes some time, you should be doing it asynchronously using BackgroundWorker, hiding your PictureBox once the operation completes.

The reason that the image is not showing currently is because while your long-running save operation is occurring, Windows messages are not being processed, and so your form will be unresponsive to user input and not perform repaints. When the save operation finishes, and messages start being processed again, the picture box has already been hidden again.

like image 80
Iridium Avatar answered Sep 19 '22 01:09

Iridium