creating a new picture box

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

Page 1 of 1

7 Replies - 39883 Views - Last Post: 08 October 2008 - 07:19 PM Rate Topic: -----

#1 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

creating a new picture box

Posted 08 February 2007 - 01:33 PM

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
Is This A Good Question/Topic? 0
  • +

#26 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: creating a new picture box

Posted 08 February 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:
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)


Was This Post Helpful? 2

#27 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: creating a new picture box

Posted 08 February 2007 - 02:57 PM

one question i have about that is what will the name of that picture box be
Was This Post Helpful? 0
  • +
  • -

#28 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: creating a new picture box

Posted 08 February 2007 - 03:22 PM

also could i make an array as a new picture box like this
dim test(5) as new picture box

the problem is that it only lets me do
dim test (5) as picturebox 


not as a new picture box is that the same thing?
Was This Post Helpful? 0
  • +
  • -

#29 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: creating a new picture box

Posted 08 February 2007 - 04:39 PM

View Postorangeslide8, on 8 Feb, 2007 - 01:57 PM, said:

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.
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.
Was This Post Helpful? 0
  • +
  • -

#30 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: creating a new picture box

Posted 09 February 2007 - 06:33 PM

i wrote
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
test(1) = New Picturebox


and said that
NullReferenceExeption was Unhandled
i don't understand why its happening any help would be great
Was This Post Helpful? 0
  • +
  • -

#31 amazebert  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-October 08

Re: creating a new picture box

Posted 08 October 2008 - 11:46 AM

View Postjayman9, on 8 Feb, 2007 - 02:41 PM, said:

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:
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?
Was This Post Helpful? 0
  • +
  • -

#32 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: creating a new picture box

Posted 08 October 2008 - 07:19 PM

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1