Board index » cppbuilder » Finding size in pixels of text in RichEdit control

Finding size in pixels of text in RichEdit control


2005-04-14 05:08:48 PM
cppbuilder95
I have a RichEdit which I rewrite between each screen. I need to adjust the
height of the containing control so that it contains all of the text, or up to
a maximum pre-defined height in pixels (so it cannot be greater than, say, the
form's clientheight less 80 pixels, for example). How do I measure the height
of the text in pixels in the RichEdit control? TIA,
--
Mark Jacobs
www.dkcomputing.co.uk
 
 

Re:Finding size in pixels of text in RichEdit control

Mark Jacobs wrote:
Quote
I have a RichEdit which I rewrite between each screen. I need to adjust
the height of the containing control so that it contains all of the
text, or up to a maximum pre-defined height in pixels (so it cannot be
greater than, say, the form's clientheight less 80 pixels, for example).
How do I measure the height of the text in pixels in the RichEdit
control?
You can find the linenumber of the last line in the control
with:
int line = SendMessage ( RichEdit1->Handle
, EM_LINEFROMCHAR
, RichEdit1->GetTextLen()
, 0);
If you have only one font then multiply with lineheigth.
Hans.
 

Re:Finding size in pixels of text in RichEdit control

Hans Galema wrote:
Quote
You can find the linenumber of the last line in the control
with:

int line = SendMessage ( RichEdit1->Handle
, EM_LINEFROMCHAR
, RichEdit1->GetTextLen()
, 0);

If you have only one font then multiply with lineheigth.
I eventually used this code (qstxt is my RichEdit control) :-
TControlCanvas *cCanvas; RECT r;
cCanvas=new TControlCanvas(); cCanvas->Font->Assign(qstxt->Font);
cCanvas->Control=qstxt; r.right=qstxt->Width-25; r.left=2;
int
heightinpixels=DrawText(cCanvas->Handle,qstxt->Text.c_str(),-1,&r,DT_CALCRECT|DT_WORDBREAK);
delete cCanvas;
--
Mark Jacobs
www.dkcomputing.co.uk
 

{smallsort}