Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何在vsIcon ViewStyle中更改TListView的图标/项目大小?_Delphi_Delphi Xe7_Tlistview - Fatal编程技术网

Delphi 如何在vsIcon ViewStyle中更改TListView的图标/项目大小?

Delphi 如何在vsIcon ViewStyle中更改TListView的图标/项目大小?,delphi,delphi-xe7,tlistview,Delphi,Delphi Xe7,Tlistview,我需要一个可以显示缩略图的控件,为此,我认为将TListView的ViewStyle设置为vsIcon就足够了,不幸的是,我意识到TImageList只支持256x256大小的图像。我知道有第三方解决方案,但我曾希望使用标准的TListView 我需要显示的图像约为348x480,因此我无法将它们添加到图像列表并将其分配给listview 因此,我想也许我可以将我的图像存储在TList中,然后自己绘制listview,这非常简单,只需使用CustomDrawItem方法并使用Item.Displ

我需要一个可以显示缩略图的控件,为此,我认为将
TListView
ViewStyle
设置为
vsIcon
就足够了,不幸的是,我意识到
TImageList
只支持256x256大小的图像。我知道有第三方解决方案,但我曾希望使用标准的
TListView

我需要显示的图像约为348x480,因此我无法将它们添加到图像列表并将其分配给listview

因此,我想也许我可以将我的图像存储在
TList
中,然后自己绘制listview,这非常简单,只需使用
CustomDrawItem
方法并使用
Item.DisplayRect
即可准确地知道绘制到何处,类似这样的内容(快速示例):

过程TForm1.ListView1CustomDrawItem(发送方:TCustomListView;
项:TListItem;状态:TCustomDrawState;变量DefaultDraw:Boolean);
变量
ItemRect:TRect;
i正确:TRect;
字幕:TRect;
开始
DefaultDraw:=False;
ItemRect:=Item.DisplayRect(drBounds);
IconRect:=Item.DisplayRect(drIcon);
CaptionRect:=Item.DisplayRect(drLabel);
用ListView1做什么
开始
如果cdsHot处于状态,则
开始
Canvas.Brush.Style:=bsSolid;
Canvas.Brush.Color:=clSkyBlue;
Canvas.FillRect(ItemRect);
结束;
如果在状态中选择了CDS,则
开始
Canvas.Brush.Style:=bsSolid;
Canvas.Brush.Color:=clBlue;
Canvas.FillRect(ItemRect);
结束;
{我的图片列表是一个在TList中保存位图的自定义控件}
如果MyPictureList1.Items.Count>0,则
MyPictureList1.Draw(画布,IconRect.Left+348第4部分,IconRect.Top+2,Item.ImageIndex);
//从imagelist中注释掉旧代码绘图
{如果大映像为零,则
开始
大图像.Draw(画布,IconRect.Left+大图像.Width div 4,2,Item.ImageIndex);
结束;}
//绘制文本等
结束;
结束;
问题是如何更改每个listview项的大小?通常,设置imagelist会更改项目的大小,但由于大小限制,我无法使用imagelist

我试过
ListView\u SetIconSpacing(ListView1.Handle,348480)这似乎没有任何作用,我还尝试膨胀我分配的本地矩形,但没有运气


是否可以手动将listview的图标/项目大小设置为大于256px?如果可以,我如何实现这一点?

您真的需要一次显示如此大的图像吗?让Listview显示较小的缩略图,然后让用户单击它们在单独的窗口中显示较大的版本怎么样?我意识到我的问题中包括了
Listview\u SetIconSpacing
(我发布得很晚)。这是一个错误,这只是我曾经尝试过的。我知道只设置项目之间的间距:。@RemyLebeau是的,这是减少图像大小的明显方法,但出于我的目的,我只需要显示大约8个缩略图,因此大小没有问题。好吧,看起来我会这样做,而不是在listview上黑客攻击。这是一个图像列表控件限制,你不能用它做任何事情。为什么不使用
TDrawGrid
来代替呢?哪个版本的Delphi?听上去,如果您只需要显示8个图标,那么最好使用带有速度按钮的
TFlowPanel
TGridPanel
之类的工具。但是这些控件只在Delphi的更高版本中出现。你真的需要一次显示这么大的图像吗?让Listview显示较小的缩略图,然后让用户单击它们在单独的窗口中显示较大的版本怎么样?我意识到我的问题中包括了
Listview\u SetIconSpacing
(我发布得很晚)。这是一个错误,这只是我曾经尝试过的。我知道只设置项目之间的间距:。@RemyLebeau是的,这是减少图像大小的明显方法,但出于我的目的,我只需要显示大约8个缩略图,因此大小没有问题。好吧,看起来我会这样做,而不是在listview上黑客攻击。这是一个图像列表控件限制,你不能用它做任何事情。为什么不使用
TDrawGrid
来代替呢?哪个版本的Delphi?听上去,如果您只需要显示8个图标,那么最好使用带有速度按钮的
TFlowPanel
TGridPanel
之类的工具。但这些控件仅在Delphi的更高版本中存在。
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
  ItemRect: TRect;
  IconRect: TRect;
  CaptionRect: TRect;
begin
  DefaultDraw := False;

  ItemRect := Item.DisplayRect(drBounds);
  IconRect := Item.DisplayRect(drIcon);
  CaptionRect := Item.DisplayRect(drLabel);

  with ListView1 do
  begin
    if cdsHot in State then
    begin
      Canvas.Brush.Style := bsSolid;
      Canvas.Brush.Color := clSkyBlue;
      Canvas.FillRect(ItemRect);
    end;

    if cdsSelected in State then
    begin
      Canvas.Brush.Style := bsSolid;
      Canvas.Brush.Color := clBlue;
      Canvas.FillRect(ItemRect);
    end;

    { my picture list is a custom control that holds bitmaps in a TList }
    if MyPictureList1.Items.Count > 0 then
      MyPictureList1.Draw(Canvas, IconRect.Left + 348 div 4, IconRect.Top + 2, Item.ImageIndex);

   // commented out old code drawing from imagelist
   { if LargeImages <> nil then
    begin
      LargeImages.Draw(Canvas, IconRect.Left + LargeImages.Width div 4, 2, Item.ImageIndex);
    end;  }

    // draw text etc
  end;
end;