469,621 Members | 1,853 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

PictureBox created in code not working

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.
Nov 13 '08 #1
5 5171
On Nov 13, 9:41*pm, AWW <wrote:
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
Nov 13 '08 #2
AWW
On Thu, 13 Nov 2008 12:56:30 -0800 (PST), kimiraikkonen
<ki*************@gmail.comwrote:
>On Nov 13, 9:41*pm, AWW <wrote:
>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)
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.
>Hope this helps,

Onur Güzel
Nov 14 '08 #3
AWW
On Thu, 13 Nov 2008 12:56:30 -0800 (PST), kimiraikkonen
<ki*************@gmail.comwrote:
>On Nov 13, 9:41*pm, AWW <wrote:
>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
I said that I had "Me.Controls.Add(Box)" but I did NOT.
Thank you for your help. Sorry about being so wrong.
Nov 14 '08 #4
On Thu, 13 Nov 2008 20:09:10 -0800, AWW <wrote:
>On Thu, 13 Nov 2008 12:56:30 -0800 (PST), kimiraikkonen
<ki*************@gmail.comwrote:
>>On Nov 13, 9:41*pm, AWW <wrote:
>>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
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.
Nov 14 '08 #5
On Nov 14, 6:09*am, AWW <wrote:
On Thu, 13 Nov 2008 12:56:30 -0800 (PST), kimiraikkonen

<kimiraikkone...@gmail.comwrote:
On Nov 13, 9:41*pm, AWW <wrote:
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

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
Nov 14 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by kashif mehmoof | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.