delphi - How to change the ListView OnDrag image? -
i'm using listview viewstyle := vsreport. when drag row 1 point point takes value of column 1 of row being dragged (in case it's 1) , displays inside dark grey rectangle shown below.
i've tried looking around in xe4 source code can't find background color set. i'd change background color clskyblue (or similar) don't know how it's done.
how go changing default dark grey background image of drag operation?
vcl's drag operations not have drag images out of box, provide mechanism providing drag image used. done constructing own "drag image list", either overriding getdragimages
method of control (when internal drag object used), or constructing own "drag object" when drag started, , assemble image list in getdragimages
method called vcl when drag initiated.
this mechanism bit different though tlistview
, ttreeview
controls because underlying api controls natively support providing drag image item that's being dragged. hence, unlike other controls, these controls override getdragimages
methods , return image list that's being created in overriden dostartdrag
methods controls ask api provide image list. why won't able find drag image created in vcl code.
to override behavior, 1 possibly override these (and possibly few other) methods in descendant class , implement them. don't know if easy or not, find providing image list through constructing drag object in onstartdrag
event handler easier. not have effect, since time getdragimages
of our drag object called, vcl has settled on image list api has supplied , api has created temporary list that's being dragged. then, can force dragging of original image list end , substitute our own.
below oversimplified example. apart error handling, resource protecting, hot spot determining etc.. vcl code see how ensures there's item that's being dragged.
type tlistwiewdragcontrolobjectex = class(tdragcontrolobjectex) protected function getdragimages: tdragimagelist; override; end; function tlistwiewdragcontrolobjectex.getdragimages: tdragimagelist; var bmp: tbitmap; r: trect; begin bmp := tbitmap.create; bmp.canvas.brush.color := clskyblue; r := tlistview(control).selected.displayrect(drbounds); bmp.setsize(r.right - r.left, r.bottom - r.top); bmp.canvas.font := tlistview(control).font; bmp.canvas.textout(0, 0, tlistview(control).selected.caption); result := tdragimagelist.create(control); result.width := bmp.width; result.height := bmp.height; imagelist_enddrag; // end drag temporary list result.setdragimage(result.add(bmp, nil), 0, 0); bmp.free; end; procedure tform1.listview1startdrag(sender: tobject; var dragobject: tdragobject); begin dragobject := tlistwiewdragcontrolobjectex.create(listview1); dragobject.alwaysshowdragimages := true; end;
Comments
Post a Comment