Solved

picturebox control in c#

Posted on 2004-10-16
9
5,311 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"Emulate" TAB key when press Enter Key 3 92
Problem to Office 1 66
How to set focus on a dynamic control 18 49
Send parameters via datatable ajax call 4 43
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

732 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