TableLayoutPanel.GetRowSpan(Control) 方法

定义

返回指定子控件跨的行数。

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

参数

control
Control

TableLayoutPanel 的子控件。

返回

子控件跨的行数。 默认值为 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 属性调用,面板在设计时将其添加到其子控件。

适用于

另请参阅