472,127 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Showing gaphics

I'm trying to dynamically add a picturebox control to a form.

I'm following some coding I see in the form designer generated code:
....and so far....nothing. Any help is appreciated.
Dim myPicture As New PictureBox()

With myPicture

myPicture = New System.Windows.Forms.PictureBox()

..Visible = True

..Name = "NewPicture"

..Size = New System.Drawing.Size(64, 48)

'myPicture.Location.X = new System.drawing

..TabStop = False

..Location = New System.Drawing.Point(700, 300)

..Image.FromFile("c:\temp\holiday1.jpg")

..Show()

End With


Nov 20 '05 #1
22 1290
try this :
myForm.Controls.Add(myPicture)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Andy Chan" <an***********@telus.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
I'm trying to dynamically add a picturebox control to a form.

I'm following some coding I see in the form designer generated code:
...and so far....nothing. Any help is appreciated.
Dim myPicture As New PictureBox()

With myPicture

myPicture = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = "NewPicture"

.Size = New System.Drawing.Size(64, 48)

'myPicture.Location.X = new System.drawing

.TabStop = False

.Location = New System.Drawing.Point(700, 300)

.Image.FromFile("c:\temp\holiday1.jpg")

.Show()

End With

Nov 20 '05 #2
Thanks for the hint. It didn't seem to work.

I'm looking around msdn.micrsoft.com and www.devx.com. Don't suppose you'd
know of anywhere else that you'd recommend for source code? Thanks again.

"Crirus" <Cr****@datagroup.ro> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
try this :
myForm.Controls.Add(myPicture)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Andy Chan" <an***********@telus.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
I'm trying to dynamically add a picturebox control to a form.

I'm following some coding I see in the form designer generated code:
...and so far....nothing. Any help is appreciated.
Dim myPicture As New PictureBox()

With myPicture

myPicture = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = "NewPicture"

.Size = New System.Drawing.Size(64, 48)

'myPicture.Location.X = new System.drawing

.TabStop = False

.Location = New System.Drawing.Point(700, 300)

.Image.FromFile("c:\temp\holiday1.jpg")

.Show()

End With


Nov 20 '05 #3
you can try to convert this C# sample... is quite easy

http://support.microsoft.com/default...;en-us;Q319266

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Andy Chan" <an***********@telus.net> wrote in message
news:Oc*************@TK2MSFTNGP11.phx.gbl...
Thanks for the hint. It didn't seem to work.

I'm looking around msdn.micrsoft.com and www.devx.com. Don't suppose you'd
know of anywhere else that you'd recommend for source code? Thanks again.

"Crirus" <Cr****@datagroup.ro> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
try this :
myForm.Controls.Add(myPicture)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Andy Chan" <an***********@telus.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
I'm trying to dynamically add a picturebox control to a form.

I'm following some coding I see in the form designer generated code:
...and so far....nothing. Any help is appreciated.
Dim myPicture As New PictureBox()

With myPicture

myPicture = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = "NewPicture"

.Size = New System.Drawing.Size(64, 48)

'myPicture.Location.X = new System.drawing

.TabStop = False

.Location = New System.Drawing.Point(700, 300)

.Image.FromFile("c:\temp\holiday1.jpg")

.Show()

End With



Nov 20 '05 #4
As a hint: Try google with "add controls to forms at run-time NET VB", if
still cant make it work, you may find other exemples

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Crirus" <Cr****@datagroup.ro> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
try this :
myForm.Controls.Add(myPicture)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Andy Chan" <an***********@telus.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
I'm trying to dynamically add a picturebox control to a form.

I'm following some coding I see in the form designer generated code:
...and so far....nothing. Any help is appreciated.
Dim myPicture As New PictureBox()

With myPicture

myPicture = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = "NewPicture"

.Size = New System.Drawing.Size(64, 48)

'myPicture.Location.X = new System.drawing

.TabStop = False

.Location = New System.Drawing.Point(700, 300)

.Image.FromFile("c:\temp\holiday1.jpg")

.Show()

End With


Nov 20 '05 #5
LOL, there is a VB version of it but didnt sow it... silly me

http://support.microsoft.com/default...b;EN-US;308433

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Crirus" <Cr****@datagroup.ro> wrote in message
news:u%****************@tk2msftngp13.phx.gbl...
you can try to convert this C# sample... is quite easy

http://support.microsoft.com/default...;en-us;Q319266

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Andy Chan" <an***********@telus.net> wrote in message
news:Oc*************@TK2MSFTNGP11.phx.gbl...
Thanks for the hint. It didn't seem to work.

I'm looking around msdn.micrsoft.com and www.devx.com. Don't suppose you'd know of anywhere else that you'd recommend for source code? Thanks again.
"Crirus" <Cr****@datagroup.ro> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
try this :
myForm.Controls.Add(myPicture)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Andy Chan" <an***********@telus.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
> I'm trying to dynamically add a picturebox control to a form.
>
> I'm following some coding I see in the form designer generated code:
> ...and so far....nothing. Any help is appreciated.
> Dim myPicture As New PictureBox()
>
> With myPicture
>
> myPicture = New System.Windows.Forms.PictureBox()
>
> .Visible = True
>
> .Name = "NewPicture"
>
> .Size = New System.Drawing.Size(64, 48)
>
> 'myPicture.Location.X = new System.drawing
>
> .TabStop = False
>
> .Location = New System.Drawing.Point(700, 300)
>
> .Image.FromFile("c:\temp\holiday1.jpg")
>
> .Show()
>
> End With
>
>
>
>



