Start New Discussion within our Software Development Community

I'm stumped right now, I cannot figure out how to code something to get information from another form.

This is what I'm trying to do:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "01" Then 'TextBox1 is in form 2.
            PictureBox1.Image = System.Drawing.Bitmap.FromFile(My.Application.Info.DirectoryPath & "\Image00001.png") 'PictureBox1 is in form 1.
        ElseIf TextBox1.Text = "02" Then 'TextBox1 is in form 2.
            PictureBox1.Image = System.Drawing.Bitmap.FromFile(My.Application.Info.DirectoryPath & "\Image00002.png") 'PictureBox1 is in form 1.
        End If
    End Sub

When I use that code, it tells me that PictureBox1 is not declared, it's because it's not in the same form as TextBox1 and the button.

I know it's probably extremely simple, but I just can't figure it out.

Hi
Was one of the forms called (or created) in the other?
for example

dim f as new form1
f.show()

If yes, then the "parent" form can access the other forms controls by prefacing it with the form name for example

f.PictureBox1

It should appear in intellisense.
Otherwise you could create a public variable on the form and then assign the value to it through that.
Hope that helps.

This question has already been answered. Start a new discussion instead.