Solved

picturebox control in c#

Posted on 2004-10-16
9
5,314 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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