ListBox.PreferredHeight-Eigenschaft
Ruft die Gesamthöhe aller Elemente in der ListBox ab.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public ReadOnly Property PreferredHeight As Integer
'Usage
Dim instance As ListBox
Dim value As Integer
value = instance.PreferredHeight
public int PreferredHeight { get; }
public:
property int PreferredHeight {
int get ();
}
/** @property */
public int get_PreferredHeight ()
public function get PreferredHeight () : int
Eigenschaftenwert
Die Gesamthöhe aller Elemente im Steuerelement in Pixel.
Hinweise
Mithilfe dieser Eigenschaft können Sie die Höhe bestimmen, die für die ListBox festgelegt werden muss, damit sämtliche verfügbaren Elemente in der Liste angezeigt werden und die Anzeige vertikaler Bildlaufleisten vermieden wird. Wenn die ListBox eine Vielzahl von Elementen enthält, wird durch eine Größenänderung des Steuerelements mithilfe des Werts der PreferredHeight-Eigenschaft möglicherweise auch die Größe der ListBox so geändert, dass diese den Clientbereich des Formulars oder des ListBox-Containers überschreitet.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie die Size-Eigenschaft einer ListBox auf der Grundlage des Werts der PreferredHeight-Eigenschaft festgelegt wird, um alle Elemente in der ListBox ohne Bildlaufleisten anzuzeigen. Für dieses Beispiel muss dem Formular das ListBox-Steuerelement listBox1
hinzugefügt werden.
Private Sub SizeMyListBox()
' Add items to the ListBox.
Dim x As Integer
For x = 0 To 19
listBox1.Items.Add(("Item " + x.ToString()))
Next x
' Set the height of the ListBox to the preferred height to display all items.
listBox1.Height = listBox1.PreferredHeight
End Sub 'SizeMyListBox
private void SizeMyListBox()
{
// Add items to the ListBox.
for(int x = 0; x < 20; x++)
{
listBox1.Items.Add("Item " + x.ToString());
}
// Set the height of the ListBox to the preferred height to display all items.
listBox1.Height = listBox1.PreferredHeight;
}
private:
void SizeMyListBox()
{
// Add items to the ListBox.
for ( int x = 0; x < 20; x++ )
{
listBox1->Items->Add( String::Format( "Item {0}", x ) );
}
listBox1->Height = listBox1->PreferredHeight;
}
private void SizeMyListBox()
{
// Add items to the ListBox.
for (int x = 0; x < 20; x++) {
listBox1.get_Items().Add("Item " + Convert.ToString(x));
}
// Set the height of the ListBox to the preferred height
// to display all items.
listBox1.set_Height(listBox1.get_PreferredHeight());
} //SizeMyListBox
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ListBox-Klasse
ListBox-Member
System.Windows.Forms-Namespace
Control.Height-Eigenschaft