線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1491
推到 Plurk!
推到 Facebook!

如何取得鼠標在richedit 的哪一行 第幾個字

尚未結案
elctppo
一般會員


發表:28
回覆:22
積分:10
註冊:2005-04-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-09-29 09:32:11 IP:202.175.xxx.xxx 未訂閱
如何取得鼠標在richedit 的哪一行 第幾個字 謝謝各位 .. . . . 還有個問題. . procedure TForm1.updatetitle; var title , temp : string; i : integer; begin i := length(docname); if i=0 then title := 'Untitled' else begin while docname[i] <> '\' do begin temp := temp docname[i]; i := i-1; end; i := length(temp) 1; while i > 0 do begin i := i-1; title := title temp[i]; end; end; caption := title ; caption := caption ' - Shine''s Notepad By 12a05 Hoi Hoi Po'; end; 這樣子無論我一開始的if 是 true or false caption 都會等於 title ' - Shine''s Notepad By 12a05 Hoi Hoi Po' 但是如果我把最後那兩行合併. . . 變成 caption := title ' - Shine''s Notepad By 12a05 Hoi Hoi Po'; 就不同了... 當我一開始的if 是 true , caption = title ' - Shine''s Notepad By 12a05 Hoi Hoi Po'; 當 if 是 false , caption = title; 為什麼會這樣子呢 . . ?? 謝謝各位大哥大姐!! http://www.mezone.net
h@visli
資深會員


發表:103
回覆:429
積分:431
註冊:2004-02-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-09-29 12:41:08 IP:222.248.xxx.xxx 未訂閱
獲取位置(RichEdit或Memo中):
function RichRow(m: TCustomMemo): Longint;
begin
  Result := SendMessage(m.Handle, EM_LINEFROMCHAR, m.SelStart, 0);
end;    function RichCol(m: TCustomMemo): Longint;
begin
  Result := m.SelStart - SendMessage(m.Handle, EM_LINEINDEX, SendMessage(m.Handle,
    EM_LINEFROMCHAR, m.SelStart, 0), 0);
end;    procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  caption := Format('%d : %d', [RichCol(Form1.Memo1), RichRow(Form1.Memo1)]);
end;    procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  Caption := Format('%d : %d', [RichCol(Form1.richedit1), RichRow(Form1.richedit1)]);
end;    // Or use CaretPos to determine the cursor's coordinates:    procedure TForm1.Button1Click(Sender: TObject);
begin
  with RichEdit1.CaretPos do
    Label1.Caption := Format('(%d, %d)',[X 1,Y 1])
end;
---------------------------- 於Delphi K.Top之上 博采眾家之長, 奉獻綿薄之力 ---------------------------
------
------------------------
博采眾家之長,奉獻綿薄之力
------------------------
h@visli
資深會員


發表:103
回覆:429
積分:431
註冊:2004-02-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-09-29 13:29:13 IP:222.248.xxx.xxx 未訂閱
第二個問題:
procedure TForm1.UpdateTitle(docname: string);
var
  title: string;
begin
  if length(docname) = 0 then title := 'Untitled'
  else title := StringReplace(docname, '\', '', [rfReplaceAll]);      caption := title;
  caption := caption   ' - Shine''s Notepad By 12a05 Hoi Hoi Po';
end;
---------------------------- 於Delphi K.Top之上 博采眾家之長, 奉獻綿薄之力 --------------------------- 發表人 - h@visli 於 2005/09/29 13:31:49
------
------------------------
博采眾家之長,奉獻綿薄之力
------------------------
系統時間:2024-05-19 14:14:34
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!