Label クラスとは? わかりやすく解説

Label クラス

モバイル デバイステキスト表示するためのラベル コントロールを表すコントロール機能提供します

名前空間: System.Web.UI.MobileControls
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)
構文構文

Public Class Label
    Inherits TextControl
public class Label : TextControl
public ref class Label : public
 TextControl
public class Label extends TextControl
public class Label extends
 TextControl
解説解説
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.MobileControls.MobileControl
       System.Web.UI.MobileControls.TextControl
        System.Web.UI.MobileControls.Label
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Label クラス

Web ページテキスト表示するラベル コントロール表します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<ControlValuePropertyAttribute("Text")> _
Public Class Label
    Inherits WebControl
    Implements ITextControl
[ControlValuePropertyAttribute("Text")] 
public class Label : WebControl, ITextControl
[ControlValuePropertyAttribute(L"Text")] 
public ref class Label : public
 WebControl, ITextControl
/** @attribute ControlValuePropertyAttribute("Text") */ 
public class Label extends WebControl implements
 ITextControl
ControlValuePropertyAttribute("Text") 
public class Label extends
 WebControl implements ITextControl
解説解説

Label コントロール使用してページ設定位置テキスト表示します静的テキストとは異なりText プロパティによりテキスト表示カスタマイズできます

Literal コントロールと PlaceHolder コントロール使用してWeb フォーム ページテキスト表示することもできます。ただし、Label コントロールとは異なり、これらのコントロールは、追加タグ表示しません。

注意に関するメモ注意

このコントロールは、ユーザー入力表示するために使用できますユーザー入力には悪意のあるクライアント スクリプト含まれている可能性ありますアプリケーション表示する前にクライアントから送信され実行スクリプトSQL ステートメントなどのコード情報はすべて検証してください入力テキストコントロール表示する前に検証コントロール使用してユーザー入力検証できますASP.NET には入力要求検証機能があり、ユーザー入力の中のスクリプトおよび HTMLブロックできます詳細については、「標準コントロールセキュリティ保護」、「方法 : HTML エンコーディング文字列適用して Web アプリケーションスクリプトによる攻略から保護する」、および「ASP.NET Web ページにおけるユーザー入力検証」を参照してください

ユーザー補助

TopicLocation
チュートリアル : Visual Web Developer での ASP.NET マスタ ページ作成使用Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : Visual Web Developer でのコード分離使用した基本的な Web ページ作成Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : Visual Web Developer での基本的な Web ページ作成Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : Web サーバー コントロール用の基本的なコントロール デザイナ作成ASP.NET コントロール作成
チュートリアル : Web フォーム ページにおけるユーザー入力検証Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル : カスタム ビジネス オブジェクトへのデータ バインディングVisual Studio での ASP .NET Web アプリケーション作成
チュートリアル : テーマ使用した Web サイトカスタマイズVisual Studio での ASP .NET Web アプリケーション作成
チュートリアル : ユーザー補助対応の Web アプリケーション作成Visual Studio での ASP .NET Web アプリケーション作成
チュートリアル: Visual Web Developer でのカスケード スタイル シートスタイル操作Visual Studio での ASP .NET Web アプリケーション作成
方法 : ASP.NET Web ページコントロールプログラムによって追加するASP .NET Web アプリケーション作成
方法 : Calendar Web サーバー コントロールにおける日単位カスタマイズASP .NET Web アプリケーション作成
方法 : DataList Web サーバー コントロールテンプレート動的に作成するASP .NET Web アプリケーション作成
方法 : Web フォーム ページLabel Web サーバー コントロール追加するASP .NET Web アプリケーション作成
方法 : Web フォーム ページLabel Web サーバー コントロール追加する (Visual Studio)Visual Studio での ASP .NET Web アプリケーション作成
方法 : キャプションとして Label Web サーバー コントロール使用するASP .NET Web アプリケーション作成
使用例使用例

Web ページLabel コントロール作成する方法次の例に示します

メモメモ

次のコード サンプルはシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード サンプルは、拡張子.aspx の空のテキスト ファイルコピーする必要がありますWeb フォームコード モデル詳細については、「ASP.NET Web ページコード モデル」を参照してください

<%@ Page Language="VB" AutoEventWireup="True"
 %>
<html>
<head>

   <script language="VB" runat="server">

      Sub Button_Click(Sender As Object,
 e As EventArgs) 
         Label1.Text = Server.HtmlEncode(Text1.Text)
      End Sub

   </script>

