Label クラス
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)




System.Web.UI.Control
System.Web.UI.MobileControls.MobileControl
System.Web.UI.MobileControls.TextControl
System.Web.UI.MobileControls.Label


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Label クラス
アセンブリ: System.Web (system.web.dll 内)

<ControlValuePropertyAttribute("Text")> _ Public Class Label Inherits WebControl Implements ITextControl

Label コントロールを使用して、ページの設定位置にテキストを表示します。静的テキストとは異なり、Text プロパティによりテキストの表示をカスタマイズできます。
Literal コントロールと PlaceHolder コントロールを使用して、Web フォーム ページにテキストを表示することもできます。ただし、Label コントロールとは異なり、これらのコントロールは、追加タグは表示しません。
![]() |
---|
このコントロールは、ユーザー入力を表示するために使用できます。ユーザー入力には悪意のあるクライアント スクリプトが含まれている可能性があります。アプリケーションに表示する前に、クライアントから送信された実行スクリプト、SQL ステートメントなどのコードの情報はすべて検証してください。入力テキストをコントロールに表示する前に、検証コントロールを使用してユーザー入力を検証できます。ASP.NET には入力要求の検証機能があり、ユーザー入力の中のスクリプトおよび HTML をブロックできます。詳細については、「標準コントロールのセキュリティ保護」、「方法 : HTML エンコーディングを文字列に適用して Web アプリケーションをスクリプトによる攻略から保護する」、および「ASP.NET Web ページにおけるユーザー入力の検証」を参照してください。 |
ユーザー補助
このコントロールに既定でレンダリングされるマークアップは、Web Content Accessibility Guidelines (WCAG) 1.0 の優先度 1 ガイドラインなどのユーザー補助に関する標準に適合しない可能性があります。このコントロールのユーザー補助サポートの詳細については、「ASP.NET コントロールとユーザー補助」を参照してください。

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>


System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.Label
System.Web.UI.WebControls.BaseValidator


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Label クラス
アセンブリ: 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

通常、Label コントロールは、コントロールについて説明するテキストを表示するために使用されます。たとえば、Label を使用して TextBox コントロールを説明するテキストを追加し、ユーザーがそのコントロールに入力できるデータの型を示すことができます。Label コントロールは、Form に説明テキストを追加し、ユーザーに有用な情報を提供するためにも使用されます。たとえば、Form の上部に Label を追加し、フォーム上のコントロールにデータを入力する方法をユーザーに説明できます。アプリケーションのステータスの実行時情報を表示するためにも Label コントロールを使用できます。たとえば、フォームに Label コントロールを追加し、一連のファイルの処理中に、各ファイルのステータスを表示できます。
Label はフォーム上のタブ オーダーには含まれますが、フォーカスは受け取りません。タブ オーダーの次のコントロールがフォーカスを受け取ります。たとえば、UseMnemonic プロパティが true に設定され、コントロールの Text プロパティにニーモニック文字 (アンパサンド (&) の直後の文字) が指定されている場合、ユーザーが Alt キーを押しながらそのニーモニック キーを押すと、フォーカスはタブ オーダーの次のコントロールに移動します。これにより、キーボードを使用してフォーム上でフォーカスを移動できます。Label コントロールは、テキストを表示するだけではなく、Image プロパティを使用するか、ImageIndex プロパティと ImageList プロパティを組み合わせて使用することによって、イメージも表示できます。
![]() |
---|
Label の BackColor プロパティを 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.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.Label
System.Windows.Forms.LinkLabel


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からLabel クラスを検索する場合は、下記のリンクをクリックしてください。

- Label クラスのページへのリンク