473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 1373
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Vishnu | last post by:
I have a strange problem on WindowsXP proffessional with IE6 ,when i try to display a tiff file ,it is not showing ,small red x is comming up. I tried by dowloading latest IE from microsoft but...
2
by: c.anandkumar | last post by:
Hi All - I have some problems getting a small piece of javascript working correctly for Firefox. Here is what I am trying to do - 1. I have a form (like a search form) 2. I have many groups...
3
by: Brian Henry | last post by:
Is there anyway to prevent the white box that drops down when you do a combobox dropdown from showing? I am trying to make a custom combobox which requires showing a custom form in its place, but...
1
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems...
0
by: ikhan | last post by:
Hello, I am using an activex control on my website. It was running fine with framework 1.1, when I try to run it on framework 2.0 it's not showing up. It's not showing any error message, just a...
10
by: bessington | last post by:
hey all, i'm having a rather bizarre problem.. the image tag i have declared in my xhtml is not showing in safari / konqueror but showing just fine in Firefox, IE, Opera... this is a complete...
15
missinglinq
by: missinglinq | last post by:
I'd like to use acCmdAppMinimize with two forms on the screen at once. Currently, if I have a form opening the db (with DoCmd.Maximize in the OnLoad event) and then a popup form on top of the first...
3
by: Torben Laursen | last post by:
I have a COM shared add-in written in C# that I use in Excel. One of the thinks that the user can do is to open some winforms. The problem that I have is that the first time the user opens a...
6
by: ajk | last post by:
Hi I was wondering how to show different properties in design and run-mode for a user control? Is it possible to do this when implementing the System.ComponentModel.ICustomTypeDescriptor...
6
by: painkiller | last post by:
language: vb.net environment: windows forms .net : v1.1 i am having a checkedlistbox control that display document category such as text, image, video, audio etc. these values are coming from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.