sjordi 39 Posted October 12, 2021 Hi, I'm implementing a drag&drop process in a TListView and I'd like to animate the selected Item (or group item). For this I think we would need to create a bitmap of the selected item to be able then to move it around in the drag process. Is there any way to actually determine the coordinates, width, height of the Item, and make a bitmap of it on the fly? Thanks for any clue about that. Steve Share this post Link to post
Serge_G 87 Posted October 13, 2021 (edited) 8 hours ago, sjordi said: Is there any way to actually determine the coordinates, width, height of the Item, and make a bitmap of it on the fly? Yes, even if I don't remember how I proceed. I will look for in my ('old') sources code tests. I remember there are some private properties but, but these memories are polluted by more recent tests on VCL.TControlList (sorry) As soon as I find these sources, I come back. Edited October 13, 2021 by Serge_G Share this post Link to post
skyzoframe[hun] 4 Posted October 13, 2021 Hi, I have almost the same question. How to get ListView item width and height in runtime? Create bitmap on fly.: check WorkStation00.rar Share this post Link to post
Pat Heuvel 1 Posted October 14, 2021 Gday, From the Delphi drag and drop example: DragImage := Control.MakeScreenshot; Svc.BeginDragDrop(Self, DragData, DragImage); DragImage is a TBitmap Control is a TControl descendent Regards, Pat Share this post Link to post
Serge_G 87 Posted October 14, 2021 I don't found the source I had in mind, but ... If there are no headers or footers procedure TForm1.ListView1ItemClick(const Sender: TObject; const AItem: TListViewItem); begin if AItem.Purpose=TListItemPurpose.None then begin memo1.Lines.Clear; memo1.Lines.Add('Item width '+(Listview1.width).ToString); memo1.Lines.Add('real Item width '+(Listview1.width-Listview1.ItemSpaces.Left-ListView1.ItemSpaces.Right).ToString); memo1.Lines.Add('Item Height '+Listview1.ItemAppearance.ItemHeight.toString); memo1.Lines.Add('real Item height '+(Listview1.ItemAppearance.Itemheight-Listview1.ItemSpaces.top-ListView1.ItemSpaces.bottom).ToString); memo1.Lines.Add('cursor '+Listview1.ScrollViewPos.ToString); memo1.Lines.Add(' Item toppos in list '+(AItem.index*Listview1.ItemAppearance.ItemHeight-Listview1.ScrollViewPos).ToString); memo1.Lines.Add(' real Item toppos in list '+(AItem.index*Listview1.ItemAppearance.ItemHeight- Listview1.ScrollViewPos+Listview1.ItemSpaces.top).ToString); end; end; With this, it's easy to make a bitmap extracted from ListView1.MakeScreenShot like this procedure TForm1.ListView1ItemClick(const Sender: TObject; const AItem: TListViewItem); var aBitmap : TBitmap; rect : Trect; begin if AItem.Purpose=TListItemPurpose.None then begin Rect:=TRect.Create(TPoint.Zero); Rect.Left:=Trunc(ListView1.ItemSpaces.Left); Rect.Top:=trunc(AItem.index*Listview1.ItemAppearance.ItemHeight-Listview1.ScrollViewPos+Listview1.ItemSpaces.top); Rect.Right:=Rect.Left+Trunc(Listview1.width-ListView1.ItemSpaces.Right); Rect.Bottom:=Rect.Top+Trunc(Listview1.ItemAppearance.Itemheight-ListView1.ItemSpaces.bottom); aBitmap:=TBitmap.Create; try aBitmap.Width:=Rect.Width; abitmap.Height:=Rect.Height; aBitmap.CopyFromBitmap(Listview1.MakeScreenshot,Rect,0,0); aBitmap.SaveToFile('itemtest.bmp'); finally abitmap.Free; end; end; end; result : Ok, I just forget to discount Scrollbar width, but that's the idea 1 Share this post Link to post
sjordi 39 Posted October 14, 2021 Thanks both. I'll try the demo and your code Serge. Hopefully works as expected... I'll post the results back Share this post Link to post
Serge_G 87 Posted October 14, 2021 Note : in case of headers/footers a loop in the items till item index shall certainly do the job. My question : what event will you used to detect drag mode ? Share this post Link to post
sjordi 39 Posted October 14, 2021 Someone posted this example in the German Praxis forum, and it seems to work. I didn't try it yet on mobile devices though. ListViewItemDrag.zip Share this post Link to post
Serge_G 87 Posted October 15, 2021 Ah, I knew I faced this GetItemRect somewhere ! It was when I compare the new VCL TControlList to FMX.TListView. In fact, I was deploring the lack of the method (not lack but private one) GetItemRect (I found in FMX.TListview) in the VCL.TControlList On 10/13/2021 at 7:38 AM, Serge_G said: I will look for in my ('old') sources code tests. Was not so old finally, but other context . (webinaire sur TControlList partie sur le dragdrop) I quickly check and "joy" got the same results Quote ItemObj left 46 top 260 right 246 bottom 294 GetItemRect left 46 top 260 right 246 bottom 294 16 hours ago, sjordi said: I didn't try it yet on mobile devices though. No mousemove event will fire, I think. And tracking the movement of the finger should be a real challenge Share this post Link to post
sjordi 39 Posted October 15, 2021 Yes with fingers, that might be another challenge. I hope to have some testing time over the week-end and let you know Share this post Link to post
nighthawk2032 0 Posted November 21, 2022 Following the question, best practice to "Control.MakeScreenshot" with background transparency? Share this post Link to post
nighthawk2032 0 Posted December 6, 2022 I used "Control.PaintTo" function and this did provide proper transparency of the background. Share this post Link to post