Label コンストラクタとは? わかりやすく解説

Label コンストラクタ


Label コンストラクタ

Label クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: 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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Label コンストラクタ

Label クラス新しインスタンス初期化します。

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

解説解説

既定では、ラベルは AutoSize プロパティfalse、および BorderStyle プロパティBorderStyle.None設定された状態で表示されます。

使用例使用例

境界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...
}

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「Label コンストラクタ」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS