2016-02-01 89 views
1

sample requirement image當winform中的水平空間結束時,我需要將圖像包裝到下一行。但只顯示垂直的圖像,請建議一些方法來實現這一目標?如何在winforms listview中打包圖像?

border_listview.Location = new Point(10, 35); 
border_listbox.Size=new System.Drawing.Size(123,123); 
border_listview.BorderStyle = BorderStyle.FixedSingle; 
// border_listview.MultiColumn = true; 
// var colel=new ImageCollection(); 
var image1=new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.NoneLineStyle.png")); 
var image3 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle2.png")); 
var image2 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle1.png")); 
var image4 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle3.png")); 
var image5 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle4.png")); 
var image6 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle5.png")); 
var image7 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle6.png")); 
var image8 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle7.png")); 
var image9 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle8.png")); 
var image10 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle9.png")); 
var image11 = new Bitmap(typeof(SfSpreadsheet).Assembly.GetManifestResourceStream("Syncfusion.Windows.Forms.Spreadsheet.Resources.FormatCellsIcons.LineStyle10.png")); 
var list = new ImageList(); 
list.ImageSize = new System.Drawing.Size(50, 10); 
list.Images.AddRange(new Image[] { image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, image11 }); 
border_listview.SmallImageList = list;   
border_listview.View = View.SmallIcon; 
border_listview.Scrollable = false;   

for (int j = 0; j < list.Images.Count; j++) 
{ 
    var item = new ListViewItem(); 
    item.ImageIndex = j; 
    border_listview.Items.Add(item); 
} 

回答

2

您可以使用ListView使用這些設置:

  • 設置View到瓷磚
  • 使用LargeImageList
  • 設置TileSize基於圖像列表ImageSize
  • Alignment對左邊,所以項目將首先填充列,然後到下一列。
  • Scrollable設置爲false,以隱藏可能的滾動條。
  • 添加一些項目併爲項目設置ImageKey/ImageIndex。
  • 您的ListView
  • 使用合適的尺寸

enter image description here enter image description here

+0

由於它的工作如預期,但多了一個要求是所選擇的項目沒有顯示任何邊界,這使得背景顏色爲藍色,但它不是明確識別選定的項目 –