Bagikan melalui


ListBox.IntegralHeight Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah kontrol harus mengubah ukuran untuk menghindari menampilkan item parsial.

public:
 property bool IntegralHeight { bool get(); void set(bool value); };
public bool IntegralHeight { get; set; }
member this.IntegralHeight : bool with get, set
Public Property IntegralHeight As Boolean

Nilai Properti

true jika kontrol mengubah ukuran sehingga tidak menampilkan item parsial; jika tidak, false. Defaultnya adalah true.

Contoh

Contoh kode berikut menunjukkan cara menggunakan HorizontalScrollbar properti dan HorizontalExtent untuk menampilkan bilah gulir horizontal yang memperlihatkan semua teks item dalam ListBox kontrol. Contoh ini juga menggunakan IntegralHeight properti untuk memastikan bahwa item tidak ditampilkan sebagian karena ukuran ListBox kontrol. Contoh ini mengharuskan ListBox kontrol, bernama listBox1, telah ditambahkan ke formulir.

private:
   void DisplayHScroll()
   {
      // Make sure no items are displayed partially.
      listBox1->IntegralHeight = true;

      // Add items that are wide to the ListBox.
      for ( int x = 0; x < 10; x++ )
      {
         listBox1->Items->Add( String::Format( "Item {0} is a very large value that requires scroll bars", x ) );

      }

      // Display a horizontal scroll bar.
      listBox1->HorizontalScrollbar = true;

      // Create a Graphics object to use when determining the size of the largest item in the ListBox.
      Graphics^ g = listBox1->CreateGraphics();

      // Determine the size for HorizontalExtent using the MeasureString method using the last item in the list.
      int hzSize = (int)g->MeasureString( dynamic_cast<String^>(listBox1->Items[ listBox1->Items->Count - 1 ]), listBox1->Font ).Width;

      // Set the HorizontalExtent property.
      listBox1->HorizontalExtent = hzSize;
   }
private void DisplayHScroll()
{
   // Make sure no items are displayed partially.
   listBox1.IntegralHeight = true;

   // Add items that are wide to the ListBox.
   for (int x = 0; x < 10; x++)
   {
      listBox1.Items.Add("Item  " + x.ToString() + " is a very large value that requires scroll bars");
   }

   // Display a horizontal scroll bar.
   listBox1.HorizontalScrollbar = true;

   // Create a Graphics object to use when determining the size of the largest item in the ListBox.
   Graphics g = listBox1.CreateGraphics();

   // Determine the size for HorizontalExtent using the MeasureString method using the last item in the list.
   int hzSize = (int) g.MeasureString(listBox1.Items[listBox1.Items.Count -1].ToString(),listBox1.Font).Width;
   // Set the HorizontalExtent property.
   listBox1.HorizontalExtent = hzSize;
}
Private Sub DisplayHScroll()
     ' Make sure no items are displayed partially.
   listBox1.IntegralHeight = True
   Dim x As Integer

   ' Add items that are wide to the ListBox.
   For x = 0 To 10
      listBox1.Items.Add("Item  " + x.ToString() + " is a very large value that requires scroll bars")
   Next x

   ' Display a horizontal scroll bar.
   listBox1.HorizontalScrollbar = True

   ' Create a Graphics object to use when determining the size of the largest item in the ListBox.
   Dim g As System.Drawing.Graphics = listBox1.CreateGraphics()


   ' Determine the size for HorizontalExtent using the MeasureString method using the last item in the list.
   Dim hzSize As Integer = g.MeasureString(listBox1.Items(listBox1.Items.Count - 1).ToString(), listBox1.Font).Width
   ' Set the HorizontalExtent property.
   listBox1.HorizontalExtent = hzSize
End Sub

Keterangan

Ketika properti ini diatur ke true, kontrol secara otomatis mengubah ukuran untuk memastikan bahwa item tidak ditampilkan sebagian. Jika Anda ingin mempertahankan ukuran ListBox asli berdasarkan persyaratan ruang formulir Anda, atur properti ini ke false.

Secara default, ListBox dan ukurannya CheckedListBox sih sehingga hanya menampilkan seluruh item. Jika Anda ingin ListBox atau CheckedListBox mengisi area yang ditampung sepenuhnya, atur IntegralHeight ke false. Hal ini menyebabkan kontrol mengisi area sepenuhnya, tetapi item terakhir tidak sepenuhnya ditampilkan.

ListBox Jika tidak berisi item apa pun, properti ini tidak berpengaruh.

Nota

Tinggi integral didasarkan pada tinggi ListBox, bukan tinggi area klien. Akibatnya, ketika IntegralHeight properti diatur true, item masih dapat ditampilkan sebagian jika bilah gulir ditampilkan.

Nota

DrawMode Jika properti diatur ke DrawMode.OwnerDrawVariable, properti ini tidak berpengaruh.

Berlaku untuk

Lihat juga