RichEdit 에서 라인과 칼럼을 알아내기
2011.12.22 01:33
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
StatusBar1: TStatusBar;
RichEdit1: TRichEdit;
procedure RichEdit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure CaretPos(H: THandle; var L,C : Word);
begin
L := SendMessage(H,EM_LINEFROMCHAR,-1,0);
C := LoWord(SendMessage(H,EM_GETSEL,0,0)) - SendMessage(H,EM_LINEINDEX,-1,0);
end;
procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
LineNum,ColNum : Word;
begin
CaretPos(RichEdit1.Handle,LineNum,ColNum);
Statusbar1.Panels[0].Text := format('Line %d Col %d',[LineNum,ColNum]);
end;
end.