Label.UseMnemonic 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示控件是否将控件 Text 的 属性中的和号字符 (&) 解释为访问键前缀字符。
public:
property bool UseMnemonic { bool get(); void set(bool value); };
public bool UseMnemonic { get; set; }
member this.UseMnemonic : bool with get, set
Public Property UseMnemonic As Boolean
属性值
true
如果标签不显示与号字符,并在其显示的文本中为与号后面的字符下划线,并将带下划线的字符视为访问键,则为 ;否则, false
如果控件的文本中显示与号字符,则为 。 默认值为 true
。
示例
下面的代码示例演示如何创建一个 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
注解
如果 属性UseMnemonic设置为 true
,并且助记符 (前面带有与号) 的字符在 的 Label属性中Text定义,按 Alt+ 键键字符会将焦点设置为 Tab 键顺序中紧跟Label的控件。 可以使用此属性为窗体上的控件提供正确的键盘导航。