Label 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示标准 Windows 标签。
public ref class Label : System::Windows::Forms::Control
public ref class Label : System::Windows::Forms::Control, System::Windows::Forms::Automation::IAutomationLiveRegion
public class Label : System.Windows.Forms.Control
[System.ComponentModel.DefaultBindingProperty("Text")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
public class Label : System.Windows.Forms.Control
[System.ComponentModel.DefaultBindingProperty("Text")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
public class Label : System.Windows.Forms.Control, System.Windows.Forms.Automation.IAutomationLiveRegion
[System.ComponentModel.DefaultBindingProperty("Text")]
public class Label : System.Windows.Forms.Control, System.Windows.Forms.Automation.IAutomationLiveRegion
type Label = class
inherit Control
[<System.ComponentModel.DefaultBindingProperty("Text")>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Label = class
inherit Control
[<System.ComponentModel.DefaultBindingProperty("Text")>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Label = class
inherit Control
interface IAutomationLiveRegion
[<System.ComponentModel.DefaultBindingProperty("Text")>]
type Label = class
inherit Control
interface IAutomationLiveRegion
Public Class Label
Inherits Control
Public Class Label
Inherits Control
Implements IAutomationLiveRegion
- 继承
- 派生
- 属性
- 实现
示例
下面的代码示例演示如何创建具有 Label 三维边框并包含图像的控件。 图像使用 ImageList 和 ImageIndex 属性显示。 控件还具有指定助记符的描述文字。 示例代码使用 PreferredHeight 和 PreferredWidth 属性来正确调整控件的大小 Label 。 此示例要求 ImageList 已创建名为 imageList1 的 ,并且已加载两个映像。 该示例还要求代码位于将 命名空间添加到其代码的窗体 System.Drawing 中。
public:
void CreateMyLabel()
{
// Create an instance of a Label.
Label^ label1 = gcnew Label;
// Set the border to a three-dimensional border.
label1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
// Set the ImageList to use for displaying an image.
label1->ImageList = imageList1;
// Use the second image in imageList1.
label1->ImageIndex = 1;
// Align the image to the top left corner.
label1->ImageAlign = ContentAlignment::TopLeft;
// Specify that the text can display mnemonic characters.
label1->UseMnemonic = true;
// Set the text of the control and specify a mnemonic character.
label1->Text = "First &Name:";
/* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
label1->Size = System::Drawing::Size( label1->PreferredWidth, label1->PreferredHeight );
//...Code to add the control to the form...
}
public void CreateMyLabel()
{
// Create an instance of a Label.
Label label1 = new Label();
// Set the border to a three-dimensional border.
label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
// Set the ImageList to use for displaying an image.
label1.ImageList = imageList1;
// Use the second image in imageList1.
label1.ImageIndex = 1;
// Align the image to the top left corner.
label1.ImageAlign = ContentAlignment.TopLeft;
// Specify that the text can display mnemonic characters.
label1.UseMnemonic = true;
// Set the text of the control and specify a mnemonic character.
label1.Text = "First &Name:";
/* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
label1.Size = new Size (label1.PreferredWidth, label1.PreferredHeight);
//...Code to add the control to the form...
}
Public Sub CreateMyLabel()
' Create an instance of a Label.
Dim label1 As New Label()
' Set the border to a three-dimensional border.
label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
' Set the ImageList to use for displaying an image.
label1.ImageList = imageList1
' Use the second image in imageList1.
label1.ImageIndex = 1
' Align the image to the top left corner.
label1.ImageAlign = ContentAlignment.TopLeft
' Specify that the text can display mnemonic characters.
label1.UseMnemonic = True
' Set the text of the control and specify a mnemonic character.
label1.Text = "First &Name:"
' Set the size of the control based on the PreferredHeight and PreferredWidth values.
label1.Size = New Size(label1.PreferredWidth, label1.PreferredHeight)
'...Code to add the control to the form...
End Sub
注解
Label 控件通常用于为控件提供描述性文本。 例如,可以使用 Label 为 TextBox 控件添加描述性文本,以通知用户控件中预期的数据类型。 Label 控件还可用于将描述性文本添加到 , Form 以便为用户提供有用的信息。 例如,可以将 添加到 Label 顶部, Form 以向用户提供有关如何在窗体上的控件中输入数据的说明。 Label 控件还可用于显示有关应用程序状态的运行时信息。 例如,可以将控件 Label 添加到窗体,以便在处理文件列表时显示每个文件的状态。
Label参与窗体的 Tab 键顺序,但不接收焦点 (tab 键顺序中的下一个控件接收焦点) 。 例如,如果 属性设置为 true
,并在控件的 UseMnemonic 属性中Text指定助记键字符(与后的第一个字符 (&) ),当用户按 Alt+ 助记键时,焦点将移动到 Tab 键顺序中的下一个控件。 此功能为窗体提供键盘导航。 除了显示文本之外,Label控件还可以使用 Image 属性或 和 ImageList 属性的组合ImageIndex显示图像。
构造函数
Label() |
初始化 Label 类的新实例。 |
属性
AccessibilityObject |
获取分配给该控件的 AccessibleObject。 (继承自 Control) |
AccessibleDefaultActionDescription |
获取或设置控件的默认操作说明以供具有辅助功能的客户端应用程序使用。 (继承自 Control) |
AccessibleDescription |
获取或设置辅助功能客户端应用程序使用的控件说明。 (继承自 Control) |
AccessibleName |
获取或设置辅助功能客户端应用程序所使用的控件名称。 (继承自 Control) |
AccessibleRole |
获取或设置控件的辅助性角色。 (继承自 Control) |
AllowDrop |
获取或设置一个值,该值指示控件是否可以接受用户拖放到它上面的数据。 (继承自 Control) |
Anchor |
获取或设置控件绑定到的容器的边缘并确定控件如何随其父级一起调整大小。 (继承自 Control) |
AutoEllipsis |
获取或设置一个值,指示是否要在 Label 的右边缘显示省略号 (...) 以表示 Label 文本超出 Label 的指定长度。 |
AutoScrollOffset |
获取或设置一个值,该值指示在 ScrollControlIntoView(Control) 中将控件滚动到何处。 (继承自 Control) |
AutoSize |
获取或设置一个值,该值指示是否自动调整控件的大小以显示其完整内容。 |
BackColor |
获取或设置控件的背景色。 (继承自 Control) |
BackgroundImage |
获取或设置在控件的背景上呈现的图像。 |
BackgroundImageLayout |
此属性与此类无关。 |
BackgroundImageLayout |
获取或设置在 ImageLayout 枚举中定义的背景图像布局。 (继承自 Control) |
BindingContext |
获取或设置控件的 BindingContext。 (继承自 Control) |
BorderStyle |
获取或设置控件的边框样式。 |
Bottom |
获取控件下边缘与其容器的工作区上边缘之间的距离(以像素为单位)。 (继承自 Control) |
Bounds |
获取或设置控件(包括其非工作区元素)相对于其父控件的大小和位置(以像素为单位)。 (继承自 Control) |
CanEnableIme |
获取一个用以指示是否可以将 ImeMode 属性设置为活动值的值,以启用 IME 支持。 (继承自 Control) |
CanFocus |
获取一个值,该值指示控件是否可以接收焦点。 (继承自 Control) |
CanRaiseEvents |
确定是否可以在控件上引发事件。 (继承自 Control) |
CanSelect |
获取一个值,该值指示是否可以选中控件。 (继承自 Control) |
Capture |
获取或设置一个值,该值指示控件是否已捕获鼠标。 (继承自 Control) |
CausesValidation |
获取或设置一个值,该值指示控件是否会引起在任何需要在接收焦点时执行验证的控件上执行验证。 (继承自 Control) |
ClientRectangle |
获取表示控件的工作区的矩形。 (继承自 Control) |
ClientSize |
获取或设置控件的工作区的高度和宽度。 (继承自 Control) |
CompanyName |
获取包含控件的应用程序的公司名称或创建者。 (继承自 Control) |
Container |
获取包含 IContainer 的 Component。 (继承自 Component) |
ContainsFocus |
获取一个值,该值指示控件或它的一个子控件当前是否有输入焦点。 (继承自 Control) |
ContextMenu |
获取或设置与控件关联的快捷菜单。 (继承自 Control) |
ContextMenuStrip |
获取或设置与此控件关联的 ContextMenuStrip。 (继承自 Control) |
Controls |
获取包含在控件内的控件的集合。 (继承自 Control) |
Created |
获取一个值,该值指示控件是否已经创建。 (继承自 Control) |
CreateParams |
获取创建控件句柄时所需要的创建参数。 |
Cursor |
获取或设置当鼠标指针位于控件上时显示的光标。 (继承自 Control) |
DataBindings |
为该控件获取数据绑定。 (继承自 Control) |
DataContext |
获取或设置用于数据绑定的数据上下文。 这是一个环境属性。 (继承自 Control) |
DefaultCursor |
获取或设置控件的默认光标。 (继承自 Control) |
DefaultImeMode |
获取此控件支持的默认输入法编辑器 (IME) 模式。 |
DefaultMargin |
获取控件之间默认指定的间距(以像素为单位)。 |
DefaultMargin |
获取控件之间默认指定的间距(以像素为单位)。 (继承自 Control) |
DefaultMaximumSize |
获取以像素为单位的长度和高度,此长度和高度被指定为控件的默认最大大小。 (继承自 Control) |
DefaultMinimumSize |
获取以像素为单位的长度和高度,此长度和高度被指定为控件的默认最小大小。 (继承自 Control) |
DefaultPadding |
获取控件内容的内部间距(以像素为单位)。 (继承自 Control) |
DefaultSize |
获取控件的默认大小。 |
DesignMode |
获取一个值,用以指示 Component 当前是否处于设计模式。 (继承自 Component) |
DeviceDpi |
获取显示当前控件的显示设备的 DPI 值。 (继承自 Control) |
DisplayRectangle |
获取表示控件的显示区域的矩形。 (继承自 Control) |
Disposing |
获取一个值,该值指示 Control 基类是否在释放进程中。 (继承自 Control) |
Dock |
获取或设置哪些控件边框停靠到其父控件并确定控件如何随其父级一起调整大小。 (继承自 Control) |
DoubleBuffered |
获取或设置一个值,该值指示此控件是否应使用辅助缓冲区重绘其图面,以减少或避免闪烁。 (继承自 Control) |
Enabled |
获取或设置一个值,该值指示控件是否可以对用户交互作出响应。 (继承自 Control) |
Events |
获取附加到此 Component 的事件处理程序的列表。 (继承自 Component) |
FlatStyle |
获取或设置标签控件的平面样式外观。 |
Focused |
获取一个值,该值指示控件是否有输入焦点。 (继承自 Control) |
Font |
获取或设置控件显示的文字的字体。 (继承自 Control) |
FontHeight |
获取或设置控件的字体的高度。 (继承自 Control) |
ForeColor |
获取或设置控件的前景色。 (继承自 Control) |
Handle |
获取控件绑定到的窗口句柄。 (继承自 Control) |
HasChildren |
获取一个值,该值指示控件是否包含一个或多个子控件。 (继承自 Control) |
Height |
获取或设置控件的高度。 (继承自 Control) |
Image |
获取或设置显示在 Label 上的图像。 |
ImageAlign |
获取或设置在控件中显示的图像的对齐方式。 |
ImageIndex |
获取或设置在 Label 上显示的图像的索引值。 |
ImageKey |
获取或设置 ImageList 中的图像的键访问器。 |
ImageList | |
ImeMode |
获取或设置此控件所支持的输入法编辑器 (IME) 模式。 |
ImeModeBase |
获取或设置控件的 IME 模式。 (继承自 Control) |
InvokeRequired |
获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中。 (继承自 Control) |
IsAccessible |
获取或设置一个值,该值指示控件对辅助功能应用程序是否可见。 (继承自 Control) |
IsAncestorSiteInDesignMode |
指示此控件的上级之一是否位于 DesignMode 中。 此属性为只读。 (继承自 Control) |
IsDisposed |
获取一个值,该值指示控件是否已经被释放。 (继承自 Control) |
IsHandleCreated |
获取一个值,该值指示控件是否有与它关联的句柄。 (继承自 Control) |
IsMirrored |
获取一个值,该值指示此控件是否为镜像控件。 (继承自 Control) |
LayoutEngine |
获取控件的布局引擎的缓存实例。 (继承自 Control) |
Left |
获取或设置控件左边缘与其容器的工作区左边缘之间的距离(以像素为单位)。 (继承自 Control) |
LiveSetting |
指示客户端应用于通知用户有关此活动区域的更改的礼貌级别。 |
Location |
获取或设置该控件的左上角相对于其容器的左上角的坐标。 (继承自 Control) |
Margin |
获取或设置控件之间的空间。 (继承自 Control) |
MaximumSize |
获取或设置大小,该大小是 GetPreferredSize(Size) 可以指定的上限。 (继承自 Control) |
MinimumSize |
获取或设置大小,该大小是 GetPreferredSize(Size) 可以指定的下限。 (继承自 Control) |
Name |
获取或设置控件的名称。 (继承自 Control) |
Padding |
获取或设置控件内的空白。 (继承自 Control) |
Parent |
获取或设置控件的父容器。 (继承自 Control) |
PreferredHeight |
获取控件的首选高度。 |
PreferredSize |
获取可以容纳控件的矩形区域的大小。 (继承自 Control) |
PreferredWidth |
获取控件的首选宽度。 |
ProductName |
获取包含控件的程序集的产品名称。 (继承自 Control) |
ProductVersion |
获取包含控件的程序集的版本。 (继承自 Control) |
RecreatingHandle |
获取一个值,该值指示控件当前是否在重新创建其句柄。 (继承自 Control) |
Region |
获取或设置与控件关联的窗口区域。 (继承自 Control) |
RenderRightToLeft |
已过时。
已过时。
此属性现已过时。 (继承自 Control) |
RenderTransparent |
已过时。
已过时。
指示容器控件背景是否在 Label 上呈现。 |
ResizeRedraw |
获取或设置一个值,该值指示控件在调整大小时是否重绘自己。 (继承自 Control) |
Right |
获取控件右边缘与其容器的工作区左边缘之间的距离(以像素为单位)。 (继承自 Control) |
RightToLeft |
获取或设置一个值,该值指示是否将控件的元素对齐以支持使用从右向左的字体的区域设置。 (继承自 Control) |
ScaleChildren |
获取一个值,该值确定子控件的缩放。 (继承自 Control) |
ShowFocusCues |
获取一个值,该值指示控件是否应显示聚焦框。 (继承自 Control) |
ShowKeyboardCues |
获取一个值,该值指示用户界面是否处于适当的状态以显示或隐藏键盘快捷键。 (继承自 Control) |
Site |
获取或设置控件的站点。 (继承自 Control) |
Size |
获取或设置控件的高度和宽度。 (继承自 Control) |
TabIndex |
获取或设置控件在其容器内的 Tab 键顺序。 (继承自 Control) |
TabStop |
获取或设置一个值,指示用户能否通过 Tab 键切换至 Label。 此类未使用此属性。 |
Tag |
获取或设置包含有关控件的数据的对象。 (继承自 Control) |
Text |
获取或设置与此控件关联的文本。 |
Text |
获取或设置与此控件关联的文本。 (继承自 Control) |
TextAlign |
获取或设置标签中文本的对齐方式。 |
Top |
获取或设置控件上边缘与其容器的工作区上边缘之间的距离(以像素为单位)。 (继承自 Control) |
TopLevelControl |
获取没有另一个 Windows 窗体控件作为其父级的父控件。 通常,这是控件所在的最外面的 Form。 (继承自 Control) |
UseCompatibleTextRendering |
获取或设置一个值,该值确定是使用 Graphics 类 (GDI+) 还是 TextRenderer 使用 GDI) 类来呈现文本 (GDI。 |
UseMnemonic |
获取或设置一个值,该值指示控件是否将控件的 Text 属性中的 & 符解释为访问键前缀字符。 |
UseWaitCursor |
获取或设置一个值,该值指示是否将等待光标用于当前控件以及所有子控件。 (继承自 Control) |
Visible |
获取或设置一个值,该值指示是否显示该控件及其所有子控件。 (继承自 Control) |
Width |
获取或设置控件的宽度。 (继承自 Control) |
WindowTarget |
此属性与此类无关。 (继承自 Control) |
方法
事件
显式接口实现
IDropTarget.OnDragDrop(DragEventArgs) |
引发 DragDrop 事件。 (继承自 Control) |
IDropTarget.OnDragEnter(DragEventArgs) |
引发 DragEnter 事件。 (继承自 Control) |
IDropTarget.OnDragLeave(EventArgs) |
引发 DragLeave 事件。 (继承自 Control) |
IDropTarget.OnDragOver(DragEventArgs) |
引发 DragOver 事件。 (继承自 Control) |
适用于
另请参阅
反馈
提交和查看相关反馈