DIGIT-ARC read-only archive · snapshot: July 23, 2026

Panel Control in C#

6 posts · originally from https://geek.digit.in/community/threads/panel-control-in-c.127075/

arpanmukherjee1
arpanmukherjee1 Original post #1
May 19, 2010 at 6:54 PM
hello,
i have a panel.
i add label and a pictureBox using this :
Code:
private void AddLabelAndImage(ref Point startPoint, string labelText, System.Drawing.Image image)
        {
            Label label = new Label();
            panel1.Controls.Add(label);
            label.Text = labelText;
            label.Name = "text";
            label.Width = 100;
            label.Height = 30;
            label.Location = startPoint;
            startPoint.Y += label.Height;

            System.Windows.Forms.PictureBox box = new PictureBox();
            panel1.Controls.Add(box);
            box.Name = "image";
            box.Size = image.Size;
            box.Image = image;
            box.Location = startPoint;
            startPoint.Y += box.Height + 10;

what i want is to retrieve the picturebox control as System.Windows.Forms.PictureBox.
every function like find() returns Control[]

how to do this??
vamsi360
May 27, 2010 at 2:27 PM
you have to returen the reference of the control i guess. I will try and tell you...
arpanmukherjee1
May 27, 2010 at 10:32 PM
^ do you mean ::

PictureBox p1= panel1 ????
dheeraj_kumar
Jun 8, 2010 at 4:08 AM
It's simple.

Cast the Control returned to PictureBox.
Zangetsu
Jun 8, 2010 at 9:45 AM
hello,
i have a panel.
i add label and a pictureBox using this :
Code:
private void AddLabelAndImage(ref Point startPoint, string labelText, System.Drawing.Image image)
        {
            Label label = new Label();
            panel1.Controls.Add(label);
            label.Text = labelText;
            label.Name = "text";
            label.Width = 100;
            label.Height = 30;
            label.Location = startPoint;
            startPoint.Y += label.Height;

            System.Windows.Forms.PictureBox box = new PictureBox();
            panel1.Controls.Add(box);
            box.Name = "image";
            box.Size = image.Size;
            box.Image = image;
            box.Location = startPoint;
            startPoint.Y += box.Height + 10;
what i want is to retrieve the picturebox control as System.Windows.Forms.PictureBox.
every function like find() returns Control[]

how to do this??

u r using a subroutine.....& adding label & picturebox in panel.....
but i didnt get ur question...u want to get the picturebox then u can use
panel.findcontrol() method......
arpanmukherjee1
Jun 9, 2010 at 12:16 AM
it's done. it returned PictureBox type .

thanks 2 u all 4 ur efforts...............