TableLayoutPanel.GrowStyle 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示当现有的所有单元格都被占用时,TableLayoutPanel 控件是否应该扩展以容纳新单元格。
public:
property System::Windows::Forms::TableLayoutPanelGrowStyle GrowStyle { System::Windows::Forms::TableLayoutPanelGrowStyle get(); void set(System::Windows::Forms::TableLayoutPanelGrowStyle value); };
public System.Windows.Forms.TableLayoutPanelGrowStyle GrowStyle { get; set; }
member this.GrowStyle : System.Windows.Forms.TableLayoutPanelGrowStyle with get, set
Public Property GrowStyle As TableLayoutPanelGrowStyle
属性值
指示增长方案的 TableLayoutPanelGrowStyle。 默认值为 AddRows。
例外
此属性值对于 TableLayoutPanelGrowStyle 枚举无效。
示例
下面的代码示例根据所选 RadioButton设置 属性的值GrowStyle。 在运行时,当用户单击标记为 “Test GrowStyle”的按钮时, Button 控件将添加到控件中 TableLayoutPanel 。 TableLayoutPanel如果控件已满,则它通过添加行或列进行扩展,或者会引发异常,具体取决于 的值GrowStyle。
private void growStyleNoneBtn_CheckedChanged(
System.Object sender,
System.EventArgs e)
{
this.tlpGrowStyle = TableLayoutPanelGrowStyle.FixedSize;
}
private void growStyleAddRowBtn_CheckedChanged(
System.Object sender,
System.EventArgs e)
{
this.tlpGrowStyle = TableLayoutPanelGrowStyle.AddRows;
}
private void growStyleAddColumnBtn_CheckedChanged(
System.Object sender,
System.EventArgs e)
{
this.tlpGrowStyle = TableLayoutPanelGrowStyle.AddColumns;
}
private void testGrowStyleBtn_Click(
System.Object sender,
System.EventArgs e)
{
this.TableLayoutPanel1.GrowStyle = this.tlpGrowStyle;
try
{
this.TableLayoutPanel1.Controls.Add(new Button());
}
catch(ArgumentException ex)
{
Trace.WriteLine(ex.Message);
}
}
Private Sub growStyleNoneBtn_CheckedChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles growStyleNoneBtn.CheckedChanged
Me.tlpGrowStyle = TableLayoutPanelGrowStyle.FixedSize
End Sub
Private Sub growStyleAddRowBtn_CheckedChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles growStyleAddRowBtn.CheckedChanged
Me.tlpGrowStyle = TableLayoutPanelGrowStyle.AddRows
End Sub
Private Sub growStyleAddColumnBtn_CheckedChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles growStyleAddColumnBtn.CheckedChanged
Me.tlpGrowStyle = TableLayoutPanelGrowStyle.AddColumns
End Sub
Private Sub testGrowStyleBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles testGrowStyleBtn.Click
Me.TableLayoutPanel1.GrowStyle = Me.tlpGrowStyle
Try
Me.TableLayoutPanel1.Controls.Add(New Button())
Catch ex As ArgumentException
Trace.WriteLine(ex.Message)
End Try
End Sub
注解
默认情况下,TableLayoutPanel 控件通过添加行向下扩展。
注意
如果尝试将控件添加到完整TableLayoutPanel控件,并且 的GrowStyleFixedSize值为 ,则会ArgumentException引发 。