表示一個沿著水平或垂直方向動態排放其內容的面板。
命名空間:System.Windows.Forms
程式集:System.Windows.Forms(在 system.windows.forms.dll 中)
FlowLayoutPanel 控制項沿著水平或垂直流向排列其內容。它的內容可以從一行換到下一行或從一列換到下一列。或者,還可以對它的內容進行剪裁,而不是進行換行。
可以通過設定 FlowDirection 屬性的值來指定流向。在從右向左 (RTL) 的布局中,FlowLayoutPanel 控制項會相應地反轉其流向。還可以通過設定 WrapContents 屬性的值來指定是對FlowLayoutPanel 控制項的內容進行換行還是剪裁。
任何 Windows 表單控制項(包括 FlowLayoutPanel 的其他執行個體)都可以是 FlowLayoutPanel 控制項的子級。使用此功能,可以構造在運行時能夠根據表單的尺寸進行相應調整的複雜布局。
子控制項的停靠和錨定行為與其他容器控制項的行為不同。停靠和錨定行為均相對於流向中的最大控制項。
樣本:
下面的樣本示範如何在 FlowLayoutPanel 控制項上設定 FlowDirection 和 WrapContents 屬性。
using System;<br />using System.Windows.Forms;<br />public class Form1 : System.Windows.Forms.Form<br />{<br />private void wrapContentsCheckBox_CheckedChanged(<br />System.Object sender,<br />System.EventArgs e)<br /> {<br /> this.FlowLayoutPanel1.WrapContents =<br />this.wrapContentsCheckBox.Checked;<br /> }<br /> private void flowTopDownBtn_CheckedChanged(<br />System.Object sender,<br />System.EventArgs e)<br /> {<br /> this.FlowLayoutPanel1.FlowDirection = FlowDirection.TopDown;<br /> }<br /> private void flowBottomUpBtn_CheckedChanged(<br />System.Object sender,<br />System.EventArgs e)<br /> {<br /> this.FlowLayoutPanel1.FlowDirection = FlowDirection.BottomUp;<br /> }<br /> private void flowLeftToRight_CheckedChanged(<br />System.Object sender,<br />System.EventArgs e)<br /> {<br /> this.FlowLayoutPanel1.FlowDirection = FlowDirection.LeftToRight;<br /> }<br /> private void flowRightToLeftBtn_CheckedChanged(<br />System.Object sender,<br />System.EventArgs e)<br /> {<br /> this.FlowLayoutPanel1.FlowDirection = FlowDirection.RightToLeft;<br /> }<br />#region " Windows Form Designer generated code "<br /> public Form1() : base()<br /> {<br /> //This call is required by the Windows Form Designer.<br /> InitializeComponent();<br /> //Add any initialization after the InitializeComponent() call<br /> }<br /> //Form overrides dispose to clean up the component list.<br /> protected override void Dispose(bool disposing)<br /> {<br /> if (disposing)<br /> {<br /> if (components != null)<br /> {<br /> components.Dispose();<br /> }<br /> }<br /> base.Dispose(disposing);<br /> }<br />private System.Windows.Forms.FlowLayoutPanel FlowLayoutPanel1;<br />private System.Windows.Forms.CheckBox wrapContentsCheckBox;<br />private System.Windows.Forms.RadioButton flowTopDownBtn;<br />private System.Windows.Forms.RadioButton flowBottomUpBtn;<br />private System.Windows.Forms.RadioButton flowLeftToRight;<br />private System.Windows.Forms.RadioButton flowRightToLeftBtn;<br />private System.Windows.Forms.Button Button1;<br />private System.Windows.Forms.Button Button2;<br />private System.Windows.Forms.Button Button3;<br />private System.Windows.Forms.Button Button4;<br />//Required by the Windows Form Designer<br /> private System.ComponentModel.IContainer components;<br /> //NOTE: The following procedure is required by the Windows Form Designer<br /> //It can be modified using the Windows Form Designer.<br /> //Do not modify it using the code editor.<br /> [System.Diagnostics.DebuggerNonUserCode]<br /> private void InitializeComponent()<br /> {<br />this.FlowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();<br />this.Button1 = new System.Windows.Forms.Button();<br />this.Button2 = new System.Windows.Forms.Button();<br />this.Button3 = new System.Windows.Forms.Button();<br />this.Button4 = new System.Windows.Forms.Button();<br />this.wrapContentsCheckBox = new System.Windows.Forms.CheckBox();<br />this.flowTopDownBtn = new System.Windows.Forms.RadioButton();<br />this.flowBottomUpBtn = new System.Windows.Forms.RadioButton();<br />this.flowLeftToRight = new System.Windows.Forms.RadioButton();<br />this.flowRightToLeftBtn = new System.Windows.Forms.RadioButton();<br />this.FlowLayoutPanel1.SuspendLayout();<br />this.SuspendLayout();<br />//<br />// FlowLayoutPanel1<br />//<br />this.FlowLayoutPanel1.Controls.Add(this.Button1);<br />this.FlowLayoutPanel1.Controls.Add(this.Button2);<br />this.FlowLayoutPanel1.Controls.Add(this.Button3);<br />this.FlowLayoutPanel1.Controls.Add(this.Button4);<br />this.FlowLayoutPanel1.Location = new System.Drawing.Point(47, 55);<br />this.FlowLayoutPanel1.Name = "FlowLayoutPanel1";<br />this.FlowLayoutPanel1.TabIndex = 0;<br />//<br />// Button1<br />//<br />this.Button1.Location = new System.Drawing.Point(3, 3);<br />this.Button1.Name = "Button1";<br />this.Button1.TabIndex = 0;<br />this.Button1.Text = "Button1";<br />//<br />// Button2<br />//<br />this.Button2.Location = new System.Drawing.Point(84, 3);<br />this.Button2.Name = "Button2";<br />this.Button2.TabIndex = 1;<br />this.Button2.Text = "Button2";<br />//<br />// Button3<br />//<br />this.Button3.Location = new System.Drawing.Point(3, 32);<br />this.Button3.Name = "Button3";<br />this.Button3.TabIndex = 2;<br />this.Button3.Text = "Button3";<br />//<br />// Button4<br />//<br />this.Button4.Location = new System.Drawing.Point(84, 32);<br />this.Button4.Name = "Button4";<br />this.Button4.TabIndex = 3;<br />this.Button4.Text = "Button4";<br />//<br />// wrapContentsCheckBox<br />//<br />this.wrapContentsCheckBox.Location = new System.Drawing.Point(46, 162);<br />this.wrapContentsCheckBox.Name = "wrapContentsCheckBox";<br />this.wrapContentsCheckBox.TabIndex = 1;<br />this.wrapContentsCheckBox.Text = "Wrap Contents";<br />this.wrapContentsCheckBox.CheckedChanged += new System.EventHandler(this.wrapContentsCheckBox_CheckedChanged);<br />//<br />// flowTopDownBtn<br />//<br />this.flowTopDownBtn.Location = new System.Drawing.Point(45, 193);<br />this.flowTopDownBtn.Name = "flowTopDownBtn";<br />this.flowTopDownBtn.TabIndex = 2;<br />this.flowTopDownBtn.Text = "Flow TopDown";<br />this.flowTopDownBtn.CheckedChanged += new System.EventHandler(this.flowTopDownBtn_CheckedChanged);<br />//<br />// flowBottomUpBtn<br />//<br />this.flowBottomUpBtn.Location = new System.Drawing.Point(44, 224);<br />this.flowBottomUpBtn.Name = "flowBottomUpBtn";<br />this.flowBottomUpBtn.TabIndex = 3;<br />this.flowBottomUpBtn.Text = "Flow BottomUp";<br />this.flowBottomUpBtn.CheckedChanged += new System.EventHandler(this.flowBottomUpBtn_CheckedChanged);<br />//<br />// flowLeftToRight<br />//<br />this.flowLeftToRight.Location = new System.Drawing.Point(156, 193);<br />this.flowLeftToRight.Name = "flowLeftToRight";<br />this.flowLeftToRight.TabIndex = 4;<br />this.flowLeftToRight.Text = "Flow LeftToRight";<br />this.flowLeftToRight.CheckedChanged += new System.EventHandler(this.flowLeftToRight_CheckedChanged);<br />//<br />// flowRightToLeftBtn<br />//<br />this.flowRightToLeftBtn.Location = new System.Drawing.Point(155, 224);<br />this.flowRightToLeftBtn.Name = "flowRightToLeftBtn";<br />this.flowRightToLeftBtn.TabIndex = 5;<br />this.flowRightToLeftBtn.Text = "Flow RightToLeft";<br />this.flowRightToLeftBtn.CheckedChanged += new System.EventHandler(this.flowRightToLeftBtn_CheckedChanged);<br />//<br />// Form1<br />//<br />this.ClientSize = new System.Drawing.Size(292, 266);<br />this.Controls.Add(this.flowRightToLeftBtn);<br />this.Controls.Add(this.flowLeftToRight);<br />this.Controls.Add(this.flowBottomUpBtn);<br />this.Controls.Add(this.flowTopDownBtn);<br />this.Controls.Add(this.wrapContentsCheckBox);<br />this.Controls.Add(this.FlowLayoutPanel1);<br />this.Name = "Form1";<br />this.Text = "Form1";<br />this.FlowLayoutPanel1.ResumeLayout(false);<br />this.ResumeLayout(false);<br />}<br />#endregion<br />}<br />