2

I'm sure there is someone out there who can explain this clearly.

I would have assumed that I could simply use:

Dim pb As PictureBox

then I could use

pb = New PictureBox

but apparently not.

I would also assume I can set parameters

pb.Width
pb.Height
pb.Top
pb.Left

etc.

If anyone can help me create a picture box dynamically where I can set the properties I would be so grateful, thanks.

I'm also sorry if this question has already been asked, but I have been looking for a few hours now and nothing has worked for me.

5
  • 2
    In what way doesn't this work? That is exactly how you create a picture box. Commented Jun 5, 2014 at 13:09
  • WozzecC is correct, that is how i do it aswell. And if it doesn't work. Could you at least give the errormessage? Commented Jun 5, 2014 at 13:10
  • 1
    possible duplicate of How to programmatically add controls to a form in VB.NET Commented Jun 5, 2014 at 13:21
  • And just to make sure... are you adding the picturebox somewhere that you can see it after you declare it and set it's properties? And is the code firing at all (put a stop on it and see if your processing hits it)? Commented Jun 5, 2014 at 13:57
  • Also, are you setting one of the pictureBox's Image properties? Without that, you can add it all you want, but you probably won't see it during runtime. Commented Jun 5, 2014 at 13:58

1 Answer 1

3

In other words, you are trying to add a control to a windows form programmatically. Of course I don't know what you have tried, but I would use:

Dim pb As New PictureBox
pb.Width = 100 'or whatever
pb.Height = 200
pb.Top = 50 'or whatever
pb.Left = 50
pb.ImageLocation = "dog.png"
Me.Controls.Add(pb)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.