-1

I'm using vb.net, and I can't figure out how to code a picturebox that I create in the code.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Mitchell
  • 1
  • 1
  • 1
  • 2

2 Answers2

3

Create a instance of PictureBox Class and Set the properties, events as per you requirement.

follow this SO thread: C#, dynamically creating picture boxes? and the Picture class documentation link to understand the properties and the events.

For example:

Dim WithEvents PictureBox1 As PictureBox

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    PictureBox1.Location = New Point(16, 48)
    PictureBox1.Text = "RadioButton3"
    PictureBox1.Size = New Size(120, 20)
    PictureBox1.Image = _
        Image.FromFile("c:\vbnet\ch07\pictureboxes\image.jpg")
    Me.Controls.Add(PictureBox1)  
End Sub
Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
0

Try this:

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim pic As New PictureBox
    With pic
        .Name = "pic1"
        .Size = New Size(250, 250)
        .Location = New Point(50, 50)
        .SizeMode = PictureBoxSizeMode.StretchImage
        .Image = Image.FromFile("C:\flower.jpg")
    End With
    Me.Controls.Add(pic)
End Sub
OGHaza
  • 4,795
  • 7
  • 23
  • 29
Amen Ayach
  • 4,288
  • 1
  • 23
  • 23