Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 10th, 2008, 04:55 PM
Authorized User
 
Join Date: Jun 2003
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic picturebox array

Is it possible to create a dynamic picturebox array?

How can i do it?

Somebody knows an example code?

Thanks....
 
Old September 11th, 2008, 02:36 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well that's easy:

List<PictureBox> pictureBoxArray = new List<PictureBox>();

However I somehow suspect that that isn't the question you where intending to ask.

/- Sam Judson : Wrox Technical Editor -/
 
Old September 11th, 2008, 12:42 PM
Authorized User
 
Join Date: Jun 2003
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply;
My problem is:
I use the code below to add an image into a picture box and to put the picture box inside of a panel called (this.panelViveiro):

PictureBox PicBox = new PictureBox();
if (caminhoImagem != "")
            {
                if (coordX.Equals(0) && coordY.Equals(0))
                {
                    horizontalX = this.RandomSerArtificial.Next(this.panelViveiro.Si ze.Width);
                    verticalY = this.RandomSerArtificial.Next(this.panelViveiro.Si ze.Height);
                }

                PicBox.Image = Image.FromFile(caminhoImagem);
                PicBox.Top = 20;
                PicBox.Width = 16;
                PicBox.Height = 16;
                PicBox.Left = 10;
                PicBox.SizeMode = PictureBoxSizeMode.AutoSize;
                PicBox.Location = new System.Drawing.Point(horizontalX, verticalY);
                Controls.Add(PicBox);
                this.panelViveiro.Controls.Add(PicBox);
            }

And now i need to put many images into a panel at the same time.

A List<PictureBox> pictureBoxArray = new List<PictureBox>(); is the best way to do this?

Do you know a weblink with an example?

Thanks again;
Thomaz
 
Old September 17th, 2008, 01:15 PM
Authorized User
 
Join Date: Jun 2003
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To solve my problem i used the Sanjudson tip like below:

private void inserindoMaisdeUmaImagemPictureBox(string caminhoImagem, int coordX, int coordY, int numeroImagens)
        {

            int horizontalX = coordX;
            int verticalY = coordY;

            if (caminhoImagem != "")
            {
                for (int i = 0; i < numeroImagens; i++)
                {
                    PictureBox PicBoxSeres = new PictureBox();
                    horizontalX = this.RandomSerArtificial.Next(this.panelViveiro.Si ze.Width);
                    verticalY = this.RandomSerArtificial.Next(this.panelViveiro.Si ze.Height);
                    PicBoxSeres.Image = Image.FromFile(caminhoImagem);
                    PicBoxSeres.Location = new System.Drawing.Point(horizontalX, verticalY);
                    PicBoxList.Add(PicBoxSeres);
                }

                foreach (PictureBox listaSeres in PicBoxList)
                {
                    this.panelViveiro.Controls.Add(listaSeres);
                }
            }//final do if





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Event On PictureBox In C# akumarp2p C# 7 January 14th, 2009 07:55 AM
Picturebox Array? thomaz C# 2008 aka C# 3.0 1 September 12th, 2008 12:11 PM
PictureBox array ? pafo C# 2 May 26th, 2006 12:49 PM
dynamic multidemsion array harpua Classic ASP Basics 1 July 27th, 2004 02:44 PM
Dynamic array - please help OC Beginning VB 6 5 March 21st, 2004 05:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.