Solved

Drag and Drop

Posted on 2000-04-28
5
256 Views
Last Modified: 2010-05-18
I've got a memo and an Edit control on a form. I want to select a portion of the text and drag it to the edit control so that I will not have to type it in the edit box. This is a good user interface technique, so how will i do it?
0
Comment
Question by:drnadeem
5 Comments
 
LVL 10

Expert Comment

by:ECollin
ID: 2759696
Why don't you just use Copy/Paste on the tmemo and on the TEdit controls.
0
 
LVL 1

Expert Comment

by:l8knight
ID: 2759841
A better way to do it would be to set up a button to copy the selected text into the Edit box, then all you need is

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := Memo1.SelText;
end;

regards

l8knight

p.s. if you really want to drag and drop try the Drag and Drop Component Suite at http://www.melander.dk they are the best I have found.
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 30 total points
ID: 2759850
Try this out: (dragtext is a global String variable).


procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then  { drag only if left button pressed }
    with Sender as Tmemo do  { treat Sender as TFileListBox }
      begin
        if seltext<>'' then  { is there tezt selected? }
          dragtext:=seltext;
          BeginDrag(False);  { if so, drag it }
    end;

end;

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

procedure TForm1.Edit1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
 edit1.text:=dragtext;
 dragtext:='';
end;
0
 
LVL 17

Expert Comment

by:inthe
ID: 2759927
looks good but how can you first select the text ?
0
 
LVL 1

Author Comment

by:drnadeem
ID: 2761422
instead of Button = mbLeft
use Button = mbRight
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now