Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft die Spaltenbreite in einer mehrspaltigen ListBox ab oder legt diese fest.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
<LocalizableAttribute(True)> _
Public Property ColumnWidth As Integer
'Usage
Dim instance As ListBox
Dim value As Integer
value = instance.ColumnWidth
instance.ColumnWidth = value
[LocalizableAttribute(true)]
public int ColumnWidth { get; set; }
[LocalizableAttribute(true)]
public:
property int ColumnWidth {
int get ();
void set (int value);
}
/** @property */
public int get_ColumnWidth ()
/** @property */
public void set_ColumnWidth (int value)
public function get ColumnWidth () : int
public function set ColumnWidth (value : int)
Eigenschaftenwert
Die Breite der einzelnen Spalten des Steuerelements in Pixel. Der Standardwert ist 0.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
Der Eigenschaft ist ein Wert zugewiesen, der kleiner als 0 ist. |
Hinweise
Wenn Sie den Wert auf 0 festlegen, wird jeder Spalte eine Standardbreite zugewiesen. Wenn die ListBox eine mehrspaltige ListBox ist, gibt diese Eigenschaft die aktuelle Breite der einzelnen Spalten in der Liste zurück. Mit dieser Eigenschaft können Sie sicherstellen, dass die Elemente in den einzelnen Spalten einer mehrspaltigen ListBox richtig angezeigt werden können.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie mit der ColumnWidth-Eigenschaft und der MultiColumn-Eigenschaft ein ListBox-Steuerelement erstellt wird, in dem Elemente in mehreren Spalten angezeigt werden. Für dieses Beispiel muss dem Formular das ListBox-Steuerelement listBox1 hinzugefügt werden.
Private Sub SetupMyMultiColumn()
Dim x As Integer
' Add items to the ListBox.
For x = 0 To 50
ListBox1.Items.Add("Items " + x.ToString())
Next x
' Display items in columns.
ListBox1.MultiColumn = True
' Determine the width of the items in the list to get the best column width setting.
Dim width As Integer = CInt(ListBox1.CreateGraphics().MeasureString(ListBox1.Items(ListBox1.Items.Count - 1).ToString(), _
ListBox1.Font).Width)
' Set the column width based on the width of each item in the list.
ListBox1.ColumnWidth = width
End Sub
private void SetupMyMultiColumn()
{
// Add items to the ListBox.
for (int x = 0; x < 50; x++)
{
listBox1.Items.Add("Items " + x.ToString());
}
// Display items in columns.
listBox1.MultiColumn = true;
// Determine the width of the items in the list to get the best column width setting.
int width = (int) listBox1.CreateGraphics().MeasureString(listBox1.Items[listBox1.Items.Count -1].ToString(),
listBox1.Font).Width;
// Set the column width based on the width of each item in the list.
listBox1.ColumnWidth = width;
}
private:
void SetupMyMultiColumn()
{
// Add items to the ListBox.
for ( int x = 0; x < 50; x++ )
{
listBox1->Items->Add( String::Format( "Items {0}", x ) );
}
listBox1->MultiColumn = true;
// Determine the width of the items in the list to get the best column width setting.
int width = (int)listBox1->CreateGraphics()->MeasureString( listBox1->Items[ listBox1->Items->Count - 1 ]->ToString(), listBox1->Font ).Width;
// Set the column width based on the width of each item in the list.
listBox1->ColumnWidth = width;
}
private void SetupMyMultiColumn()
{
// Add items to the ListBox.
for (int x = 0; x < 50; x++) {
listBox1.get_Items().Add("Items " + System.Convert.ToString(x));
}
// Display items in columns.
listBox1.set_MultiColumn(true);
// Determine the width of the items in the list to get the best column
// width setting.
int width = (int)(listBox1.CreateGraphics().MeasureString(listBox1.
get_Items().get_Item((listBox1.get_Items().get_Count() - 1)).
ToString(), listBox1.get_Font()).get_Width());
// Set the column width based on the width of each item in the list.
listBox1.set_ColumnWidth(width);
} //SetupMyMultiColumn
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