?
Solved

picturebox control in c#

Posted on 2004-10-16
9
Medium Priority
?
5,323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 800 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

649 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