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 convert the mouse coordinates into a line and character offset in a TRich 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
145
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I am currently trapping the OnMouseMove event, however have run into significant 
problems converting the mouse coordinates into a line and character offset in a 
rich edit.

Answer:
1   
2   procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
3     Integer);
4   var
5     Point: TPoint;
6     Value: LongInt;
7     LineNumber: Integer;
8     LinePos: Integer;
9     Line: string;
10  begin
11    {Get absolute position of character beneath mouse}
12    Point.x := X;
13    Point.y := Y;
14    Value := RichEdit1.Perform(EM_CHARFROMPOS, 0, LParam(@Point));
15    if Value >= 0 then
16    begin
17      {Get line number}
18      LineNumber := RichEdit1.Perform(EM_LINEFROMCHAR, Value, 0);
19      {Get line position}
20      LinePos := Value - RichEdit1.Perform(EM_LINEINDEX, LineNumber, 0);
21      {Get line}
22      Line := RichEdit1.Lines[LineNumber];
23      Label1.Caption := Format('Line: %d Column: %d: %s', [LineNumber, LinePos, 
24  Line]);
25    end
26    else
27    begin
28      Label1.Caption := EmptyStr;
29    end;
30  end;


This only works for RichEdits.

			
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