TextBoxBase.PreferredHeight プロパティ

単一行テキスト ボックスに最適な高さを取得します。

Public ReadOnly Property PreferredHeight As Integer
[C#]
public int PreferredHeight {get;}
[C++]
public: __property int get_PreferredHeight();
[JScript]
public function get PreferredHeight() : int;

プロパティ値

単一行テキスト ボックスに最適な高さ。

解説

このプロパティから返されるサイズは、テキスト ボックスのフォントの高さと境界線のスタイルに基づいています。このプロパティを使用すると、テキスト ボックスの正しいサイズを判断して、テキストをコントロールに適切に表示できます。このプロパティからの戻り値は、ピクセル単位で表されます。

使用例

[Visual Basic, C#, C++] 派生クラス TextBox を使用して、一重線の境界線で囲まれた 20 ポイントの Arial で表されるテキストを適切に表示するテキスト ボックスの作成例を次に示します。この例では、 PreferredHeight プロパティを使用して、フォントと BorderStyle がコントロールに割り当てられた後のコントロールの適切な高さが判断されます。

 
Public Sub CreateTextBox()
    ' Create an instance of the TextBox control.
    Dim textBox1 As New TextBox()
    ' Set the TextBox Font property to 20-point Arial.
    textBox1.Font = New Font("Arial", 20)
    ' Set the BorderStyle property to FixedSingle.
    textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    ' Make the height of the control equal to the preferred height.
    textBox1.Height = textBox1.PreferredHeight
End Sub


[C#] 
public void CreateTextBox()
 {
    // Create an instance of the TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the TextBox Font property to 20-point Arial.
    textBox1.Font = new Font ("Arial" , 20);
    // Set the BorderStyle property to FixedSingle.
    textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    // Make the height of the control equal to the preferred height.
    textBox1.Height = textBox1.PreferredHeight;
 }
 

[C++] 
public:
void CreateTextBox()
 {
    // Create an instance of the TextBox control.
    TextBox* textBox1 = new TextBox();
    // Set the TextBox Font property to 20-point Arial.
    textBox1->Font = new System::Drawing::Font (S"Arial", 20);
    // Set the BorderStyle property to FixedSingle.
    textBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
    // Make the height of the control equal to the preferred height.
    textBox1->Height = textBox1->PreferredHeight;
 }
 

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

TextBoxBase クラス | TextBoxBase メンバ | System.Windows.Forms 名前空間 | AutoSize