C#中标签怎么定义 用法又是如何

如题所述

第1个回答  2009-04-03
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.label_members(VS.80).aspx

Label 类
表示标准 Windows 标签。

Label 控件通常用于提供控件的描述性文字。例如,可使用 Label 为 TextBox 控件添加描述性文字,以便将控件中所需的数据类型通知用户。Label 控件还可用于为 Form 添加描述性文字,以便为用户提供有帮助作用的信息。例如,可将 Label 添加到 Form 的顶部,为用户提供关于如何将数据输入窗体上的控件中的说明。Label 控件还可用于显示有关应用程序状态的运行时信息。例如,可将 Label 控件添加到窗体,以便在处理一列文件时显示每个文件的状态。

Label 参与窗体的 Tab 键顺序,但不接收焦点(Tab 键顺序中的下一个控件接收焦点)。例如,如果 UseMnemonic 属性设置为 true,并且在控件的 Text 属性中指定助记键字符(“and”符 (&) 之后的第一个字符),则当用户按下 Alt+ 助记键时,焦点移动到 Tab 键顺序中的下一个控件。该功能为窗体提供键盘导航。除了显示文本外,Label 控件还可使用 Image 属性显示图像,或使用 ImageIndex 和 ImageList 属性组合显示图像。

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...
}

参考资料:http://msdn.microsoft.com/zh-cn/library/system.windows.forms.label(VS.80).aspx

本回答被提问者采纳
第2个回答  2009-04-03
直接从工具箱中拖到页面里 设置属性
其中Text是显示的值
第3个回答  2009-04-03
label吗,就跟便贴一样,做标记用