Returns the preferred height for a single-line text box.
[Visual Basic] Public ReadOnly Property PreferredHeight As Integer [C#] public int PreferredHeight {get;} [C++] public: __property int get_PreferredHeight(); [JScript] public function get PreferredHeight() : int;
The preferred height of a single-line text box.
The size returned by this property is based on the font height and border style of the text box. You can use this property to determine the appropriate size of the text box to ensure that text is properly displayed in the control. The value returned by this property is in pixels.
The following example uses TextBox, a derived class, to create a text box that can properly display text using a 20 point Arial font with a single border. This example uses the PreferredHeight property to determine the appropriate height of the control after the font and BorderStyle have been assigned.
[Visual Basic]
Public Sub CreateTextBox() ' Create an instance of the TextBox control. Dim Text1 as TextBox Set Text1 = New TextBox ' Set the TextBox Font property to 20 point Arial. Set Text1.Font = New Font ("Arial" , 20) ' Set the BorderStyle property to FixedSingle. Text1.BorderStyle = BorderStyle.FixedSingle ' Make the height of the control equal to the preferred height. Text1.Height = Text1.PreferredHeight End Sub
TextBoxBase Class | TextBoxBase Members | System.WinForms Namespace | AutoSize