Solved

Drag and Drop

Posted on 2000-04-28
5
258 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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