'popup window to display image vb.net

I'm trying to do something in VB.net but not succeeding. I have a linklabel on a form which when a user clicks it will need to display a pop up window with an image.

Can anyone help me with this please?

I have the following code but it only displays the popup form and the image is displayed on the main form of where the linklabel is and not in the popup form.

Dim Obj As New Form
Obj.Show()

PictureBox1.Image = Image.FromFile("d:\testImage.jpg")


Solution 1:[1]

What you have to do is to add a pictureBox in the popup form (PictureBox1) Then:

Dim Obj As New Form
Obj.PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
Obj.Show()

Solution 2:[2]

Assuming that you already have designed a form (let's call it Form2) and this form has a picturebox inside it, then:

You need to load the image before loading the pop up window to the user Also make sure the pop-up window shows modaly to avoid confusion that may arise by the window being loaded but behind the parent form that loaded it.

Dim Obj As New Form2    'You need to specify the form name that you have already designed.
Obj.PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
Obj.ShowDialog()  'ShowDialog will force the user to close the form first before 
                 'coming back to the original form

Solution 3:[3]

right click your project. Then add new form. Name it form2 then on that form drop a picture box. Now for simple how-to on your form1 add a button.. Double click the button so you get the click event. In the code you will enter:

  Dim myForm2 As New Form2
  myForm2.PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
  myForm2.showDialog
  'Any actions after the user returns would be here
  myForm2.dispose()

myForm2 is a new instance of your Form2. Note Form2 is the name that you have assigned to form2 under form2 property window.

To add a new form to your project.. Right click your project name in solution explorer. Then ADD. Then windows form... Name it Form2.vb.

After that go to the design view for form2 and drop a picture box on the form... Then go to form1 and use the above code on a button click event to see it work..

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nianios
Solution 2
Solution 3