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

The author:(作者)qq
published in(发表于) 2014/7/11 9:17:11
C#中Label控件应用实例

C#中Label控件应用实例

Label控件

1.功能

Label控件即标签控件,是Windows应用程序中最基本的控件。Label控件用来显示用户不能直接改变的文本信息。可以在“属性”窗口中设置控件的文本信息,也可以通过编写代码来设置要显示的文本信息。在向窗体添加Label控件时,系统会自动创建Label控件的一个对象。图1为Label控件。

向窗体添加Label控件的步骤如下。

(1)在“工具箱”窗口中选择要添加的Label控件。

(2)将鼠标焦点移动到窗体上,当鼠标指针变为十字形时,按住鼠标左键同时拖曳鼠标,当达到所需要的大小时释放鼠标,此时控件将被添加到窗体中,如图2所示。其他控件的添加方法与Label控件类似,不再详细介绍。



图1 Label控件



图2 在窗体中添加控件

2.属性

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

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



续表



下面对比较重要的属性进行详细介绍。

(1)Text属性。用来设置要在该控件上显示的文本。

语法:

public override string Text { get; set; }
示例

使用Text属性设置控件的显示文本

本示例实现的功能是,当程序运行时,在Label控件中显示“欢迎你”文本信息。

程序主要代码如下:

private void frmLabel_Load(object sender, EventArgs e)

{

this.label1.Text = "欢迎你";

}

(2)Visible属性。用于设置控件是否可见。

语法:

public bool Visible { get; set; }
属性值:如果显示该控件,则为True,否则为False。一般默认为True。

例如,下面用来设置Label2控件是可见的,代码如下:

label2.Visible = True;
完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_01

{

static class Program

{

///



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

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmLabel());

}

}

}

★★★★★frmLabel窗体设计文件完整程序代码★★★★★


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





QQ:154298438
QQ:417480759