+ Reply to Thread
Results 1 to 3 of 3

Thread: Show an image in another form

  1. #1

    Show an image in another form

    Hi , i have created a thumbnail application that import pictures from a folder and view them as thumbnails , so i`d
    like to add a feature where whenever i click on any image a new form pop up shows the picture in a bigger view.
    So i was wondering how could i do so ? as i don`t know much about transfering data between forms.

  2. #2
    Okay so do the following :
    1- Create a new form and insert a picturebox and dock it in the middle so it would fill the form.
    2- On the first form whenever you create a picture just add TAG to it and the TAG`s value would be the image path
    So for example :
    picturebox.Tag = Img_path;
    3- Now head to the second form and add the following lines :
            string img_path = "";
            public Form2(string path)
    			// so the img_path will equal to the given parameter path from form1
                img_path = path;
            private void Form2_Load(object sender, EventArgs e)
                pictureBox1.BackgroundImage = Image.FromFile(img_path);
                pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
                this.Text = Path.GetFileName(img_path); // so that the form name could be the image name.
    4- Now on form1 add the following Method :
            private void Bigger_View(object sender, EventArgs e)
                var pb = sender as PictureBox;
                if (pb != null)
                    Form2 f2 = new Form2(pb.Tag.ToString());
    And make sure that whenever you are creating pictureboxes for thumbnail that you added :
    picturebox.Click += new EventHandler(Pop_Up); // Where Pop_Up is our custom event handler
    So finally you will be able to :
    - Click on image and it will pop up a new form shows the image on a bigger view
    - Once you click on image form1 will be hidden and form2 will be shown
    - Once you close form2 , form1 will show up again.

  3. #3

    Show an image in another form

    An reference to an object with the image can be passed to another class. When that happens could be controlled by a button with a listener.

+ Reply to Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts