全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1255
推到 Plurk!
推到 Facebook!

是否能在RichEdit 按 F3 自動選取游標所在的一整行文字

答題得分者是:hagar
wenberg
一般會員


發表:6
回覆:15
積分:9
註冊:2002-12-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-02-15 11:50:32 IP:61.223.xxx.xxx 未訂閱
謝謝
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-02-15 12:10:14 IP:202.39.xxx.xxx 未訂閱
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var aX, aY: Integer;
  i, iSelStart, iSelLen: integer;
begin
  if Key = VK_F3 then begin
    aX := 0;
    aY := 0;
    aY := SendMessage(RichEdit1.Handle, EM_LINEFROMCHAR, RichEdit1.SelStart, 0);
    aX := RichEdit1.SelStart - SendMessage(RichEdit1.Handle, EM_LINEINDEX, aY, 0);        iSelStart := 0;
    for i := 0 to aY-1 do
      iSelStart := iSelStart   Length(RichEdit1.Lines[i])   2;
    iSelLen := Length(RichEdit1.Lines[aY]);
    RichEdit1.SelStart := iSelStart;
    RichEdit1.SelLength := iSelLen;
    RichEdit1.SetFocus;
  end;
end;
-- 將進酒 杯莫停 與君歌一曲 請君為我傾耳聽 (hagar@gcn.net.tw)
wenberg
一般會員


發表:6
回覆:15
積分:9
註冊:2002-12-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-02-15 13:43:38 IP:61.223.xxx.xxx 未訂閱
引言:
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var aX, aY: Integer;
  i, iSelStart, iSelLen: integer;
begin
  if Key = VK_F3 then begin
    aX := 0;
    aY := 0;
    aY := SendMessage(RichEdit1.Handle, EM_LINEFROMCHAR, RichEdit1.SelStart, 0);
    aX := RichEdit1.SelStart - SendMessage(RichEdit1.Handle, EM_LINEINDEX, aY, 0);        iSelStart := 0;
    for i := 0 to aY-1 do
      iSelStart := iSelStart   Length(RichEdit1.Lines[i])   2;
    iSelLen := Length(RichEdit1.Lines[aY]);
    RichEdit1.SelStart := iSelStart;
    RichEdit1.SelLength := iSelLen;
    RichEdit1.SetFocus;
  end;
end;
-- 將進酒 杯莫停 與君歌一曲 請君為我傾耳聽 (hagar@gcn.net.tw)
如果想要選取游標之前文字呢? 謝謝
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-02-15 13:50:05 IP:202.39.xxx.xxx 未訂閱
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var aX, aY: Integer;
  i, iSelLen: integer;
begin
  if Key = VK_F3 then begin
    aX := 0;
    aY := 0;
    aY := SendMessage(RichEdit1.Handle, EM_LINEFROMCHAR, RichEdit1.SelStart, 0);
    aX := RichEdit1.SelStart - SendMessage(RichEdit1.Handle, EM_LINEINDEX, aY, 0);        iSelLen := 0;
    for i := 0 to aY-1 do
      iSelLen := iSelLen   Length(RichEdit1.Lines[i])   2;
    iSelLen := iSelLen   aX;
    RichEdit1.SelStart := 0;
    RichEdit1.SelLength := iSelLen;
    RichEdit1.SetFocus;
  end;
end;
-- 將進酒 杯莫停 與君歌一曲 請君為我傾耳聽 (hagar@gcn.net.tw) 發表人 - hagar 於 2003/02/15 13:51:15
wenberg
一般會員


發表:6
回覆:15
積分:9
註冊:2002-12-26

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-02-20 15:08:58 IP:61.223.xxx.xxx 未訂閱
引言:
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var aX, aY: Integer;
  i, iSelLen: integer;
begin
  if Key = VK_F3 then begin
    aX := 0;
    aY := 0;
    aY := SendMessage(RichEdit1.Handle, EM_LINEFROMCHAR, RichEdit1.SelStart, 0);
    aX := RichEdit1.SelStart - SendMessage(RichEdit1.Handle, EM_LINEINDEX, aY, 0);        iSelLen := 0;
    for i := 0 to aY-1 do
      iSelLen := iSelLen   Length(RichEdit1.Lines[i])   2;
    iSelLen := iSelLen   aX;
    RichEdit1.SelStart := 0;
    RichEdit1.SelLength := iSelLen;
    RichEdit1.SetFocus;
  end;
