Share via


TableLayoutPanel.GetColumn(Control) 方法

定義

傳回指定之子控制項的資料行位置。

public:
 int GetColumn(System::Windows::Forms::Control ^ control);
public int GetColumn (System.Windows.Forms.Control control);
member this.GetColumn : System.Windows.Forms.Control -> int
Public Function GetColumn (control As Control) As Integer

參數

control
Control

TableLayoutPanel 的子控制項。

傳回

Int32

指定之子控制項的資料行位置,如果 control 的位置是由 LayoutEngine 所決定,則為 -1。

例外狀況

controlnull

control 並不是一個可由此 LayoutEngine 所安排的型別。

範例

下列程式碼範例會列舉 中的所有 TableLayoutPanel 子控制項,並使用 方法尋找每個控制項 GetColumn 的資料行索引。

private void getColumnBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    foreach ( Control c in this.TableLayoutPanel1.Controls )
    {
        Trace.WriteLine(this.TableLayoutPanel1.GetColumn(c));
    }
}
Private Sub getColumnBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles getColumnBtn.Click

    Dim c As Control
    For Each c In Me.TableLayoutPanel1.Controls

        Trace.WriteLine(Me.TableLayoutPanel1.GetColumn(c))

    Next

End Sub

備註

如果 control 跨越兩個或多個資料行, GetColumn 方法會傳回最低的資料行索引。

資料行位置值是以零起始,因此您可以使用它做為 所 GetColumnWidths 傳回陣列的索引。

這個方法是由 Column 屬性所呼叫,面板會在設計階段新增至其子控制項。

若要取得 的實際位置,即使其位置 control 是由 LayoutEngine 判斷,仍 GetPositionFromControl 會呼叫 方法。

適用於

另請參閱