2015-10-13 489 views
0

我有一個列表視圖,我添加了不同大小的圖像,例如。 123x23,23,43等等。 我該如何繼續解決這個問題。我知道listview有一個tilesize屬性,但設置所有瓷磚的一般大小 嘗試與圖像列表,更改圖像列表圖像大小也沒有幫助......繼承人代碼我用來將圖像添加到列表框將不同大小的圖像添加到列表視圖

代碼中的imglist是加載所有所需圖像的圖像列表。

Private Sub frm_load_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
      Form1.ListViewEx1.LargeImageList = imglist 

      For i = 0 To imglist.Images.Count - 1 
       Dim x = Form1.ListViewEx1.Items.Add(New ListViewItem("", i)) 
       x.Tag = imglist.Images.Keys(i).ToString 
      Next 

      Form1.lbl_status1.Text = "Image Count: " & Form1.ListViewEx1.Items.Count 
End sub 

回答

-1

我有同樣的問題。 我發現這個和那對我有用:Click here

Public Sub LoadImageList(ByVal ImagePath As String, ByVal Key As String) 

Dim picImage As Image = Nothing 
Dim final_Bitmap As Bitmap = Nothing 
Dim org_Image As Bitmap = Nothing 

If File.Exists(ImagePath) Then 
     picImage = Image.FromFile(ImagePath) 
'********************* Drawing the Image in proportion to the imagelist Size Here **************** 
     Dim proportion As Integer = 0 
     Dim startx As Decimal = 0 
     Dim startY As Decimal = 0 
     Dim drawwidth As Decimal = 0 
     Dim drawheight As Decimal = 0 
     org_Image = New Bitmap(picImage) 
     final_Bitmap = New Bitmap(ImageList1.ImageSize.Width, ImageList1.ImageSize.Height) 
     Dim gr As Graphics = Graphics.FromImage(final_Bitmap) 
     Dim factorscale As Decimal 
     factorscale = org_Image.Height/org_Image.Width 
     drawwidth = final_Bitmap.Width 
     drawheight = final_Bitmap.Width * factorscale 
     If drawheight > final_Bitmap.Height Then 
       proportion = 1 
       factorscale = org_Image.Width/org_Image.Height 
       drawheight = final_Bitmap.Height 
       drawwidth = final_Bitmap.Height * factorscale 
     End If 
     startx = 0 
     startY = final_Bitmap.Height - drawheight 
     gr.DrawImage(org_Image, startx, startY, drawwidth, drawheight) 
     ImageList1.Images.Add(Key, final_Bitmap) 
     org_Image.Dispose() 
     final_Bitmap.Dispose() 
'************************** End Loading the Image**************** 
End If 

End Sub