TableLayoutPanel.SetRowSpan(Control, Int32) 方法

定义

设置子控件跨的行数。

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

参数

control
Control

TableLayoutPanel 的子控件。

value
Int32

要跨的行数。

例外

value 小于 1。

示例

下面的代码示例使用GetRowSpanSetRowSpan方法设置控件的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

注解

跨行通常可用于定位比其对等高得多的控件。

此方法由 RowSpan 属性调用,面板在设计时将其添加到其子控件中。

适用于

另请参阅