列表视图平铺布局问题(vb.net) [英] listview tile layout problem (vb.net)

查看:311
本文介绍了列表视图平铺布局问题(vb.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示(最终)列表视图下它专辑名称一个iTunes播放列表的专辑封面。我遇到的问题是,我不能让专辑封面(目前是空白方块)上面的相册名称。它总是在身边...我怎么办呢?我已经尝试添加列标题和alsorts ...

I have a listview which displays (eventually) an album cover of an itunes play list with the album name under it. the problem I am having is that I cannot get the album art (currently a blank square) ABOVE the album name. It always is on the side... how do I do it? I've tried adding column headers and alsorts...

code设置列表视图

code to set up the listview

    Dim myImageList As ImageList

    albumList.View = View.Tile
    albumList.TileSize = New Size(120, 150)

    ' Initialize the item icons. 
    myImageList = New ImageList()

    myImageList.Images.Add(Image.FromFile("c:/test.jpg"))
    myImageList.ImageSize = New Size(80, 80)
    albumList.LargeImageList = myImageList

然后我做一个循环,以显示它使用的每张专辑名称

I then do a loop to display each album name which uses

        Dim item0 As New ListViewItem(New String() _
                {Albums(i).Name}, 0)

        albumList.Items.Add(item0)

输出的http://i111.photobucket.com/albums/n122/mfacer/Screenshot2010-05-02at164815.png

但正如我所说,我想橙色框下的专辑名称...

but as i said, I want the album name under the orange box....

任何想法?
感谢您的任何信息!

any ideas?? Thanks for any info!

推荐答案

这是烤的瓷砖视图的安排。如果你想在图像下方的标签,那么你的有无的设置视图= LargeIcon。如果产生图像的多余间距,那么你可以P / Invoke的SendMessage()发送LVM_SETICONSPACING消息。这种行之有效:

That is the baked-in arrangement for tile view. If you want the labels underneath the images then you have to set View = LargeIcon. If that produces an undesirable spacing of images then you can P/Invoke SendMessage() to send the LVM_SETICONSPACING message. This worked well:

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class TileView : ListView {
  public TileView() {
    mSpacing = new Size(48, 48);
  }
  private Size mSpacing;
  public Size IconSpacing {
    get { return mSpacing; }
    set {
      mSpacing = value;
      updateSpacing();
    }
  }
  protected override void OnHandleCreated(EventArgs e) {
    base.OnHandleCreated(e);
    updateSpacing();
  }
  private void updateSpacing() {
    if (this.IsHandleCreated) {
      SendMessage(this.Handle, 0x1000 + 53, IntPtr.Zero, (IntPtr)((mSpacing.Height << 16) | mSpacing.Width));
    }
  }
  [DllImport("user32.dll")]
  private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}

更改设计新IconSpacing属性与图像在你的ImageList尺寸很好地工作。你会马上看到效果。

Change the new IconSpacing property in the designer to work well with the size of the images in your ImageList. You'll see the effect immediately.

Public Class TileView
  Inherits ListView

  Public Sub New()
    mSpacing = New Size(48, 48)
  End Sub

  Private mSpacing As Size

  Public Property IconSpacing As Size
    Get
      Return mSpacing
    End Get
    Set(ByVal value As Size)
      mSpacing = value
      updateSpacing()
    End Set
  End Property

  Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
    MyBase.OnHandleCreated(e)
    updateSpacing()
  End Sub

  Private Sub updateSpacing()
    If Me.IsHandleCreated Then
      SendMessageW(Me.Handle, &H1000 + 53, IntPtr.Zero, CType((mSpacing.Height << 16) Or mSpacing.Width, IntPtr))
    End If
  End Sub

  Private Declare Function SendMessageW Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr
End Class

这篇关于列表视图平铺布局问题(vb.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