Nov 20 '05 #6
* "Andy Chan" <an***********@telus.net> scripsit:
I'm looking around msdn.micrsoft.com and www.devx.com. Don't suppose you'd
know of anywhere else that you'd recommend for source code? Thanks again.


<http://groups.google.com>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #7
Cor
Hi Andy,
What is the size of your form

.Location = New System.Drawing.Point(700, 300)

Can it be that you paint it beside your form?

And you need in my opinion that Add that Crirus stated.

Cor
Nov 20 '05 #8
Hi Andy,

You're right to use the code that the Form Designer creates but you have
to do it carefully (like Crirus's Controls.Add) - and know which bits to do
differently - like Image.

The Designer uses embedded resources which is not what you want. You
spotted that so you used

myPicture.Image.FromFile("c:\temp\holiday1.jpg")

Unfortunately this loads an image and then throws it away because it's not
being assigned to anything. The use of myPicture doesn't mean that it updates
myPicture!

The bit that you're missing is <setting> the Image.

myPicture.Image = Image.FromFile ("c:\temp\holiday1.jpg")

Regards,
Fergus

Nov 20 '05 #9
Image.FromFile is a shared function which will return a new Image based on
the file. Being shared, it doesn't have an Image instance to load the file
into, so it won't change the Image who's reference you used to call the
function. Your code isn't assigning the returned image to the Image
property of your PictureBox.

Try replacing this line:
.Image.FromFile("c:\temp\holiday1.jpg")

With this line:
.Image = Image.FromFile("c:\temp\holiday1.jpg")

I think that your code to create and display the PictureBox is working just
fine, it just doesn't have an image to display. You do need to add the
picturebox to the form's control collection though (as mentioned in another
post).

Nov 20 '05 #10
Maybe you will consider the ideea of direct paint the image on the form
without this struggle of adding picture box only for display

Something like this:

In form's Paint event

dim myImg as new Image.fromFile(...)
e.Graphics.drawImage(myImg,....)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Andy Chan" <an***********@telus.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
I'm trying to dynamically add a picturebox control to a form.

I'm following some coding I see in the form designer generated code:
...and so far....nothing. Any help is appreciated.
Dim myPicture As New PictureBox()

With myPicture

myPicture = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = "NewPicture"

.Size = New System.Drawing.Size(64, 48)

'myPicture.Location.X = new System.drawing

.TabStop = False

.Location = New System.Drawing.Point(700, 300)

.Image.FromFile("c:\temp\holiday1.jpg")

.Show()

End With

Nov 20 '05 #11
Cor
Hi Fergus,

Good morning

Where did you been, did you sleep a night, very good.

Or was it football with all those London clubs?

:-))

Cor
Nov 20 '05 #12
Cor
Hi Fergus,

With that what Crirus now tells I was strugling yesterday.

In your example for me you use that
e.graphics.draw(master,rectangle,rectangle,size)

It was drawing direct on the screen in the place of the second picture box.
You did use the rectangle of that picture box. I found it now, but did cost
some thinking before I saw it was not placed in that picturebox.

(All is ready now I start to get it smaller and saving.
I start just with seeing if the thumbnail will work for me, and if that does
not work for me. I go search and will ask Herfried, Nick, Crirus and you
again, how I can delete some information from the pixel information. (Not
just removing pixels, that gives not nice pictures). But bringing by
instance colours back from 16Kbits to 64bits or what is more not direct
needed information for internet.

Cor

Nov 20 '05 #13
Good morning Cor,

I promised Scorpion that I'd write him a Registry Searcher so I had to
keep the modem unplugged and give myself time for it. (otherwsie - too much
temptation to answer 'just one more question'). And I still have another
couple oif things that need to be done for people. I heaped my plate high -
now I have to eat it!

Football? What's that?? ;-))

Regards
Nov 20 '05 #14
Before unplugg again the modem, will you look at my issue about mouse
cursor.. :D

please!
--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Fergus Cooney" <fi****@post.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
Good morning Cor,

I promised Scorpion that I'd write him a Registry Searcher so I had to
keep the modem unplugged and give myself time for it. (otherwsie - too much temptation to answer 'just one more question'). And I still have another
couple oif things that need to be done for people. I heaped my plate high - now I have to eat it!

Football? What's that?? ;-))

Regards

Nov 20 '05 #15
Hi Cor,

|| All is ready now I start to get it smaller and saving.

Sounds good...I look forward to seeing it.

|| But bringing by instance colours back from 16Kbits to 64bits

You'll be studying these I reckon.
Encoder Class
EncoderParameter Class
EncoderParameters Class
http://support.microsoft.com/?kbid=324788

Regards,
Fergus
Nov 20 '05 #16
Cor
Hi Fergus,

To forfill this I try to do everything in English.
Sounds good...I look forward to seeing it.


Did you know that this is an advantage normaly from non native English
language programmers on native English language programmers.

We use our own language for variables and english for keywords and defined
objects etc. And because a lot of non native English speakers send in code
parts, I'v seen here we normaly do that all.

By doing this we have never a problem to get mixed up. But now I did take
the chalenge to do it in English, so I can show you the results and I am
developing it still as a stand alone program.

Cor
Nov 20 '05 #17
Hi Cor,

|| We use our own language for variables and english for
|| keywords and defined objects etc
|| By doing this we have never a problem to get mixed up.

It's a nice advantage - much clearer separation of App from System. Also,
you get your own choice. Many's the time I'd like to use a word that has
already been taken.

But for sticking to English - thanks! ;-)

