Bagikan melalui


ListBox.PreferredHeight Properti

Definisi

Mendapatkan tinggi gabungan dari semua item di ListBox.

public:
 property int PreferredHeight { int get(); };
[System.ComponentModel.Browsable(false)]
public int PreferredHeight { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PreferredHeight : int
Public ReadOnly Property PreferredHeight As Integer

Nilai Properti

Tinggi gabungan, dalam piksel, dari semua item dalam kontrol.

Atribut

Contoh

Contoh kode berikut menunjukkan cara mengatur Size properti dari ListBox berdasarkan nilai PreferredHeight properti untuk menampilkan semua item dalam ListBox tanpa menggunakan bilah gulir. Contoh ini mengharuskan ListBox kontrol, bernama listBox1, telah ditambahkan ke formulir.

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.Items.Add("Item " + x.ToString());
   }
   // Set the height of the ListBox to the preferred height to display all items.
   listBox1.Height = listBox1.PreferredHeight;
}
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

Keterangan

Properti ini memungkinkan Anda menentukan tinggi yang ListBox perlu diukur, untuk menampilkan setiap item yang tersedia dalam daftar dan untuk menghindari tampilan bilah gulir vertikal. Jika jumlah item dalam ListBox besar, ukuran kontrol menggunakan nilai PreferredHeight properti dapat menyebabkan ListBox ukuran di luar area klien formulir atau ListBox kontainer.

Berlaku untuk

Lihat juga