public static void AdjustTileToWidth(this ListView lvw, int maxLines = 1, int iconSpacing = 4)
        {
            const string str      = "Wg";
            var          lvTVInfo = new NativeMethods.LVTILEVIEWINFO(0)
            {
                IconTextSpacing = iconSpacing, MaxTextLines = maxLines
            };
            var sb = new StringBuilder(str);

            for (int i = 0; i < maxLines; i++)
            {
                sb.Append("\r" + str);
            }
            using (Graphics g = lvw.CreateGraphics())
                lvTVInfo.TileSize = new Size(lvw.ClientSize.Width, Math.Max(lvw.LargeImageList.ImageSize.Height, TextRenderer.MeasureText(g, sb.ToString(), lvw.Font).Height));
            NativeMethods.SendMessage(lvw.Handle, NativeMethods.ListViewMessage.SetTileViewInfo, 0, lvTVInfo);
            //var lvTVInfo = new NativeMethods.LVTILEVIEWINFO(0) { TileWidth = lvw.ClientSize.Width };
            //NativeMethods.SendMessage(lvw.Handle, NativeMethods.ListViewMessage.SetTileViewInfo, 0, lvTVInfo);
            //NativeMethods.SendMessage(lvw.Handle, (uint)NativeMethods.ListViewMessage.SetExtendedListViewStyle, new IntPtr(0x200000), new IntPtr(0x200000));
        }
示例#2
0
文件: ListView.cs 项目: JianwenSun/cc
        // updates the win32 list view w/ our tile info - columns + tile size
        private void UpdateTileView() {
            Debug.Assert(ComctlSupportsVisualStyles, "this function works only when ComCtl 6.0 and higher is loaded");
            Debug.Assert(this.viewStyle == View.Tile, "this function should be called only in Tile view");
            NativeMethods.LVTILEVIEWINFO tileViewInfo = new NativeMethods.LVTILEVIEWINFO();
            // the tile view info line count
            tileViewInfo.dwMask = NativeMethods.LVTVIM_COLUMNS;
            tileViewInfo.cLines = this.columnHeaders != null ? this.columnHeaders.Length : 0;

            // the tile view info size
            tileViewInfo.dwMask |= NativeMethods.LVTVIM_TILESIZE;
            tileViewInfo.dwFlags = NativeMethods.LVTVIF_FIXEDSIZE;
            tileViewInfo.sizeTile = new NativeMethods.SIZE(this.TileSize.Width, this.TileSize.Height);

            bool retval = UnsafeNativeMethods.SendMessage(new HandleRef(this,Handle),NativeMethods.LVM_SETTILEVIEWINFO,0,tileViewInfo);
            Debug.Assert(retval,"LVM_SETTILEVIEWINFO failed");
        }
示例#3
0
 public static extern bool SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out] NativeMethods.LVTILEVIEWINFO lParam);