如何在tablelayout中访问控件内的控件

时间:2014-03-17 07:44:32

标签: c# .net tablelayout control-array

我在tablelayoutpanel单元格中有一个Class(Conatiner)对象。我想访问该特定字段中的该文本字段。如何在按钮上单击值?

我想使用Channel以及X和Y值访问1 2 3。但是我不知道tableLayoutPanel中的数字对象

这是我到目前为止编写的代码

private void masterTab1_SaveButton_Click(object sender, EventArgs e)
{

   var colWidths = this.MatrixPanel.GetColumnWidths();
   var rowHeights = this.MatrixPanel.GetRowHeights();
   int col = -1, row = -1;
   int offset = 0;
   for (int iRow = 0; iRow < this.MatrixPanel.RowCount; ++iRow)
   {
       offset += rowHeights[iRow];
       row = iRow;
       for (int iCol = 0; iCol < this.MatrixPanel.ColumnCount; ++iCol)
       {
           offset += colWidths[iCol];
           col = iCol;

           var myCellControl = MatrixPanel.GetControlFromPosition(col, row);
           if (myCellControl is Container)
           {
              Adapter.insertposition(RackID, row, col, //Want the Channel Value  , "Ready");
           }
       }
   }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

如果你的&#34;容器&#34; class是否正确设置/具有获取所需信息所需的所有属性或控件,然后我相信您正在寻找的是:

if (myCellControl is Container)
{
   Container tmp = myCellControl as Container;
   //after this point, you can reference the controls/properties of your
   //Container class/control using tmp... see example below as i do not know
   //what your Container control exposes as far as properties are concerned.
   Adapter.insertposition(RackID, row, col, tmp.ChannelValue, "Ready");
}