此控件用于在Web窗体上显示文本信息。它主要用于为其他控件(如:TextBox)创建标题。
要创建Label标签,无涯教程可以编写代码,也可以使用Visual Studio 2017的拖放功能。
这是服务器端控件,asp提供自己的标签来创建标签。下面给出了示例。
<asp:LabelID="Label1" runat="server" Text="Label" ></asp:Label>
此控件具有自己的属性,如下表所示。
Property | Description |
---|---|
AccessKey | 它用于为标签设置键盘快捷键。 |
TabIndex | 控件的选项卡顺序。 |
BackColor | 它用于设置标签的背景颜色。 |
BorderColor | 它用于设置标签的边框颜色。 |
BorderWidth | 它用于设置标签边框的宽度。 |
Font | 它用于为标签文本设置字体。 |
ForeColor | 它用于设置标签文本的颜色。 |
Text | 它用于设置要为标签显示的文本。 |
ToolTip | 它显示鼠标在标签上时显示文本。 |
Visible | 在表格上设置控制的可见性。 |
Height | 它用于设置控件的高度。 |
Width | 它用于设置控件的宽度。 |
//WebControls.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebControls.aspx.cs" Inherits="WebFormsControlls.WebControls" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .auto-style1 { width: 100%; } .auto-style2 { margin-left: 0px; } .auto-style3 { width: 121px; } </style> </head> <body> <form id="form1" runat="server"> <div> <h4>Provide the Following Details:</h4> <table class="auto-style1"> <tr> <td class="auto-style3"> <asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label></td> <td> <asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style2"></asp:TextBox></td> </tr> <tr> <td class="auto-style3"> <asp:Label ID="Label2" runat="server" Text="Upload a File"></asp:Label></td> <td> <asp:FileUpload ID="FileUpload1" runat="server" /></td> </tr> </table> </div> </form> </body> </html>
这是标签控件的属性窗口。
在这里,无涯教程使用了带有两个不同控件的Label控件。它会产生以下输出。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)