ListBox.MultiColumn 属性

获取或设置一个值,该值指示 ListBox 是否支持多列。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property MultiColumn As Boolean
用法
Dim instance As ListBox
Dim value As Boolean

value = instance.MultiColumn

instance.MultiColumn = value
public bool MultiColumn { get; set; }
public:
property bool MultiColumn {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_MultiColumn ()

/** @property */
public void set_MultiColumn (boolean value)
public function get MultiColumn () : boolean

public function set MultiColumn (value : boolean)

属性值

如果 ListBox 支持多个列,则为 true;否则为 false。默认为 false

异常

异常类型 条件

ArgumentException

多列 ListBox 的高度不能变化。

备注

多列 ListBox 将项放在许多列中,列的数目为不必进行垂直滚动所需的数量。用户可使用键盘定位到当前不可见的列。将 HorizontalScrollbar 属性设置为 true 以显示水平滚动条,使用户得以滚动到在 ListBox 的可见区域中当前未显示的列。ColumnWidth 属性的值确定每列的宽度。

示例

下面的代码示例演示如何使用 ColumnWidthMultiColumn 属性来创建可在多列中显示项的 ListBox 控件。此示例要求已将名为 listBox1ListBox 控件添加到窗体中。

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

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ListBox 类
ListBox 成员
System.Windows.Forms 命名空间
ListBox.HorizontalScrollbar 属性
ListBox.ColumnWidth 属性