Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14490161
  • 博文数量: 5645
  • 博客积分: 9880
  • 博客等级: 中将
  • 技术积分: 68081
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-28 13:35
文章分类

全部博文(5645)

文章存档

2008年(5645)

我的朋友

分类:

2008-04-28 20:48:21

下载本文示例代码
  Delphi // 指定输入游标的位置 procedure SetCaret(RTF: TRichEdit; var Row, Col: word); var i, iStopLine, iSelStart: integer; begin if (RTF = nil) then Exit; if Row = 0 then Row := 1; if Col = 0 then Col := 1; // 到第 Row 列, Col 行共几个字元 iStopLine := Row - 1; iSelStart := 0; for i := 0 to RTF.Lines.Count - 1 do begin if i = iStopLine then begin if Length(RTF.Lines[i]) $#@62;= Col then Inc(iSelStart, Col) else Inc(iSelStart, Length(RTF.Lines[i]) 2); Break; end; Inc(iSelStart, Length(RTF.Lines[i]) 2); end; if iSelStart $#@62; 0 then Dec(iSelStart); // 以设定标记的方式指定游标位置 SendMessage(RTF.Handle, EM_SETSEL, iSelStart, iSelStart); // 再次侦测游标位置 Row := SendMessage(RTF.Handle, EM_LINEFROMCHAR, RTF.SelStart, 0); Col := RTF.SelStart - SendMessage(RTF.Handle, EM_LINEINDEX, Row, 0); // 卷到游标所在位置 SendMessage(RTF.Handle, EM_SCROLLCARET, 0, 0); end; procedure TForm1.Button1Click(Sender: TObject); var iRow, iCol: word; begin iRow := 17; iCol := 3; SetCaret(RichEdit1, iRow, iCol); RichEdit1.SetFocus; end;   Delphi // 指定输入游标的位置 procedure SetCaret(RTF: TRichEdit; var Row, Col: word); var i, iStopLine, iSelStart: integer; begin if (RTF = nil) then Exit; if Row = 0 then Row := 1; if Col = 0 then Col := 1; // 到第 Row 列, Col 行共几个字元 iStopLine := Row - 1; iSelStart := 0; for i := 0 to RTF.Lines.Count - 1 do begin if i = iStopLine then begin if Length(RTF.Lines[i]) $#@62;= Col then Inc(iSelStart, Col) else Inc(iSelStart, Length(RTF.Lines[i]) 2); Break; end; Inc(iSelStart, Length(RTF.Lines[i]) 2); end; if iSelStart $#@62; 0 then Dec(iSelStart); // 以设定标记的方式指定游标位置 SendMessage(RTF.Handle, EM_SETSEL, iSelStart, iSelStart); // 再次侦测游标位置 Row := SendMessage(RTF.Handle, EM_LINEFROMCHAR, RTF.SelStart, 0); Col := RTF.SelStart - SendMessage(RTF.Handle, EM_LINEINDEX, Row, 0); // 卷到游标所在位置 SendMessage(RTF.Handle, EM_SCROLLCARET, 0, 0); end; procedure TForm1.Button1Click(Sender: TObject); var iRow, iCol: word; begin iRow := 17; iCol := 3; SetCaret(RichEdit1, iRow, iCol); RichEdit1.SetFocus; end; 下载本文示例代码


改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置改变RichEdit的游标位置
阅读(206) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~