Q&A

  • TMemo에서 Key Cursor가 있는 행과 컬럼을 어떻게 알아내죠 ?
TMemo에서 KeyPressed 이벤트가 발생했을때 그때 행과 컬럼을 뿌려줄려고 합니다.





어떻게 해야 하죠 ?



한수 부탁 합니다.

1  COMMENTS
  • Profile
    Mr.Q 2000.11.16 06:47
    전체소스입니다.







    unit Unit1;



    interface



    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    StdCtrls, ComCtrls;



    type

    TForm1 = class(TForm)

    Memo1: TMemo;

    StatusBar1: TStatusBar;

    Button1: TButton;

    Button2: TButton;

    Button3: TButton;

    procedure FormCreate(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Memo1KeyDown(Sender: TObject; var Key: Word;

    Shift: TShiftState);

    procedure Memo1Click(Sender: TObject);

    procedure Memo1KeyUp(Sender: TObject; var Key: Word;

    Shift: TShiftState);

    private

    { Private declarations }

    public

    { Public declarations }

    procedure GetMemoLine(memo:TCustomMemo);

    procedure SetMemoLine(Memo:TCustomMemo; MemoLine, MemoCol:integer);

    end;



    var

    Form1: TForm1;

    MemoLine, MemoCol, CharseBeforeLine:integer;



    implementation



    {$R *.DFM}



    procedure TForm1.GetMemoLine(memo:TCustomMemo);

    var

    LineNum:LongInt;

    //CharseBeforeLine:LongInt;

    begin

    LineNum:=SendMessage(Memo.Handle, EM_LINEFROMCHAR, Memo.SelStart, 0);

    CharseBeforeLine:=SendMessage(Memo.Handle, EM_LINEINDEX, LineNum, 0);

    MemoLine:=LineNum+1;

    MemoCol:=Memo.SelStart - CharseBeforeLine + 1;

    end;



    procedure TForm1.SetMemoLine(Memo:TCustomMemo; MemoLine, MemoCol:integer);

    begin

    Memo.SelStart:=SendMessage(Memo.Handle, EM_LINEINDEX, MemoLine-1, 0)+MemoCol-1

    ;

    end;



    procedure TForm1.FormCreate(Sender: TObject);

    begin

    GetMemoLine(Memo1);

    end;



    procedure TForm1.Button2Click(Sender: TObject);

    begin

    ShowMessage(IntToStr(Memo1.SelStart));

    Memo1.SetFocus;

    end;



    procedure TForm1.Button1Click(Sender: TObject);

    begin

    GetMemoLine(Memo1);

    Showmessage(IntToStr(CharseBeforeLine));

    Memo1.SetFocus;

    end;



    procedure TForm1.Button3Click(Sender: TObject);

    begin

    GetMemoLine(Memo1);

    SetMemoLine(Memo1, MemoLine, MemoCol);



    Memo1.SetFocus;

    end;



    procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;

    Shift: TShiftState);

    begin

    GetMemoLine(Memo1);

    StatusBar1.SimpleText:='Line: '+IntToStr(MemoLine)+ ' ' +

    'Col: ' +IntToStr(MemoCol);

    end;



    procedure TForm1.Memo1Click(Sender: TObject);

    begin

    GetMemoLine(Memo1);

    StatusBar1.SimpleText:='Line: '+IntToStr(MemoLine)+ ' ' +

    'Col: ' +IntToStr(MemoCol);

    end;



    procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word;

    Shift: TShiftState);

    begin

    GetMemoLine(Memo1);

    StatusBar1.SimpleText:='Line: '+IntToStr(MemoLine)+ ' ' +

    'Col: ' +IntToStr(MemoCol);

    end;



    end.







    원영준 wrote:

    > TMemo에서 KeyPressed 이벤트가 발생했을때 그때 행과 컬럼을 뿌려줄려고 합니다.

    >

    >

    > 어떻게 해야 하죠 ?

    >

    > 한수 부탁 합니다.