7404
Конференция Delphi SoobCha
письмо # 7405
|
7406 |
|
go6poro BPEMEHu cyTOK.> Коллеги, подскажите как позиционировать курсор в нужное место? --- Возможный вариант (для TRichEdit). procedure RichEdit_SetLine(RE:TRichedit;Linepos,charpos:integer); Begin with RE do begin selstart:=perform(EM_LineIndex,Linepos,0)+charpos; sellength:=length(lines[Linepos]); perform(EM_ScrollCaret,0,0); end; end; function RichEdit_GetLastVisibleLine(RichEdit: TRichEdit): Integer; const EM_EXLINEFROMCHAR = WM_USER + 54; var r: TRect; i: Integer; begin RichEdit.Perform(EM_GETRECT, 0, Longint(@r)); r.Left := r.Left + 1; r.Top := r.Bottom - 2; i := RichEdit.Perform(EM_CHARFROMPOS, 0, Integer(@r.topleft)); Result := RichEdit.Perform(EM_EXLINEFROMCHAR, 0, i); end; begin ... ... sFind:='Искомый текст'; StartPos := 0; ToEnd := Length(RE_Func.Text) - StartPos; //(RE_Func: TRichEdit) //Ищем текст FoundAt := RE_Func.FindText(sFind, StartPos, ToEnd, [{stMatchCase}]); if FoundAt <> -1 then begin //текст найден //Позиционируемся RichEdit_SetLine(RE_Func,0, FoundAt); RE_Func.SetFocus; //Фокус ввода //"Красим" найденный текст RE_Func.SelStart := FoundAt; RE_Func.SelLength := Length(sFind); //Прокрутка, чтоб не в конце и не в начале ... if (RE_Func.CaretPos.Y+5)>=RichEdit_GetLastVisibleLine(RE_Func) then begin //Позиционируемся со сдвигом на 5 строк RichEdit_SetLine(RE_Func,RE_Func.CaretPos.Y-5, FoundAt); RE_Func.SetFocus; //Фокус ввода //"Красим" найденный текст RE_Func.SelStart := FoundAt; RE_Func.SelLength := Length(sFind); end; ... ... end; -------------- C yBa}I{eHueM, sapopov@mail.ru |
7404
|
7406 |
|
|
|
|