ListView.LargeImageList ListView.LargeImageList ListView.LargeImageList ListView.LargeImageList Property

定义

获取或设置当项以大图标在控件中显示时使用的 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.

示例

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

此示例要求您已将代码添加到Form , 并从构造函数或窗体上的其他方法调用在此示例中创建的方法。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. 该示例还要求MySmallImage1名为MyLargeImage1MySmallImage2、和MyLargeImage2的映像位于驱动器 C 的根目录中。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 'CreateMyListView

注解

属性允许您指定一个ImageList对象, 该对象包含在显示带View大图标的项 (当属性设置为LargeIcon时) 时要使用的图标。 LargeImageListThe 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). 控件在显示图标时可以接受ImageList控件支持的任何图形格式。 ListViewThe ListView control can accept any graphics format that the ImageList control supports when displaying icons. ListView控件不限制为 .ico 文件。The ListView control is not limited to .ico files. ImageIndex ListViewItem ListView将分配LargeImageList给属性后, 可以将控件中每个的的属性设置为中ImageList相应图像的索引位置。 ImageListOnce 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. LargeImageList图标的大小ImageSize由指定。The size of the icons for the LargeImageList is specified by the ImageSize.

由于只能为ListViewItem.ImageIndex属性指定一个索引, LargeImageList因此和SmallImageList属性中ImageList指定的对象应具有与要显示的图像相同的索引位置。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. 例如, 如果ImageIndex将的SmallImageList属性ListViewItem设置为 0, 则在LargeImageList和属性中指定的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.

若要设置ImageList在使用小图标显示项 (除之外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.

适用于

另请参阅