ListView iconspacing in dotnet 2.0

Hiya,

I'm looking for a way to set the icon spacing while displaying large icons.
In dotnet 1.1 this could be done by using the SendMessage and setting the variable
LVM_SETICONSPACING. Unfortunately this doesn't work anymore

Anyone suggestions

Sven.


Answer this question

ListView iconspacing in dotnet 2.0

  • lmueller

    The following works fine for me using Visual Studio 2005:

    Imports System.Runtime.InteropServices

    Public Class MyForm

    <DllImport("User32.dll")> Private Shared Function SendMessage( ByVal Handle As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

    End Function

    Const LVM_FIRST = &H1000

    ...

    Public Sub ListViewSetSpacing(ByVal LView As ListView, ByVal x As Integer, ByVal y As Integer)

    Dim i As Integer

    i = (y * 65536) + (x And 65535)

    Call SendMessage(LView.Handle, LVM_FIRST + 53, 0, i)

    End Sub

    'e.g.

    ListViewSetSpacing(Me.MyListView, 80, 120)

    ...

    End Class


  • Paul Carmichael

    Strange - this code works fine for us in VS 2003/.NET 1.1 but not in VS2005/.NET 2.0.
    (8.0.50727.42 / 2.0.50727)

    Using View.Tile and TileSize comes close, but I want the label below the icon.

    Any more ideas, anyone I'd like to be able to set icon spacing for ListView in .NET 2.0. There's nothing of any use in Google groups at this date.

    Thanks and regards



  • CDO

    Can you post the demo C# project on how to use LVM_SETICONSPACING


  • Steve Greatrex

    It seems that doing a SendMessage with LVM_SETICONSPACING only works after the control has become visible. In C# I added this delegate to set the icon spacing for a ListView and this code works for me in .NET 1.1 and .NET 2.0 using the ListViewSetSpacing method above from nrb1955:

    /// Create the ListView
    ...
    listView.VisibleChanged += new EventHandler(listView_VisibleChanged);
    ...

    /// <summary>
    /// When the list view is first shown then set the spacing, otherwise it's ignored
    /// in .NET 2.0 until the the style is changed to Small and back to Large icons again.
    /// </summary>
    void listView_VisibleChanged(object sender, EventArgs e) {
    listView.VisibleChanged -= new EventHandler(listView_VisibleChanged);
    ListViewSetSpacing(listView, 80, 96);
    }


  • ListView iconspacing in dotnet 2.0