如何知道richedit中现在的可视行数(150分)

  • 主题发起人 主题发起人 g622
  • 开始时间 开始时间
G

g622

Unregistered / Unconfirmed
GUEST, unregistred user!
各位:如何取得richedit中当前总共有多少行可以被看见?
 
将光标定位在当前最后一行,取得行数即可。<br>var row:integer;RTF:TRichEdit;<br>Row := SendMessage(RTF.Handle, EM_LINEFROMCHAR, RTF.SelStart, 0);<br>
 
对不起,我再把问题说清楚一些,我是问当前可视的行数,而不是此控件中到底有多少行。<br>
 
茶叶蛋:说话呀。。。。。
 
var<br>&nbsp; i,j:integer;<br>begin<br>&nbsp; {if GetScrollRange(RichEdit1.Handle,SB_VERT,i,j) then<br>&nbsp; &nbsp; showmessage(inttostr(i)+','+inttostr(j));<br>&nbsp; ShowMessage(inttostr(GetScrollPos(RichEdit1.Handle,SB_VERT)));<br>&nbsp; RichEdit1.Perform(SBM_GETRANGE,i,j);<br>&nbsp; &nbsp; showmessage(inttostr(i)+','+inttostr(j));}<br>&nbsp; i:=RichEdit1.Perform(EM_GETFIRSTVISIBLELINE,0,0);<br>&nbsp; if RichEdit1.Perform(WM_VSCROLL,SB_PAGEDOWN,j)=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; j:=RichEdit1.Perform(EM_GETFIRSTVISIBLELINE,0,0);<br>&nbsp; &nbsp; RichEdit1.Perform(WM_VSCROLL,SB_PAGEUP,j);<br>&nbsp; end;<br>&nbsp; showmessage('当前显示行数是: '+inttostr(j-i));<br>end;<br>
 
给出一个更为简洁的方法:<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; R: TRect;<br>&nbsp; result:integer;<br>begin<br>&nbsp; RichEdit1.Perform(EM_GETRECT, 0, Longint(@R));<br>&nbsp; Result := (R.Top - R.Bottom) div Richedit1.font.Height;<br>&nbsp; showmessage('当前可见行数是: '+inttostr(result));<br>end;<br>
 
多人接受答案了。
 
用 RichEdit1.Height div (-RichEdit1.Font.Height +2); 不是更简单 !<br>RichEdit1.Font.Height 为负 ,所以加个负号;+2 是考虑行距.
 
呵呵, richedit的字体可以每行不一样大, 你的方法当然有问题了:-)<br>
 
后退
顶部