首页 | 培训 | 求学 | 参考 | 教师 | 教材 | 学校 | 招聘 | 租房 | 旅游ASKEDU.com  


培训指南—ASKEDU.com

返回 | 主页


在RichEdit如何定位光标位置?



[摘要]
如题,如何将光标定位在x行y列? 仔细看看下面的代码,希望给你以启示...

   // 指定输入游标的位置
   procedure SetCaret(RTF: TRichEdit; var Row, Col: word);
   var i, iStopLine, iSelStart: integer;
   begin
    if ...

如题,如何将光标定位在x行y列? 仔细看看下面的代码,希望给你以启示...

   // 指定输入游标的位置
   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]) >= 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 > 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;


其它培训参考信息:
托福与雅思的比较和区别
别让IE和Office泄露了你的秘密
网络管理之数据包的解释与结构分析
动 画 世 界
什么是XteamLinux系统?
IT启示录:从微软看网络管理
学习基础知识当好称职网络管理员
《Turbo C语言概述 》



信息来自互联网,敬请核实,谨慎使用



 




  中国 | Worldwide: United States United Kingdom Australia Canada India | Travel AgencyASKEDU.com