关于光标定位的问题(高手请进)!!!!!!!(100分)

  • 主题发起人 主题发起人 joky1981
  • 开始时间 开始时间
J

joky1981

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样得到RichEdit控件的行间距?
怎样在RichEdit1中的到光标的位置,然后把光标定位在RichEdit2中与RichEdit1相同的位置?
 
var
LineNum: longint;
CharsBeforeLine: longint;
begin
LineNum := SendMessage(Memo1.Handle, EM_LINEFROMCHAR, Memo1.SelStart,0);
CharsBeforeLine := SendMessage(Memo1.Handle, EM_LINEINDEX, LineNum, 0);
Label1.Caption := '行 ' + IntToStr(LineNum +1)
Lebel2.Caption := '列 ' + IntToStr((Memo1.SelStart -
CharsBeforeLine) + 1);
end;
 
怎样得到行间距?
 
procedure TForm1.Button2Click(Sender: TObject);
var
n:integer;
begin
RichEdit1.selstart:=RichEdit2.selstart;
RichEdit1.sellength:=RichEdit2.sellength;
RichEdit1.SetFocus ;

n:=RichEdit1.Font.height+RichEdit1.Font.size;
if n<0 then n:=-n;
showmessage(inttostr(n));

end;
 
得到一整行的高度也行吧:)

function GetLineHeight(Rich: TRichEdit): Integer;
var
TempDC: HDC; // temp device context
TM: TTextMetric;
begin
TempDC := GetDC(Rich.Handle);
SelectObject(TempDC, Rich.Font.Handle);
GetTextMetrics(TempDC, TM);
ReleaseDC(Rich.Handle, TempDC);
Result := TM.tmHeight;
end;
 
后退
顶部