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 属性调用,面板在设计时将其添加到其子控件中。

适用于

另请参阅