显示缩略图标128×128像素或更大,在ListView的网格 [英] Displaying thumbnail icons 128x128 pixels or larger in a grid in ListView

查看:408
本文介绍了显示缩略图标128×128像素或更大,在ListView的网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始的问题(参见下面的更新)

我有一个WinForms程序,需要与大图标一个体面的可滚动图标控制(128×128或更大的缩略图真的),可单击以高亮或双单击以执行某些操作。 preferably会有最少浪费的空间(可能需要每一个图标的下方短文件名字幕;如果文件名太长,我可以添加一个省略号)。

我试着用用LargeIcon(默认.View),一个ListView,结果令人失望:

也许我填充控制不当? code:

  ImageList中的IList =新的ImageList();
this.listView.LargeImageList = IList的;
INT I = 0;
的foreach(在gc.files GradorCacheFile GCF)
{
位图B = gcf.image128;
ilist.Images.Add(二);
ListViewItem的LVI =新的ListViewItem(文字);
lvi.ImageIndex = I;
this.listView.Items.Add(LVI);
我++;
}

我需要很少的空空间,尴尬小图标并不大空大图标。


  1. 是否有一个.NET控件,它我需要什么?

  2. 有没有做到这一点?
  3. 最喜欢的第三方控件
  4. 如果不是,它控制将是最好的继承和调整,使其工作?

  5. 我应该打破,使自定义控制(我有足够的经验......只是不想去那个极端,因为这是较为复杂)。

我发现本教程中有关的OwnerDraw 而是从工作基本上相当于数3或4以上,因为这只是演示了如何来调剂行的详细信息视图。

更新

添加行

  ilist.ImageSize =新的大小(128,128);

在for循环固定大小的问题,但现在的图像是调色板化,以8位(貌似系统颜色?)尽管调试器显示图像插入到ImageList中为24 bpp的System.Drawing.Bitmap的


  1. 如何(可以吗?),使图像显示的完整的24位色?

  2. 图标周围的间距仍相当浪费...我怎么解决这个问题?可以吗?

更新2

随着加入行

  ilist.ColorDepth = ColorDepth.Depth24Bit;

一个设置ilist.ImageSize后,我跟着仲裁者的建议,改变了间距:

 函数[DllImport(user32.dll中)]
公共静态外部的IntPtr SendMessage函数(IntPtr的的HWND,UINT消息,IntPtr的的wParam,lParam的IntPtr的);公众诠释MAKELONG(短lowPart,短highPart)
{
    回报(INT)(((USHORT)lowPart)|(UINT)(highPart<< 16));
}公共无效ListView_SetSpacing(ListView控件列表视图,CX短,短CY)
{
    const int的LVM_FIRST = 0x1000的;
    const int的LVM_SETICONSPACING = LVM_FIRST + 53;
    // http://msdn.microsoft.com/en-us/library/bb761176(VS.85).aspx
    //最小间距= 4
    SendMessage函数(listview.Handle,LVM_SETICONSPACING,
    IntPtr.Zero,(IntPtr的)MAKELONG(CX,CY));    // http://msdn.microsoft.com/en-us/library/bb775085(VS.85).aspx
    //不行!
    //不能在DLL中找到COMCTL32.DLL ListView_SetIconSpacing
    //ListView_SetIconSpacing(listView.Handle,5,5);
}////////////////////////////////////////////////// /////////ListView_SetSpacing(this.listView,128 + 12,128 + 4 + 20);

ListView控件可能不是完美的或有我期望的默认值(如间距属性),但我很高兴我能驯服它,到底:

顺便说一句,维持缩略图适当的宽高比,我不得不让我自己128x128的位图,清除背景相匹配的控制,和中心这些图像:

 公共无效CenterDrawImage(位图对象,彩色背景,位图centerme)
{
    图形G = Graphics.FromImage(目标);
    g.Clear(背景);
    INT X =(target.Width - centerme.Width)/ 2;
    INT Y =(target.Height - centerme.Height)/ 2;
    g.DrawImage(centerme,X,Y);
    g.Dispose();
}


解决方案

