Welcome to Dream.In.Code
Become a VB Expert!

Join 137,232 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,824 people online right now. Registration is fast and FREE... Join Now!




creating a new picture box

 
Reply to this topicStart new topic

creating a new picture box, im am trying to make a new picture box during run time

orangeslide8
8 Feb, 2007 - 12:33 PM
Post #1

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
i was wondering if you could make a new picture box during run time or do you have to have the picture box already set and visible = false then just make it true. any help with making a new picture box would be great
thnx
john
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Creating A New Picture Box
8 Feb, 2007 - 01:41 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Yes, anything you can do in the designer can be done at runtime. Just have the code execute inside the Form Load event.

An example would be:
CODE

Dim newPictureBox As New PictureBox

newPictureBox.Image = Image.FromFile("C:\pathToYourImage\filename.jpg")
newPictureBox.Visible = True
newPictureBox.Top = 20
newPictureBox.Width = 100
newPictureBox.Height = 50
newPictureBox.Left = 10
'add control to form
Controls.Add(newPictureBox)

User is offlineProfile CardPM
+Quote Post

orangeslide8
RE: Creating A New Picture Box
8 Feb, 2007 - 01:57 PM
Post #3

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
one question i have about that is what will the name of that picture box be

User is offlineProfile CardPM
+Quote Post

orangeslide8
RE: Creating A New Picture Box
8 Feb, 2007 - 02:22 PM
Post #4

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
also could i make an array as a new picture box like this
CODE

dim test(5) as new picture box

the problem is that it only lets me do
CODE

dim test (5) as picturebox

not as a new picture box is that the same thing?

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Creating A New Picture Box
8 Feb, 2007 - 03:39 PM
Post #5

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
QUOTE(orangeslide8 @ 8 Feb, 2007 - 01:57 PM) *

one question i have about that is what will the name of that picture box be

The name of the PictureBox is the name of the object given in the Dim statement, in this case newPictureBox.

To create an array of controls you must initialize each control independently of the others. That is why you cannot use the New keyword when declaring the array of controls.
CODE

Dim test(5) As PictureBox

test(0) = New PictureBox
test(1) = New PictureBox
.
.
.etc..
Controls.Add(test(0))
Controls.Add(test(1))


Don't forget, if you create your controls in code then you must handle setting the properties in code like I showed you in the previous post.
User is offlineProfile CardPM
+Quote Post

orangeslide8
RE: Creating A New Picture Box
9 Feb, 2007 - 05:33 PM
Post #6

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
i wrote
CODE

test(1) = New PictureBox
Test(1).Image = Image.FromFile("C:\documents and settings\rob crampton\desktop\red chip.tiff"
test(1).Width = 51
test(1).Height = 53
Test(1).Top = 373
Test(1).Left = 220
Test(1).visible = true
controls.Add(Chip(1))

but it highlighted
CODE

test(1) = New Picturebox

and said that
NullReferenceExeption was Unhandled
i don't understand why its happening any help would be great

User is offlineProfile CardPM
+Quote Post

amazebert
RE: Creating A New Picture Box
8 Oct, 2008 - 10:46 AM
Post #7

New D.I.C Head
*

Joined: 8 Oct, 2008
Posts: 1

QUOTE(jayman9 @ 8 Feb, 2007 - 02:41 PM) *

Yes, anything you can do in the designer can be done at runtime. Just have the code execute inside the Form Load event.

An example would be:
CODE

Dim newPictureBox As New PictureBox

newPictureBox.Image = Image.FromFile("C:\pathToYourImage\filename.jpg")
newPictureBox.Visible = True
newPictureBox.Top = 20
newPictureBox.Width = 100
newPictureBox.Height = 50
newPictureBox.Left = 10
'add control to form
Controls.Add(newPictureBox)


What happens when the project is sent to a different user or computer? The path name to the picture will not be the same. How can this be overcome?
User is offlineProfile CardPM
+Quote Post

thava
RE: Creating A New Picture Box
8 Oct, 2008 - 06:19 PM
Post #8

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 452



Thanked: 18 times
Dream Kudos: 50
My Contributions
place afolder in your project folder and place all those images when you deploy your project deploy the files in working folder of your exe
now use the

appl.path

oh it's in vb.net please move this post to vb.net

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:29PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month