end;
-- 將進酒 杯莫停 與君歌一曲 請君為我傾耳聽 (hagar@gcn.net.tw) 發表人 - hagar 於 2003/02/15 13:51:15
選取游標之前文字及 選取游標之後文字 我還是不懂要如何更改上列程式?
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-02-20 21:02:00 IP:202.39.xxx.xxx 未訂閱
選取游標之後:
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var aX, aY: Integer;
  i, iSelLen, iSelStart: integer;
begin
  if Key = VK_F3 then begin
    aX := 0;
    aY := 0;
    aY := SendMessage(RichEdit1.Handle, EM_LINEFROMCHAR, RichEdit1.SelStart, 0);
    aX := RichEdit1.SelStart - SendMessage(RichEdit1.Handle, EM_LINEINDEX, aY, 0);        iSelStart := 0;
    for i := 0 to aY-1 do
      iSelStart := iSelStart   Length(RichEdit1.Lines[i])   2;
    iSelStart := iSelStart   aX;
   
    iSelLen := 0;
    for i := aY 1 to RichEdit1.Lines.Count-1 do
      iSelLen := iSelLen   Length(RichEdit1.Lines[i])   2;
    iSelLen := iSelLen   Length(RichEdit1.Lines[aY]) - aX;
    RichEdit1.SelStart := iSelStart;
    RichEdit1.SelLength := iSelLen;
    RichEdit1.SetFocus;
  end;
end;
發表人 - hagar 於 2003/02/20 21:03:06
wenberg
一般會員


發表:6
回覆:15
積分:9
註冊:2002-12-26

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-02-21 14:15:23 IP:61.223.xxx.xxx 未訂閱
//選取游標之前:???????? ...... iSelStart := 0;//選取游標之後 for i := 0 to aY-1 do iSelStart := iSelStart Length(RichEdit1.Lines[i]) 2; iSelStart := iSelStart aX; iSelLen := 0; iSelLen := iSelLen Length(RichEdit1.Lines[aY])- aX; ........ 發表人 - wenberg 於 2003/02/21 14:17:17
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-02-21 14:41:57 IP:202.39.xxx.xxx 未訂閱
引言: //選取游標之前:???????? ......前面幾行是取得游漂在第幾行(aY)第幾欄(aX) iSelStart := 0;//選取游標之後 這是初始值 這個 for 迴圈在計算 aX 前有幾個字元(含換行字元) 所得值即為 SelStart 之值 for i := 0 to aY-1 do iSelStart := iSelStart Length(RichEdit1.Lines[i]) 2; iSelStart := iSelStart aX; iSelLen := 0; iSelLen := iSelLen Length(RichEdit1.Lines[aY])- aX; ........ 第二個 for 迴圈在計算 aX 之後有幾個字元(含換行字元) 所得之值即為 SelLength 的值
有問題嗎? 小弟試了可以啊。
wenberg
一般會員


發表:6
回覆:15
積分:9
註冊:2002-12-26

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-02-21 15:02:21 IP:61.223.xxx.xxx 未訂閱
//選取游標之後已經可以 ...... iSelStart := 0;//選取游標之後 for i := 0 to aY-1 do iSelStart := iSelStart Length(RichEdit1.Lines[i]) 2; iSelStart := iSelStart aX; iSelLen := 0; iSelLen := iSelLen Length(RichEdit1.Lines[aY])- aX; ........ 選取游標之前就是不行 謝謝再幫幫忙
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-02-21 15:12:35 IP:202.39.xxx.xxx 未訂閱
引言:
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var aX, aY: Integer;
  i, iSelLen: integer;
begin
  if Key = VK_F3 then begin
    aX := 0;
    aY := 0;
    aY := SendMessage(RichEdit1.Handle, EM_LINEFROMCHAR, RichEdit1.SelStart, 0);
    aX := RichEdit1.SelStart - SendMessage(RichEdit1.Handle, EM_LINEINDEX, aY, 0);        iSelLen := 0;
    for i := 0 to aY-1 do
      iSelLen := iSelLen   Length(RichEdit1.Lines[i])   2;
    iSelLen := iSelLen   aX;
    RichEdit1.SelStart := 0;
    RichEdit1.SelLength := iSelLen;
    RichEdit1.SetFocus;
  end;
end;
這一個是選取游標之前的 小弟試也可以啊。
系統時間:2024-05-14 1:29:04
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!