有关更新:


  1. 设置图片列表颜色深度,除了图像尺寸(ilist.ColorDepth = ColorDepth.Depth24Bit)

  2. 的WinForms ListView控件没有可能改变图标的​​间距,但它可以使用Win32轻松完成。您需要发送 LVM_SETICONSPACING 您的ListView(有很多的教程如何使用SendMessage函数Win32函数在.NET中,所以我觉得这个方向必须够你)。

Original Question (see Update below)

I have a WinForms program that needs a decent scrollable icon control with large icons (128x128 or larger thumbnails, really) that can be clicked to hilight or double clicked to perform some action. Preferably there would be minimal wasted space (short filename captions might be needed below each icon; if the filename is too long I can add an ellipsis).

I tried using a ListView with LargeIcon (default .View) and the results are disappointing:

Perhaps I am populating the control incorrectly? Code:

		ImageList ilist = new ImageList();
		this.listView.LargeImageList = ilist;
		int i = 0;
		foreach (GradorCacheFile gcf in gc.files)
		{
			Bitmap b = gcf.image128;
			ilist.Images.Add(b);
			ListViewItem lvi = new ListViewItem("text");
			lvi.ImageIndex = i;
			this.listView.Items.Add(lvi);
			i++;
		}

I need large icons with little empty space, not large empty space with embarrassingly small icons.

  1. Is there a .NET control that does what I need?
  2. Is there a favorite third party control that does this?
  3. If not, which control would be best to inherit and tweak to make it work?
  4. Should I break down and make a custom Control (which I have plenty of experience with... just don't want to go to that extreme since that is somewhat involved).

I found this tutorial about OwnerDraw but work from that basically amounts to number 3 or 4 above since that demo just shows how to spice up the rows in the details view.

Update

Adding the line

ilist.ImageSize = new Size(128, 128);

before the for loop fixed the size problem but now the images are palette-ized to 8-bit (looks like system colors?) even though the debugger shows that the images are inserted into the ImageList as 24bpp System.Drawing.Bitmap's:

  1. How do I (can I?) make the images show in full 24 bit color?
  2. The spacing around the icons is still rather wasteful... how do I fix that? Can I?

Update 2

Along with adding the line

ilist.ColorDepth = ColorDepth.Depth24Bit;

next after setting ilist.ImageSize, I followed arbiter's advice and changed the spacing:

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

public int MakeLong(short lowPart, short highPart)
{
    return (int)(((ushort)lowPart) | (uint)(highPart << 16));
}

public void ListView_SetSpacing(ListView listview, short cx, short cy)
{
    const int LVM_FIRST = 0x1000;
    const int LVM_SETICONSPACING = LVM_FIRST + 53;
    // http://msdn.microsoft.com/en-us/library/bb761176(VS.85).aspx
    // minimum spacing = 4
    SendMessage(listview.Handle, LVM_SETICONSPACING,
    IntPtr.Zero, (IntPtr)MakeLong(cx, cy));

    // http://msdn.microsoft.com/en-us/library/bb775085(VS.85).aspx
    // DOESN'T WORK!
    // can't find ListView_SetIconSpacing in dll comctl32.dll
    //ListView_SetIconSpacing(listView.Handle, 5, 5);
}

///////////////////////////////////////////////////////////

ListView_SetSpacing(this.listView, 128 + 12, 128 + 4 + 20);

The ListView control may not be perfect or have the defaults I'd expect (like a Spacing property) but I'm glad I could tame it, in the end:

By the way, to maintain the proper aspect ratio for the thumbnails, I had to make my own 128x128 bitmaps, clear the background to match the control, and center those images:

public void CenterDrawImage(Bitmap target, Color background, Bitmap centerme)
{
    Graphics g = Graphics.FromImage(target);
    g.Clear(background);
    int x = (target.Width - centerme.Width) / 2;
    int y = (target.Height - centerme.Height) / 2;
    g.DrawImage(centerme, x, y);
    g.Dispose();
}

解决方案

For update:

  1. Set image list color depth in addition to image size (ilist.ColorDepth = ColorDepth.Depth24Bit)
  2. WinForms ListView does not have possibility to change icon spacing, however it can be easily done using Win32. You need to send LVM_SETICONSPACING to your ListView (there is a lot of tutorials how to use SendMessage win32 function in .net, so I think this direction must be enough for you).

这篇关于显示缩略图标128×128像素或更大,在ListView的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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