Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to control where text is dropped into a TMemo Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
84
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How can I control where text is dropped into a TMemo? In other words, I am in the 
middle of a drag operation and want to drop selected text into a TMemo based on the 
mouse position of where I drop. How can I tell the caret to go to the mouse 
location prior to the drop action?

Answer:

Send a EM_CHARFROMPOS message to the control, passing the mouse position (in client 
coordinates).
1   
2   procedure TForm1.Memo1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
3   var
4     ret: Longint;
5   begin
6     ret := memo1.perform(EM_CHARFROMPOS, 0, MakeLParam(X, Y));
7     label1.caption := format('row: %d, character index: %d', [HiWord(ret),
8       LoWord(ret)]);
9   end;


That is the first step, it gives you the mouse position in "character coordiantes". 
You still need to convert that to a character index, which you assign to SelStart 
to set the caret to that position.

10  with memo1 do
11    selstart := perform(EM_LINEINDEX, row, 0) + col;


You can now assign the dropped text to the memos SelText property to insert it.

Note that the EM_CHARFROMPOS message can also be used with TRichedit but the 
parameters
are different!

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC