c# - Draw horizontal line in ListView to show dropping place -


when in foobar2000 drag-and-drop files playlist, listview shows place of dropping tracks:

enter image description here

i'm looking way implement feature. drawn graphics library, or have implemented method show horizontal line on listview?

at least listview control, there limited built-in support provided way of insertionmark property, works in icon view, small icon view, , tile view. doesn't work when items sorted or when groups turned on, , requires comctrl32.dll version 6 (thus meaning windows xp or later, visual styles enabled).

if want more general solution, can draw line in dragover event:

animated demo of effect

to avoid flicker remember last index:

int previtem = -1; 

the event uses hittest determine item under cursor..:

private void listview1_dragover(object sender, drageventargs e) {     point mloc = listview1.pointtoclient(cursor.position);     var hitt = listview1.hittest(mloc);     if (hitt.item == null) return;      int idx = hitt.item.index;     if (idx == previtem) return;      listview2.refresh();     using (graphics g = listview1.creategraphics())     {         rectangle rect = listview1.getitemrect(idx);         g.drawline(pens.red, rect.left, rect.top, rect.right, rect.top);     }     previtem = idx; } 

if want use listbox, code pretty same:

private void listbox1_dragover(object sender, drageventargs e) {     point mloc = listbox1.pointtoclient(cursor.position);     int idx = listbox1.indexfrompoint(mloc);     if (idx  < 0) return;     if (idx == previtem) return;      listbox1.refresh();     using (graphics g = listbox1.creategraphics())     {         rectangle rect = listbox1.getitemrectangle(idx);         g.drawline(pens.red, rect.left, rect.top, rect.right, rect.top);     }     previtem = idx; } 

also refresh clear line in dragleave event , in dragdrop event!

note 1 of rare situations when want use control.creategraphics because drawing meant non-persistent! graphics should drawn e.graphics object in paint event!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -