Label コンストラクタ
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)
構文
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 内)
構文
使用例
Label コントロールの新しいインスタンスを作成および初期化する方法を次の例に示します。
メモ |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script language="VB" runat="server"> Sub Button1_Click(Sender As Object, e As EventArgs) Dim myLabel As New Label() myLabel.Text = "This is a new Label" Page.Controls.Add(myLabel) End Sub </script> </head> <body> <form runat="server"> <h3>Label Example</h3> <asp:Button id="Button1" Text="Create and Show a Label" OnClick="Button1_Click" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script language="C#" runat="server"> void Button1_Click(Object Sender, EventArgs e) { Label myLabel = new Label(); myLabel.Text = "This is a new Label"; Page.Controls.Add(myLabel); } </script> </head> <body> <form runat="server"> <h3>Label Example</h3> <asp:Button id="Button1" Text="Create and Show a Label" OnClick="Button1_Click" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script language="JScript" runat="server"> function Button1_Click(Sender :Object, e : EventArgs) { var myLabel : Label = new Label(); myLabel.Text = "This is a new Label"; Page.Controls.Add(myLabel); } </script> </head> <body> <form runat="server"> <h3>Label Example</h3> <asp:Button id="Button1" Text="Create and Show a Label" OnClick="Button1_Click" runat="server"/> </form> </body> </html>
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 内)
構文
使用例
境界が 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
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... }
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- Label コンストラクタのページへのリンク