Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drag and Drop Text

Posted on 2013-12-02
4
Medium Priority
?
458 Views
Last Modified: 2013-12-02
hello guys

I have three objects on my form, an Image and two listbox.

There is a listbox with somewords that I'd like to drag it to my empty listbox and insert the text there, but I'd like to know how can I drag and drop the text on the image and it send the text to the listbox above it.

I am sending an example made in D7, please give me an example how to do that, drag and drop text from listbox to another and listbox to image that will send automaticly to the above listbox.

Thanks
Alex
DropImage.zip
0
Comment
Question by:hidrau
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 39689540
I think that's it, what you are looking for...
How to Move ListBox Items with the Mouse (Drag and Drop)
0
 
LVL 1

Author Comment

by:hidrau
ID: 39689553
Hello Thommy,

From a listbox to another listbox I know how, but if I drag the text into the image, how can I send it automatically to my empty listbox? That is the problem.
0
 
LVL 19

Accepted Solution

by:
Thommy earned 2000 total points
ID: 39689906
Below code adds Listbox2 drag item to Listbox1, when dropped on Image1...

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);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox2.DragMode := dmAutomatic;
end;

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

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

end.

Open in new window

DropImageNew.zip
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 39691343
Thanks very much for the help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

926 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