I'm using vb.net, and I can't figure out how to code a picturebox that I create in the code.
Asked
Active
Viewed 1,097 times
-1
-
Can you please supply more information? What are you stuck on? What have you tried? – Arion Feb 23 '12 at 16:18
-
I know how to create a picturebox already, I just want to program it. – Mitchell Feb 24 '12 at 13:04
-
For example, if I was to create a button in code, how would I determine what that button does? – Mitchell Feb 24 '12 at 13:05
2 Answers
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