473,322 Members | 1,409 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,322 software developers and data experts.

dynamic pictureBox creation

Hi all,

I have a form that contains one button and one textbox, the textbox will take a number that will be passed to another form. I have done this successfully.
The thing is that I need the second form to create a number of pictureboxes = the number received from the first form.

Any ideas?
Mar 12 '07 #1
2 1783
bergy
89
Are you using VB .NET or C#? I'll write you a little example loop that you can expand on if you let me know which language to use :)

Adam
Mar 13 '07 #2
bergy
89
Well here is the VB, let me know if you need C#. What I have here is a button that when pressed will generate 5 pictureboxes on the form, you can easily change NumOfBoxes = 5 to your textbox value. I have also attached a click event to each picture box and included the sub to handle when you click on one.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim NumOfBoxes As Integer = 5
  3.         For i As Integer = 0 To NumOfBoxes - 1
  4.             Dim myPicBox As New PictureBox
  5.             'Give the Box a Name
  6.             myPicBox.Name = "DynamicPicBox" & i
  7.             'Give the Picture Boxes a Border so we can see them
  8.             myPicBox.BorderStyle = BorderStyle.FixedSingle
  9.             'Set the Width and Height
  10.             myPicBox.Width = 50
  11.             myPicBox.Height = 50
  12.             'Set the position of the boxes
  13.             myPicBox.Left = 10 * i
  14.             myPicBox.Top = 50 * i
  15.             'Add a "Click" event handler
  16.             AddHandler myPicBox.Click, AddressOf DynPicBox_Click
  17.             Me.Controls.Add(myPicBox)
  18.         Next i
  19.     End Sub
  20.  
  21.     Private Sub DynPicBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  22.         'Send the Name in a message - notice we have to cast the sender object to a picture box
  23.         MessageBox.Show("You clicked picture box: " & CType(sender, PictureBox).Name)
  24.     End Sub
Happy Coding!

Adam
Mar 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK'...
1
by: Will | last post by:
Hi all. I'm learning VB.Net and am developing a WinForms app. I'm trying to make an app that I will use to scan in one or more than on image. I want to use a tabbed interface to hold each image....
7
by: Scott Mackay | last post by:
Hi, I'm using visual studio dotnet 2002 programming in vb can anyone tell me how I can handle the mousedown event for pictureboxes I create dynamically at runtime? I've tried setting the...
6
by: Rich | last post by:
Hello, I want to simulate the dynamic thumbnail display of Windows Explorer (winxp) on a form or pannel container. If I place a picture box on my container form/pannel and dimension it to the...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
13
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
3
by: TheLostLeaf | last post by:
How do I change this : this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.pictureBox3 = new...
2
by: TheLostLeaf | last post by:
Hello, Im a c# noob, How do I Change this: this.pictureBox.Image = global::WindowsApplication1.Properties.Resources._00; this.pictureBox.Image =...
1
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
5
by: AWW | last post by:
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.