ListView.LargeImageList 属性

定义

获取或设置当项以大图标在控件中显示时使用的 ImageListGets or sets the ImageList to use when displaying items as large icons in the control.

public:
 property System::Windows::Forms::ImageList ^ LargeImageList { System::Windows::Forms::ImageList ^ get(); void set(System::Windows::Forms::ImageList ^ value); };
public System.Windows.Forms.ImageList LargeImageList { get; set; }
member this.LargeImageList : System.Windows.Forms.ImageList with get, set
Public Property LargeImageList As ImageList

属性值

ImageList,包含将 View 属性设置为 LargeIcon 时要使用的图标。An ImageList that contains the icons to use when the View property is set to LargeIcon. 默认值为 nullThe default is null.

示例

下面的代码示例创建一个 @no__t 0 的控件,其中指定了三个 @no__t 对象和三个为每个项指定的 @no__t 2 个对象。The following code example creates a ListView control with three ListViewItem objects specified and three ListViewItem.ListViewSubItem objects specified for each item. 该示例还创建 @no__t 0 对象,以便在详细信息视图中显示子项。The example also creates ColumnHeader objects to display the subitems in details view. 在代码示例中,还会创建两个 @no__t 0 对象,以便为 @no__t 1 对象提供图像。Two ImageList objects are also created in the code example to provide images for the ListViewItem objects. 这些 ImageList 对象将添加到 @no__t 和 @no__t 2 属性。These ImageList objects are added to the LargeImageList and SmallImageList properties. 该示例使用以下属性创建 @no__t 0 控件。The example uses the following properties in creating the ListView control.

此示例要求您已将代码添加到 @no__t 0,并从构造函数或窗体上的其他方法调用在此示例中创建的方法。This example requires that you have added the code to a Form and call the method created in the example from the constructor or another method on the form. 该示例还要求在驱动器 C 的根目录中指定名为 MySmallImage1MySmallImage2、@no__t @no__t)的映像。The example also requires that images named MySmallImage1, MySmallImage2, MyLargeImage1, and MyLargeImage2 are located in the root directory of drive C.

private:
   void CreateMyListView()
   {
      // Create a new ListView control.
      ListView^ listView1 = gcnew ListView;
      listView1->Bounds = Rectangle(Point(10,10),System::Drawing::Size( 300, 200 ));

      // Set the view to show details.
      listView1->View = View::Details;

      // Allow the user to edit item text.
      listView1->LabelEdit = true;

      // Allow the user to rearrange columns.
      listView1->AllowColumnReorder = true;

      // Display check boxes.
      listView1->CheckBoxes = true;

      // Select the item and subitems when selection is made.
      listView1->FullRowSelect = true;

      // Display grid lines.
      listView1->GridLines = true;

      // Sort the items in the list in ascending order.
      listView1->Sorting = SortOrder::Ascending;

      // Create three items and three sets of subitems for each item.
      ListViewItem^ item1 = gcnew ListViewItem( "item1",0 );

      // Place a check mark next to the item.
      item1->Checked = true;
      item1->SubItems->Add( "1" );
      item1->SubItems->Add( "2" );
      item1->SubItems->Add( "3" );
      ListViewItem^ item2 = gcnew ListViewItem( "item2",1 );
      item2->SubItems->Add( "4" );
      item2->SubItems->Add( "5" );
      item2->SubItems->Add( "6" );
      ListViewItem^ item3 = gcnew ListViewItem( "item3",0 );

      // Place a check mark next to the item.
      item3->Checked = true;
      item3->SubItems->Add( "7" );
      item3->SubItems->Add( "8" );
      item3->SubItems->Add( "9" );

      // Create columns for the items and subitems.
      // Width of -2 indicates auto-size.
      listView1->Columns->Add( "Item Column", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 2", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 3", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 4", -2, HorizontalAlignment::Center );

      //Add the items to the ListView.
      array<ListViewItem^>^temp1 = {item1,item2,item3};
      listView1->Items->AddRange( temp1 );

      // Create two ImageList objects.
      ImageList^ imageListSmall = gcnew ImageList;
      ImageList^ imageListLarge = gcnew ImageList;

      // Initialize the ImageList objects with bitmaps.
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage1.bmp" ) );
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage2.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage1.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage2.bmp" ) );

      //Assign the ImageList objects to the ListView.
      listView1->LargeImageList = imageListLarge;
      listView1->SmallImageList = imageListSmall;
      
      // Add the ListView to the control collection.
      this->Controls->Add( listView1 );
   }
private void CreateMyListView()
{
    // Create a new ListView control.
    ListView listView1 = new ListView();
    listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));

    // Set the view to show details.
    listView1.View = View.Details;
    // Allow the user to edit item text.
    listView1.LabelEdit = true;
    // Allow the user to rearrange columns.
    listView1.AllowColumnReorder = true;
    // Display check boxes.
    listView1.CheckBoxes = true;
    // Select the item and subitems when selection is made.
    listView1.FullRowSelect = true;
    // Display grid lines.
    listView1.GridLines = true;
    // Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending;
                
    // Create three items and three sets of subitems for each item.
    ListViewItem item1 = new ListViewItem("item1",0);
    // Place a check mark next to the item.
    item1.Checked = true;
    item1.SubItems.Add("1");
    item1.SubItems.Add("2");
    item1.SubItems.Add("3");
    ListViewItem item2 = new ListViewItem("item2",1);
    item2.SubItems.Add("4");
    item2.SubItems.Add("5");
    item2.SubItems.Add("6");
    ListViewItem item3 = new ListViewItem("item3",0);
    // Place a check mark next to the item.
    item3.Checked = true;
    item3.SubItems.Add("7");
    item3.SubItems.Add("8");
    item3.SubItems.Add("9");

    // Create columns for the items and subitems.
    // Width of -2 indicates auto-size.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

    //Add the items to the ListView.
    listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

    // Create two ImageList objects.
    ImageList imageListSmall = new ImageList();
    ImageList imageListLarge = new ImageList();

    // Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));

    //Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge;
    listView1.SmallImageList = imageListSmall;

    // Add the ListView to the control collection.
    this.Controls.Add(listView1);
}
Private Sub CreateMyListView()
    ' Create a new ListView control.
    Dim listView1 As New ListView()
    listView1.Bounds = New Rectangle(New Point(10, 10), New Size(300, 200))

    ' Set the view to show details.
    listView1.View = View.Details
    ' Allow the user to edit item text.
    listView1.LabelEdit = True
    ' Allow the user to rearrange columns.
    listView1.AllowColumnReorder = True
    ' Display check boxes.
    listView1.CheckBoxes = True
    ' Select the item and subitems when selection is made.
    listView1.FullRowSelect = True
    ' Display grid lines.
    listView1.GridLines = True
    ' Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending

    ' Create three items and three sets of subitems for each item.
    Dim item1 As New ListViewItem("item1", 0)
    ' Place a check mark next to the item.
    item1.Checked = True
    item1.SubItems.Add("1")
    item1.SubItems.Add("2")
    item1.SubItems.Add("3")
    Dim item2 As New ListViewItem("item2", 1)
    item2.SubItems.Add("4")
    item2.SubItems.Add("5")
    item2.SubItems.Add("6")
    Dim item3 As New ListViewItem("item3", 0)
    ' Place a check mark next to the item.
    item3.Checked = True
    item3.SubItems.Add("7")
    item3.SubItems.Add("8")
    item3.SubItems.Add("9")

    ' Create columns for the items and subitems.
    ' Width of -2 indicates auto-size.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

    'Add the items to the ListView.
    listView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

    ' Create two ImageList objects.
    Dim imageListSmall As New ImageList()
    Dim imageListLarge As New ImageList()

    ' Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage1.bmp"))
    imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage2.bmp"))
    imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage1.bmp"))
    imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage2.bmp"))

    'Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge
    listView1.SmallImageList = imageListSmall

    ' Add the ListView to the control collection.
    Me.Controls.Add(listView1)