Regards,
Fergus
Nov 20 '05 #18
Hi Fergus,

Thanks for the input.

Wow. I've been doing VB 6 for sometime now. I've been behind the times and
finally sitting down to do some .NET coding. Boy, what a difference. It's
like I have to start all over again.


"Fergus Cooney" <fi****@post.com> wrote in message
news:uY*************@TK2MSFTNGP11.phx.gbl...
Hi Andy,

You're right to use the code that the Form Designer creates but you have to do it carefully (like Crirus's Controls.Add) - and know which bits to do differently - like Image.

The Designer uses embedded resources which is not what you want. You
spotted that so you used

myPicture.Image.FromFile("c:\temp\holiday1.jpg")

Unfortunately this loads an image and then throws it away because it's not being assigned to anything. The use of myPicture doesn't mean that it updates myPicture!

The bit that you're missing is <setting> the Image.

myPicture.Image = Image.FromFile ("c:\temp\holiday1.jpg")

Regards,
Fergus

Nov 20 '05 #19
SUCCESS!!!

Thanks to everyone who contributed! Hope to return the favor someday.....but
umm.....I think I've got a bit of a learning curve before I do so.

It seemed to come down to 2 things I was doing wrong:

1. mypicture.Image = Image.FromFile("c:\temp\holiday1.jpg") was definitely
it.

and

2. I was adding the the control with me.controls.add after I was trying to
set the picture. Once I moved this before the picture creation, no problem.


"Andy Chan" <an***********@telus.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
I'm trying to dynamically add a picturebox control to a form.

I'm following some coding I see in the form designer generated code:
...and so far....nothing. Any help is appreciated.
Dim myPicture As New PictureBox()

..Image = Image.FromFile("c:\blackjack\clubs3.jpg")

With myPicture
myPicture = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = "NewPicture"

.Size = New System.Drawing.Size(64, 48)

'myPicture.Location.X = new System.drawing

.TabStop = False

.Location = New System.Drawing.Point(700, 300)

.Image.FromFile("c:\temp\holiday1.jpg")

.Show()

End With

Nov 20 '05 #20
Addendum:

How would you add more than 1 image?

I've tried to add a second graphic, but it only shows the first one. I know
the coding is correct, as I can comment out the coding for the 1st picture,
and the 2nd photo shows up.


"Andy Chan" <an***********@telus.net> wrote in message
news:eq**************@tk2msftngp13.phx.gbl...
SUCCESS!!!

Thanks to everyone who contributed! Hope to return the favor someday.....but umm.....I think I've got a bit of a learning curve before I do so.

It seemed to come down to 2 things I was doing wrong:

1. mypicture.Image = Image.FromFile("c:\temp\holiday1.jpg") was definitely
it.

and

2. I was adding the the control with me.controls.add after I was trying to
set the picture. Once I moved this before the picture creation, no problem.

"Andy Chan" <an***********@telus.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
I'm trying to dynamically add a picturebox control to a form.

I'm following some coding I see in the form designer generated code:
...and so far....nothing. Any help is appreciated.
Dim myPicture As New PictureBox()

.Image = Image.FromFile("c:\blackjack\clubs3.jpg")

With myPicture

myPicture = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = "NewPicture"

.Size = New System.Drawing.Size(64, 48)

'myPicture.Location.X = new System.drawing

.TabStop = False

.Location = New System.Drawing.Point(700, 300)

.Image.FromFile("c:\temp\holiday1.jpg")

.Show()

End With


Nov 20 '05 #21
Hi Andy,

The second one should replace the first. Perhaps you should show us the latest version of the code.

Regards,
Fergus
Nov 20 '05 #22
* "Andy Chan" <an***********@telus.net> scripsit:
How would you add more than 1 image?

I've tried to add a second graphic, but it only shows the first one. I know
the coding is correct, as I can comment out the coding for the 1st picture,
and the 2nd photo shows up.


I think you solved the problem by adding a 2nd picturebox?!

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #23

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by c.anandkumar | last post: by
3 posts views Thread by Brian Henry | last post: by
reply views Thread by ikhan | last post: by
3 posts views Thread by Torben Laursen | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.