JackKuti
asked on
Dragging an item
I want to click item in the ListBox and then drag the item somewhere on other component (eg. other ListBox), but I want the item still to appear under the cursor while draging. To be more exact, I want to drag name of font from the font list and drop it to some text in other component and by this to change font of the text. How can be this effect achieved?
ASKER
Thanks, font are changed perfectly, but still, I´d like to achieve the effect of appearing of font name under the cursor while draging it from ListBox untill it is dropped down. This is not necessary for the application to work but its nice.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your code. And don´t you know how to remove the crossed ring being displayed while dragging?
Are you sure you want to do that? Its the only UI cue to the user when a drop operation cannot be performed.
Russell
Russell
//////////////////////////
// TTextDrag
//////////////////////////
type
TTextDrag = class(TDragObject)
private
// Private declarations
FDragImage: TDragImageList;
FText: String;
protected
// Protected declarations
function GetDragCursor(Accepted: Boolean; X, Y: Integer): TCursor; override; // ADD
function GetDragImages: TDragImageList; override;
public
// Public declarations
constructor Create;
destructor Destroy; override;
procedure UpdateDragImage(Font: TFont; Text: String);
property Text: String read FText;
end;
etc....
implementation
{$R *.DFM}
function TTextDrag.GetDragCursor(Ac
begin
// Perform inherited
result:=inherited GetDragCursor(Accepted, X, Y);
// Check accepted = false. You can also remove this check and always return zero
// which will make it use the default cursor
if not(Accepted) then result:=0;
end;
ASKER
Trying if it looks better without the ring, if it won´t the ring will be returned. Many thanks to you!
Set the following
1. ListBox1.Drag Mode = dgAutomatic;
2. ListBox1.Tag := -1; // this will track the item to drag
in the OnMouseDown of ListBox1 write the following line
ListBox1.Tag := ListBox1.ItemAtPos(Point(X
in the OnDragOver event of other control put the following line
Accept := ListBox1.Tag > -1;
in the OnDragDrop event of other control put the following code
if ListBox1.Tag > -1 then
begin
Edit1.Font.Name := ListBox1.Items.Strings[Lis
ListBox1.Tag := -1; // reset the dragged item
end;