Solved

picturebox control in c#

Posted on 2004-10-16
9
5,303 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET HttpWebRequest 12 55
How to LOAD up a .NET Framework website with data? 2 39
Not showing JavaScript in the list 5 32
Filename to be appended with DateTimeof Download 3 40
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
A short film showing how OnPage and Connectwise integration works.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

947 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

18 Experts available now in Live!

Get 1:1 Help Now