</head>

<body>

   <form id="Form1" runat="server">

      <h3>Label Example</h3>

      <asp:Label id="Label1" 
                 Text="Label Control" 
                 runat="server"/>

      <p>
        
      <asp:TextBox id="Text1" 
           Text="Copy this text to the label"
           Width="200px"  
           runat="server" />

      <asp:Button id="Button1" 
           Text="Copy" 
           OnClick="Button_Click" 
           runat="server"/>
      </p>
   </form>

</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

   <script language="C#" runat="server">

      void Button_Click(Object Sender, EventArgs e) 
      {
         Label1.Text = Server.HtmlEncode(Text1.Text);
      }

   </script>

</head>

<body>

   <form id="Form1" runat="server">

      <h3>Label Example</h3>

      <asp:Label id="Label1" 
                 Text="Label Control" 
                 runat="server"/>

      <p>
        
      <asp:TextBox id="Text1" 
           Text="Copy this text to the label"
           Width="200px"  
           runat="server" />

      <asp:Button id="Button1" 
           Text="Copy" 
           OnClick="Button_Click" 
           runat="server"/>
      </p>

   </form>

</body>
</html>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.Label
         System.Web.UI.WebControls.BaseValidator
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Label クラス

標準Windows ラベル表します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class Label
    Inherits Control
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class Label : Control
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class Label : public
 Control
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Label extends Control
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class Label extends
 Control
解説解説

通常Label コントロールは、コントロールについて説明するテキスト表示するために使用されます。たとえば、Label使用して TextBox コントロール説明するテキスト追加しユーザーがそのコントロール入力できるデータの型を示すことができますLabel コントロールは、Form説明テキスト追加しユーザー有用な情報提供するためにも使用されます。たとえば、Form の上部に Label追加しフォーム上のコントロールデータ入力する方法ユーザー説明できますアプリケーションステータス実行時情報表示するためにも Label コントロール使用できます。たとえば、フォームLabel コントロール追加し一連のファイル処理中に、各ファイルステータス表示できます

Labelフォーム上のタブ オーダーには含まれますが、フォーカス受け取りません。タブ オーダー次のコントロールフォーカス受け取ります。たとえば、UseMnemonic プロパティtrue設定されコントロールText プロパティニーモニック文字 (アンパサンド (&) の直後文字) が指定されている場合ユーザーAlt キー押しながらそのニーモニック キーを押すと、フォーカスタブ オーダー次のコントロール移動します。これにより、キーボード使用してフォーム上でフォーカス移動できますLabel コントロールは、テキスト表示するだけではなくImage プロパティ使用するか、ImageIndex プロパティImageList プロパティ組み合わせて使用することによって、イメージ表示できます

メモメモ

LabelBackColor プロパティColor.Transparent設定すると、ラベル透明にすることができます。透明のラベル使用する場合は、現在のデバイス座標系だけを使用してコンテナ上に描画ます。他のデバイス座標系を使用すると、Label後ろにあるコントロール適切に描画されない場合あります

使用例使用例

境界線3 次元で、イメージ表示する Label コントロール作成方法次のコード例示しますイメージImageList プロパティImageIndex プロパティ使用して表示されます。このコントロールには、ニーモニック文字指定したキャプション表示されます。このコードの例では、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

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:
   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.set_BorderStyle(System.Windows.Forms.BorderStyle.Fixed3D);
    // Set the ImageList to use for displaying an image.
    label1.set_ImageList(imageList1);
    // Use the second image in imageList1.
    label1.set_ImageIndex(1);
    // Align the image to the top left corner.
    label1.set_ImageAlign(ContentAlignment.TopLeft);
    // Specify that the text can display mnemonic characters.
    label1.set_UseMnemonic(true);
    // Set the text of the control and specify a mnemonic character.
    label1.set_Text("First &Name:");
    /* Set the size of the control based on the PreferredHeight
       and PreferredWidth values. */
    label1.set_Size(new Size(label1.get_PreferredWidth(), 
        label1.get_PreferredHeight()));
    //...Code to add the control to the form...
} //CreateMyLabel 
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...
}

継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.Label
           System.Windows.Forms.LinkLabel
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からLabel クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からLabel クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からLabel クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Label クラス」の関連用語

Label クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Label クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS