Label.AutoSize プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

[LocalizableAttribute(true)] public: virtual property bool AutoSize { bool get () override; void set (bool value) override; }
/** @property */ public boolean get_AutoSize () /** @property */ public void set_AutoSize (boolean value)
public override function get AutoSize () : boolean public override function set AutoSize (value : boolean)
表示内容に合わせてコントロールの幅を調整する場合は true。それ以外の場合は false。既定値は false です。

このプロパティを true に設定すると、内容全体が表示されるように Label の幅が調整されます。Label コントロールを使用して、長さが変化するテキスト (アプリケーション プロセスのステータスなど) を表示する場合は、通常、このプロパティを true に設定します。アプリケーションが各種言語でテキストを表示し、テキスト サイズが Windows の言語設定に基づいて変化する場合も、このプロパティを使用できます。
![]() |
---|
フォントの高さが Label の高さを超えているときに、AutoEllipsis が true の場合、描画するテキストに対し、AutoSize を false に設定する必要があります。 |

AutoSize プロパティのコード例を次に示します。この例を実行するには、次のコードをフォームに貼り付けて、フォームのコンストラクタまたは Load メソッドから InitializeLabel メソッドを呼び出します。
' Declare a label. Friend WithEvents Label1 As System.Windows.Forms.Label ' Initialize the label. Private Sub InitializeLabel() Me.Label1 = New Label Me.Label1.Location = New System.Drawing.Point(10, 10) Me.Label1.Name = "Label1" Me.Label1.TabIndex = 0 ' Set the label to a small size, but set the AutoSize property ' to true. The label will adjust its length so all the text ' is visible, however if the label is wider than the form, ' the entire label will not be visible. Me.Label1.Size = New System.Drawing.Size(10, 10) Me.Controls.Add(Me.Label1) Me.Label1.AutoSize = True Me.Label1.Text = "The text in this label is longer than the set size." End Sub
// Declare a label. internal System.Windows.Forms.Label Label1; // Initialize the label. private void InitializeLabel() { this.Label1 = new Label(); this.Label1.Location = new System.Drawing.Point(10, 10); this.Label1.Name = "Label1"; this.Label1.TabIndex = 0; // Set the label to a small size, but set the AutoSize property // to true. The label will adjust its length so all the text // is visible, however if the label is wider than the form, // the entire label will not be visible. this.Label1.Size = new System.Drawing.Size(10, 10); this.Controls.Add(this.Label1); this.Label1.AutoSize = true; this.Label1.Text = "The text in this label is longer" + " than the set size."; }
// Declare a label. internal: System::Windows::Forms::Label ^ Label1; private: // Initialize the label. void InitializeLabel() { this->Label1 = gcnew Label; this->Label1->Location = System::Drawing::Point( 10, 10 ); this->Label1->Name = "Label1"; this->Label1->TabIndex = 0; // Set the label to a small size, but set the AutoSize property // to true. The label will adjust its length so all the text // is visible, however if the label is wider than the form, // the entire label will not be visible. this->Label1->Size = System::Drawing::Size( 10, 10 ); this->Controls->Add( this->Label1 ); this->Label1->AutoSize = true; this->Label1->Text = "The text in this label is longer" " than the set size."; }
// Declare a label. private System.Windows.Forms.Label label1; // Initialize the label. private void InitializeLabel() { this.label1 = new Label(); this.label1.set_Location(new System.Drawing.Point(10, 10)); this.label1.set_Name("label1"); this.label1.set_TabIndex(0); // Set the label to a small size, but set the AutoSize property // to true. The label will adjust its length so all the text // is visible, however if the label is wider than the form, // the entire label will not be visible. this.label1.set_Size(new System.Drawing.Size(10, 10)); this.get_Controls().Add(this.label1); this.label1.set_AutoSize(true); this.label1.set_Text("The text in this label is longer" + " than the set size."); } //InitializeLabel

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.AutoSize プロパティのページへのリンク