Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)qq
published in(发表于) 2014/7/11 9:16:22
C#中FlowLayoutPanel控件用法以及实例

C#中FlowLayoutPanel控件用法以及实例

FlowLayoutPanel控件

功能

FlowLayoutPanel控件用来在水平或垂直方向排列其内容。开发人员可以将FlowLayoutPanel控件的内容从一行换至下一行,或者从一列换至下一列,还可以选择剪裁内容。任何Windows窗体控件都可以是FlowLayoutPanel控件的子控件,包括FlowLayout Panel的其他实例。利用此功能,可以在运行时构造适应窗体尺寸大小的复杂布局。图1所示为FlowLayoutPanel 控件。



图1 FlowLayoutPanel控件

2.属性

FlowLayoutPanel控件常用属性及说明如表1所示。



表1 FlowLayoutPanel控件常用属性及说明

下面详细介绍FlowDirection属性,此属性用来指示控件布局的方向。

语法:

public FlowDirection FlowDirection { get; set; }

属性值:FlowDirection值之一,指示控件在面板中的连续放置方向。默认值为LeftToRight。

说明:FlowDirection是一个返回值,它用来指定控件布局的方向。当值为BottomUp时,元素从设计图面的底部流到顶部;当值为LeftToRight时,元素从设计图面的左边缘流到右边缘,默认为此选项;当值为RightToLeft时,元素从设计图面的右边缘流到左边缘;当值为TopDown时,元素从设计图面的顶部流到底部。本教程来自http://www.isstudy.com/

示例

FlowDirection属性

本示例中,当程序运行时,单击【FlowDirection属性】按钮,把FlowDirection属性设置为底部布局。示例运行结果如图2所示。



图2 FlowDirection属性

程序主要代码如下:

this.flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;

完整程序代码如下:网站源代码

主程序文件完整程序代码如下:

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_19

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmFlowLayoutPane());

}

}

}

frmFlowLayoutPane窗体设计文件完整程序代码如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _8_19

{

public partial class frmFlowLayoutPane : Form

{

public frmFlowLayoutPane()

{

InitializeComponent();

}

private void button7_Click(object sender, EventArgs e)

{

this.flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;

}

private void button8_Click(object sender, EventArgs e)

{

this.flowLayoutPanel1.SetFlowBreak(this.flowLayoutPanel1, false);

}

private void flowLayoutPanel1_Layout(object sender, LayoutEventArgs e)

{

}

private void frmFlowLayoutPane_Load(object sender, EventArgs e)

{

}

}

}

frmFlowLayoutPane窗体代码文件完整程序代码如下:

namespace _8_19

//本教程来自http://www.isstudy.com/

{

partial class frmFlowLayoutPane

{

///

/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();

this.button1 = new System.Windows.Forms.Button();

this.button5 = new System.Windows.Forms.Button();


If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759