Registriert seit: 29. Sep 2013
152 Beiträge
|
AW: Line index in Richedit
22. Apr 2014, 00:53
Meine Loesung Zum Zentrieren der Selection-Line im Richedit:
Delphi-Quellcode:
procedure TForm.Button1Click(Sender: TObject);
const
EM_EXLINEFROMCHAR = WM_USER + 54;
var FirstLine, LastLine, SelLine : Integer;
LinesToScroll : Integer;
r: TRect;
i: Integer;
begin
// Get selection line
SelLine := Richedit1.caretpos.y;
// Get first visible line
FirstLine := RichEdit1.Perform(EM_GETFIRSTVISIBLELINE, 0, 0);
// Get last visible line
RichEdit1.Perform(EM_GETRECT, 0, Longint(@r));
r.Left := r.Left + 1;
r.Top := r.Bottom - 2;
i := RichEdit1.Perform(EM_CHARFROMPOS, 0, Integer(@r.topleft));
LastLine := RichEdit1.Perform(EM_EXLINEFROMCHAR, 0, i);
// Center selection in Richedit by scrolling
LinesToScroll := -Round(0.5*(LastLine+FirstLine) - SelLine);
RichEdit1.Perform(EM_LINESCROLL, 0, LinesToScroll);
end;
|
|
Zitat
|