locked
how can i move a picture from form 1 to form2 RRS feed

  • Question

  • good day

    i have a picture box in form 1

    and i have a picture in form 2

    how can i transfer the picture from form1 and see it on form 2?

    i am using visual basic 2010

    regards

    Monday, April 30, 2018 3:19 AM

Answers

  • Form 2: Add Public Property

    Public Property SetImage As Image
            Get
                Return PictureBoxForm2.Image
            End Get
            Set(value As Image)
                PictureBoxForm2.Image = value
            End Set
        End Property

    Form 1: Set Form 2 SetImage Property

    Form2.SetImage = PictureBoxForm1.Image

    PictureBoxForm1 is PictureBox on Form1

    PictureBoxForm2 is PictureBox on Form2



    Monday, April 30, 2018 3:35 AM
  • Hi  anglefbi,

    Just as Acamar said, your purpose depends of when you transfer the image, if it is before displaying a new form, you can use Acamar's code, if you want to transfer the image at the running time, please refer to this:

    In Form1:

    Public Class Form1
        Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
            Dim f2 As Form2 = New Form2(AddressOf ShowImage)
            f2.Show()
        End Sub
    
        Private Sub ShowImage(ByVal image As Image)
            pictureBox1.Image = image
        End Sub
    End Class

    In Form2:

    Public Class Form2
        Public Delegate Sub Del(ByVal image As Image)
        Private _del As Del
    
        Public Sub New(ByVal del As Del)
            InitializeComponent()
            Me._del = del
        End Sub
    
        Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
            _del(pictureBox1.Image)
        End Sub
    End Class

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 1, 2018 8:13 AM

All replies

  • Form 2: Add Public Property

    Public Property SetImage As Image
            Get
                Return PictureBoxForm2.Image
            End Get
            Set(value As Image)
                PictureBoxForm2.Image = value
            End Set
        End Property

    Form 1: Set Form 2 SetImage Property

    Form2.SetImage = PictureBoxForm1.Image

    PictureBoxForm1 is PictureBox on Form1

    PictureBoxForm2 is PictureBox on Form2



    Monday, April 30, 2018 3:35 AM
  • how can i transfer the picture from form1 and see it on form 2?

    That depends on what the relationship between form 1 and form 2 is, and how you want the image to be inserted

    If you are showing an instance of form 2 from code in form 1, then you can insert the image before you show the form:

    Dim frm2 as New Form2
    frm2.Picturebox1.image = me.Picturebox1.image
    frm2.Show

    If the image is updated in some other event then you just need to ensure that frm2 is declared at the form level so that all the methods in form 1 have access to it.  Note that you should check that frm2 is not nothing before attempting to update the image.

    If form 2 is being shown from some other form it becomes more complicated, because you have to somehow pass a reference to the instance of form 2 to form 1, so it can refer to the controls on form 2.

    Monday, April 30, 2018 4:57 AM
  • Hi  anglefbi,

    Just as Acamar said, your purpose depends of when you transfer the image, if it is before displaying a new form, you can use Acamar's code, if you want to transfer the image at the running time, please refer to this:

    In Form1:

    Public Class Form1
        Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
            Dim f2 As Form2 = New Form2(AddressOf ShowImage)
            f2.Show()
        End Sub
    
        Private Sub ShowImage(ByVal image As Image)
            pictureBox1.Image = image
        End Sub
    End Class

    In Form2:

    Public Class Form2
        Public Delegate Sub Del(ByVal image As Image)
        Private _del As Del
    
        Public Sub New(ByVal del As Del)
            InitializeComponent()
            Me._del = del
        End Sub
    
        Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
            _del(pictureBox1.Image)
        End Sub
    End Class

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 1, 2018 8:13 AM
  • woooow i appreciate it brother

    thank you very very much :D

    Tuesday, May 1, 2018 8:29 PM
  • thank you for your quick response 

    you are the man 

    you helped me

    thank you

    Tuesday, May 1, 2018 8:29 PM