PictureBox created in code not working

A

AWW

XP VB 2005 running an example from help that creates a picturebox in
code - the picturebox is not created.
If I comment out the "Dim Box as New PictureBox" and create it in
Design mode - the example works.
I have tried Show, Enabled, Visible, and even BackColor.
Why does a help example not work? and why does Design creation work?
Thanks - I hope.
 
K

kimiraikkonen

XP VB 2005 running an example from help that creates a picturebox in
code - the picturebox is not created.
 If I comment out the "Dim Box as New PictureBox" and create it in
Design mode - the example works.
I have tried Show, Enabled, Visible, and even BackColor.
Why does a help example not work? and why does Design creation work?
Thanks - I hope.

It's not much clear what you mean, but as far as i understand, you
don't see picturebox on your form, and i think that's because you
didn't add picturebox control on your form by calling "Me.Controls.Add
(Box)" and also you need to specify the location of your picturebox
based on your example which you didn't tell its code.

So, try this with assumption:

Dim Box As New PictureBox
Box.Image = Image.FromFile("c:\picture.jpg")
Box.Location = New Point(100, 100)
' Equalize picturebox size with image size
Box.Size = Box.Image.Size

' Finally add control onto form
Me.Controls.Add(Box)

Hope this helps,

Onur Güzel
 
A

AWW

It's not much clear what you mean, but as far as i understand, you
don't see picturebox on your form, and i think that's because you
didn't add picturebox control on your form by calling "Me.Controls.Add
(Box)" and also you need to specify the location of your picturebox
based on your example which you didn't tell its code.

So, try this with assumption:

Dim Box As New PictureBox
Box.Image = Image.FromFile("c:\picture.jpg")
Box.Location = New Point(100, 100)
' Equalize picturebox size with image size
Box.Size = Box.Image.Size

' Finally add control onto form
Me.Controls.Add(Box)
I am using an example from Help showing how to draw a line in a
PictureBox - so no image involved - and it did not work until I
replaced "Dim Box as New PictureBox" with a box created in Design
mode. Is that clear. Yes the "Me.Controls.Add(Box)" is there.
Basically the question is - how to create a New PictureBox in code -
not containing an image - the same way as a PictureBox is created in
Design mode. Or is that not possible? Thanks.
 
A

AWW

It's not much clear what you mean, but as far as i understand, you
don't see picturebox on your form, and i think that's because you
didn't add picturebox control on your form by calling "Me.Controls.Add
(Box)" and also you need to specify the location of your picturebox
based on your example which you didn't tell its code.

So, try this with assumption:

Dim Box As New PictureBox
Box.Image = Image.FromFile("c:\picture.jpg")
Box.Location = New Point(100, 100)
' Equalize picturebox size with image size
Box.Size = Box.Image.Size

' Finally add control onto form
Me.Controls.Add(Box)

Hope this helps,

Onur Güzel
I said that I had "Me.Controls.Add(Box)" but I did NOT.
Thank you for your help. Sorry about being so wrong.
 
J

Jack Jackson

I said that I had "Me.Controls.Add(Box)" but I did NOT.
Thank you for your help. Sorry about being so wrong.

That's why it helps if you post the code you are using.
 
K

kimiraikkonen

I said that I had "Me.Controls.Add(Box)" but I did NOT.
Thank you for your help. Sorry about being so wrong.

So, your problem was solved by adding Me.Controls.Add(Box)?. I hope
so.

Thanks,

Onur Güzel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top