whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

17 Visitors Online


 
...Drag & Drop items from a TListBox to a TRichEdit?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (9):  
     


function RECharIndexByPos(RichEdit: TRichEdit; X, Y: Integer): Integer;
var
  
P: TPoint;
begin
  
P := Point(X, Y);
  Result := SendMessage(RichEdit.Handle, EM_CHARFROMPOS, 0, Longint(@P));
end;


procedure TForm1.RichEdit1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
var
  
P: TPoint;
begin
  
// Check, if Source is ListBox1
  
Accept := Source = ListBox1;
  if GetCursorPos(P) then
    with 
RichEdit1 do
    begin
      
// Get the Index from Mouse Position
      
P := ScreenToClient(P);
      SelStart := RECharIndexByPos(RichEdit1, P.X, P.Y);
      SetFocus;
    end;
end;

procedure TForm1.RichEdit1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  
// finally insert text at mouse position
  
RichEdit1.SelText := ListBox1.Items[ListBox1.ItemIndex];
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners