我还在做我的毕业设计,现在其他的我都不要了,只想知道怎么在MEMO控件里面通过函数设置光标在我想要的位置,这个可以吗?

解决方案 »

  1.   

    用下面两个函数:
    function  GetColumn(Memo:TMemo): SmallInt;
    begin
      Result := (Memo.SelStart+Memo.SelLength) - Memo.Perform(EM_LINEINDEX, -1, 0);
    end;function  GetRow(Memo:TMemo) : SmallInt;
    begin
      Result := LongRec(Memo.Perform(EM_LINEFROMCHAR, -1, 0)).Lo;
    end;
      

  2.   

    procedure SetCaret(RTF: TRichEdit; var row, col: word);vari,iStopLine,iSelStart:integer;Strings:TStrings;beginif (RTF=nil) then exit;Strings:=RTF.Lines;if Row=0 then Row:=1;if Col=0 then Col:=1;//到第Row列,Col行共几个字元iStopLine:=Row-1;iSelStart:=0;for i:=0 to Strings.Count-1 dobeginif i=iStopLine thenbeginif Length(Strings[i])>Col thenInc(iSelStart,Col)elseInc(iSelStart,Length(Strings[i])+2);Break;end;Inc(iSelStart,Length(Strings[i])+2);end;if iSelStart>0 then Dec(iSelStart);//以设定标记的方式指定游标位置RTF.SelStart :=iSelStart;// + Length(RTF.Lines[i])+2;//再次侦测游标位置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;