在TableLayoutPanel中查找控件

时间:2009-12-02 06:57:58

标签: c#

private TableLayoutPanel CreateLayoutpan()                     {                         pTablePanel = new TableLayoutPanel();                         pTablePanel.BackColor = System.Drawing.SystemColors.ButtonFace;                         pTablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute,30));                         pTablePanel.RowStyles.Add(new RowStyle());                         pTablePanel.Size = new System.Drawing.Size(165,223);                         pTablePanel.Location = new System.Drawing.Point(9,14);                         pTablePanel.TabIndex = 0;                         pTablePanel.Controls.Clear();                         pTablePanel.ColumnCount = 2;                         return pTablePanel;                     }

PictureBox pict;
            private void AddtoPbx(Image im)
            {
                try
                {
                    pict = new PictureBox();
                    pict.BackColor = System.Drawing.Color.Blue;
                    pict.Padding = new Padding(2);

                     pict.Image = m;                                                              pict.Width = 100;
                    pict.Height = 60;

                    pict.SizeMode = PictureBoxSizeMode.StretchImage;

                    CheckBox chkBx = new CheckBox();
                    chkBx.Name = "checkImage";
                    chkBx.Location = new System.Drawing.Point(40, 40);

                    pTablePanel.Controls.Add(chkBx, 0, iCount);
                    pTablePanel.Controls.Add(pict, 1, iCount);
                    iCount++;                       
                    pTablePanel.AutoScroll = true;
                    System.Threading.Thread.Sleep(50);
                    pict.Focus();
                    STA_gbxImages.Controls.Add(pTablePanel);


                }
                catch (Exception ex)
                {     }
            }

这里我将添加chkbox以及连续的图像.... 现在我的问题是如果chkbox被检查我需要在其他集合中添加ccorresponding图像....如何做到这一点请帮助我...

1 个答案:

答案 0 :(得分:0)

创建动态控件时,请勿直接将它们添加到表单中。只需放置一个PlaceHolder控件并将其添加到其中。 然后,使用占位符中的FinfControl():PlaceHodler1.FindControl("table1")