End Sub

注解

@No__t-0 属性允许您指定一个 @no__t 的对象,该对象包含显示带有大图标的项时要使用的图标(@no__t 2 属性设置为 LargeIcon)。The LargeImageList property allows you to specify an ImageList object that contains icons to use when displaying items with large icons (when the View property is set to LargeIcon). @No__t-0 控件可以接受在显示图标时 @no__t 1 控件支持的任何图形格式。The ListView control can accept any graphics format that the ImageList control supports when displaying icons. @No__t-0 控件不限制为 .ico 文件。The ListView control is not limited to .ico files. 将 @no__t 分配给 LargeImageList 属性后,可以将 ListView 控件中每个 @no__t 的 ImageIndex 属性设置为 @no__t 中相应图像的索引位置。Once an ImageList is assigned to the LargeImageList property, you can set the ImageIndex property of each ListViewItem in the ListView control to the index position of the appropriate image in the ImageList. @No__t 的图标大小是由 @no__t 指定的。The size of the icons for the LargeImageList is specified by the ImageSize.

由于只能为 ListViewItem.ImageIndex 属性指定一个索引,LargeImageList 和 @no__t 属性中指定的 @no__t 对象的索引位置应与要显示的图像的索引位置相同。Because only one index can be specified for the ListViewItem.ImageIndex property, the ImageList objects specified in the LargeImageList and SmallImageList properties should have the same index positions for the images to display. 例如,如果 @no__t 的 @no__t 0 属性设置为0,则用于小图标和大图标的图像应位于 LargeImageListSmallImageList 属性中指定的 ImageList 对象中的同一索引位置。For example, if the ImageIndex property of a ListViewItem is set to 0, the images to use for both small and large icons should be at the same index position in the ImageList objects specified in the LargeImageList and SmallImageList properties.

备注

如果用键指定了图像,则仍需要将图像的小型和大型版本放置在其各自的图像列表中的同一索引位置。When the images are specified with keys, you still need to place small and large versions of the image at the same index location in their respective image lists. 在视图之间切换时,使用一个列表中的图像的索引位置来查找另一个列表中的图像,而不考虑指定的键值。When switching between views, the index location of the image in one list is used to locate the image in the other list, regardless of the key value specified.

若要设置在使用小图标显示项时使用的 @no__t (除 LargeIcon 之外的所有视图模式),请使用 SmallImageList 属性。To set the ImageList to use when displaying items with small icons (all view modes other than LargeIcon), use the SmallImageList property. 如果要使用图像显示项状态,请使用 StateImageList 属性。If you want to use images to display item state, use the StateImageList property.

适用于

另请参阅