Solved

picturebox control in c#

Posted on 2004-10-16
9
5,301 Views
Last Modified: 2011-08-18
Hi,

I have a form with a picturebox control, i select a picture and display it in it,then i hide this form and then show it.....when i do this the picturebox no longer shows the picture....!
now how do i get the picturebox control to still display the picture after hide and show of  the form?

thanks
0
Comment
Question by:srao0
9 Comments
 
LVL 4

Expert Comment

by:Farshid-Zaker
ID: 12329773
I tried to simulate this condition on my machine. But I did not succeeded and picture box always shows the picture! Please provide more information.

Farshid
0
 
LVL 3

Expert Comment

by:aacool
ID: 12330381
please provide the code that is used to load the image, hide and show the form
0
 
LVL 6

Expert Comment

by:prasitlee
ID: 12330600
Yes just post sample code. It would be easier for us to check what 's wrong in your code.
                                                               Meng
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 12331118
change the property AutoRedraw of forms and picturebox to true.

-FA
0
 

Author Comment

by:srao0
ID: 12335118
heres the code, button 1 and 2 are on form 1 and they select the picture to display and then hide the form 1, and display form 2, form 2 then returns the path of a new picture which form1 should display, the code works if i comment this.Hide() ie form 1 hide, but doesnt display new picture if i have the Hide()


private void button1_Click(object sender, System.EventArgs e)
            {
                  OpenFileDialog openFileDialog = new OpenFileDialog();

                  openFileDialog.Filter = "Picture Files|*.jpg;";
                  openFileDialog.InitialDirectory = @"C:\" ;
                  if(openFileDialog.ShowDialog() == DialogResult.OK)
                  {
                        picfile = openFileDialog.FileName ;
                  }
                  pictureBox1.Image = Image.FromFile(picfile) ;
            }

private void button2_Click(object sender, System.EventArgs e)
            {
                        form2.Show();
                  this.Hide();
            }

//this function gets the file to display
private void PassData(string s)
            {
                  pictureBox1.Image = Image.FromFile(s) ;
            }

now if i comment out this.Hide(), then the picturebox displays the image but if i have it then it doesnt
0
 
LVL 3

Accepted Solution

by:
aacool earned 200 total points
ID: 12352258
Put your image loading code in the Load event for the form as well.

Basically in your form class

class WinForm
{
    Image m_img //store the picturebox image when opening the image
    bool isImg = false; // set to true when first loading the image

private void WinForm_Load(object sender, System.EventArgs e)
{
     if(isImg==true)
     {
              pictureBox1.Image = m_img;
     }
}

//modify
private void button1_Click(object sender, System.EventArgs e)
          {
               OpenFileDialog openFileDialog = new OpenFileDialog();

               openFileDialog.Filter = "Picture Files|*.jpg;";
               openFileDialog.InitialDirectory = @"C:\" ;
               if(openFileDialog.ShowDialog() == DialogResult.OK)
               {
                    picfile = openFileDialog.FileName ;
               }
               pictureBox1.Image = Image.FromFile(picfile) ;
               m_img = pictureBox1.Image;
               isImg = true;
          }

}
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now