[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Drag and Drop texto from a listbox to another showing the word being dragged.

Posted on 2013-12-04
3
Medium Priority
?
572 Views
Last Modified: 2013-12-04
Hello,

I have a listbox1 with some words and a second empty listbox2. I can drag any word from listbox1 and drop it to listbox2, but the cursor is a drag figure and can't see the word that I am draging to the destination.

Is it possible to do it as it was made to picture? When I drag the image, I can pic it and it float with my cursor until the destination, can I do that with words?

pic drag from this thread http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_28302574.html#a39695283

thanks
Alex
0
Comment
Question by:hidrau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 19

Accepted Solution

by:
Thommy earned 1000 total points
ID: 39695643
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, jpeg, ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    ListBox1: TListBox;
    ListBox2: TListBox;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Image1DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure Image1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure ListBox2StartDrag(Sender: TObject; var DragObject: TDragObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TTextDragObject = class(TDragControlObjectEx)
  private
    FDragImages: TDragImageList;
    FText: String;
  protected
    function GetDragImages: TDragImageList; override;
  end;


var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox2.DragMode := dmAutomatic;
  ControlStyle := ControlStyle + [csDisplayDragImage];
  Image1.ControlStyle := ListBox2.ControlStyle + [csDisplayDragImage];
end;

procedure TForm1.Image1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  ListBox1.Items.Add(ListBox2.Items[ListBox2.Tag]);
end;

procedure TForm1.Image1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept:=true;
end;


procedure TForm1.ListBox2StartDrag(Sender: TObject;
  var DragObject: TDragObject);
var
  List: TListbox absolute Sender;
begin
  DragObject := TTextDragObject.Create(List);
  if List.ItemIndex > -1 then
    TTextDragObject(DragObject).FText := List.Items[List.ItemIndex];
    List.Tag:=List.ItemIndex;
end;

function TTextDragObject.GetDragImages: TDragImageList;
var
  Bmp: TBitmap;
begin
  if FDragImages = nil then
  begin
    FDragImages := TDragImageList.Create(Control);
    Bmp := TBitmap.Create;
    try
      Bmp.Width := Bmp.Canvas.TextWidth(FText);
      Bmp.Height := Bmp.Canvas.TextHeight(FText);
      Bmp.Canvas.TextOut(0, 0, FText);
      FDragImages.Width := Bmp.Width;
      FDragImages.Height := Bmp.Height;
      FDragImages.SetDragImage(FDragImages.Add(Bmp, nil), 0, 0);
    finally
      Bmp.Free;
    end;
  end;
  Result := FDragImages;
end;


end.

Open in new window

0
 
LVL 28

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 1000 total points
ID: 39696634
My example is very similar. I use transparency in dragging text. Works as I described in another thread and Thommy did it similar too.

Thommy, small comment if I may - you didn't destroy your TDragImageList after usage.
drag.zip
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 39697035
Thanks very much everybody
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question