次の方法で共有


Label.UseMnemonic プロパティ

コントロールの Text プロパティに含まれるアンパサンド文字 (&) をアクセス キーの接頭文字として解釈するかどうかを示す値を取得または設定します。

Public Property UseMnemonic As Boolean
[C#]
public bool UseMnemonic {get; set;}
[C++]
public: __property bool get_UseMnemonic();public: __property void set_UseMnemonic(bool);
[JScript]
public function get UseMnemonic() : Boolean;public function set UseMnemonic(Boolean);

プロパティ値

ラベルのテキストにアンパサンド文字を表示せずに、アンパサンドの直後の文字に下線を付け、その下線付き文字をアクセス キーとして扱う場合は true 。アンパサンド文字をそのままコントロールのテキストに表示する場合は false 。既定値は true です。

解説

UseMnemonic プロパティが true に設定され、 LabelText プロパティにニーモニック文字 (アンパサンドの直後の文字) が定義されている場合は、Alt キーを押しながらそのニーモニック文字を押すと、タブ オーダーで Label の次のコントロールにフォーカスが設定されます。このプロパティを使用すると、キーボードを使ってフォーム上のコントロールにフォーカスを移動できます。

使用例

3 次元の輪郭と、 ImageList プロパティおよび ImageIndex プロパティを使用して表示するイメージを持つ Label コントロールの作成方法の例を次に示します。このコントロールには、ニーモニック文字を指定したキャプションも表示されます。このコードの例では、 PreferredHeight プロパティと PreferredWidth プロパティを使用して、表示するフォーム上の Label コントロールのサイズを適切に設定します。また、この例は、 imageList1 という名前の ImageList が作成され、2 つのイメージが読み込まれていることを前提にしています。このコードがフォーム内にあり、そのフォームのコードに System.Drawing 名前空間が追加されていることも前提にしています。

 
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


[C#] 
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...
}


[C++] 
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 = S"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...
 }
 

[JScript] 
public function CreateMyLabel()
{
   // Create an instance of a Label.
   var label1 : Label = 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 System.Drawing.Size (label1.PreferredWidth, label1.PreferredHeight);

   //...Code to add the control to the form...
}

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Label クラス | Label メンバ | System.Windows.Forms 名前空間 | Control.Text