共用方式為


TableLayoutPanel.SetColumnSpan(Control, Int32) 方法

定義

設定子控制項所合併的資料行數目。

public:
 void SetColumnSpan(System::Windows::Forms::Control ^ control, int value);
public void SetColumnSpan (System.Windows.Forms.Control control, int value);
member this.SetColumnSpan : System.Windows.Forms.Control * int -> unit
Public Sub SetColumnSpan (control As Control, value As Integer)

參數

control
Control

TableLayoutPanel 的子控制項。

value
Int32

要合併的資料行數目。

例外狀況

value 小於 1。

範例

下列程式碼範例會使用 GetColumnSpanSetColumnSpan 方法,在 中 TableLayoutPanel 設定 控制項的 Button 寬度。

private void toggleSpanBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    Control c = this.TableLayoutPanel1.GetControlFromPosition(0, 0);

    if ( c != null )
    {
        int xSpan = this.TableLayoutPanel1.GetColumnSpan(c);
        int ySpan = this.TableLayoutPanel1.GetRowSpan(c);

        if (xSpan>1)
        {
            xSpan = 1;
            ySpan = 1;
        }
        else
        {
            xSpan = 2;
            ySpan = 2;
        }

        this.TableLayoutPanel1.SetColumnSpan(c, xSpan);
        this.TableLayoutPanel1.SetRowSpan(c, ySpan);
    }
}
Private Sub toggleSpanBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles toggleSpanBtn.Click

    Dim c As Control = Me.TableLayoutPanel1.GetControlFromPosition(0, 0)

    If c IsNot Nothing Then

        Dim xSpan As Integer = Me.TableLayoutPanel1.GetColumnSpan(c)
        Dim ySpan As Integer = Me.TableLayoutPanel1.GetRowSpan(c)

        If xSpan > 1 Then

            xSpan = 1
            ySpan = 1

        Else

            xSpan = 2
            ySpan = 2

        End If

        Me.TableLayoutPanel1.SetColumnSpan(c, xSpan)
        Me.TableLayoutPanel1.SetRowSpan(c, ySpan)

    End If

End Sub

備註

資料行跨越通常適用于定位遠大於其對等的控制項。

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

適用於

另請參閱