Board index » cppbuilder » Row height & Character Heights for a TMemo

Row height & Character Heights for a TMemo

    I would like to know how to figure the number of rows of Text that can
fit on a TMemo with a given height that can be changed. I want to be able to
access any string at any position on the memo in my program. I can get the
needed line height by using the 'GetCaretPos()' after I have moved down 1
line. But I am missing something somewhere, there has to be a way to get the
line height before that, but the brain just isn't working right or
something. Also if the Font is changed then the numbers change and I would
like to be able to get the line height again as needed.
    I hope this is clear enough to understand. Thanks for any help.
        --Tom--
 

Re:Row height & Character Heights for a TMemo


Hi Tom,
Quote
> I would like to know how to figure the number of rows of Text that can
> fit on a TMemo with a given height that can be changed.

[snip]

You can calculate this value through the use of the TCanvas::TextHeight() member
function...

#include <memory>

    std::auto_ptr<TControlCanvas> MemoCanvas(new TControlCanvas());
    MemoCanvas->Control = Memo1;
    MemoCanvas->Font = Memo1->Font;

    int line_height = MemoCanvas->TextHeight("A");
    int num_lines_fit = Memo1->ClientHeight / line_height;

Good luck!

--
Damon Chandler (TeamB)
http://bcbcaq.freeservers.com

Re:Row height & Character Heights for a TMemo


I know this is a nitty gritty question, but is there a special reason why Damon
prefers to write

Quote
>     std::auto_ptr<TControlCanvas> MemoCanvas(new TControlCanvas());

instead of:

  TControlCanvas *MemoCanvas=new TControlCanvas;
which seems to be more concise etc. and works just as well??

Re:Row height & Character Heights for a TMemo


    I have no Idea! In fact I have no idea where to find some of this info.
In fact, if it wasn't for this News Group I'd still have Questions and no
answeres. I read this Group and the WinAppi Group alot.
    The Team B and everyone else are a great help. I have used your line and
it works just as well. Thanks to all of you. Yoto, Remy,Zombacity and all
the rest.

Re:Row height & Character Heights for a TMemo


Quote
zombacity wrote:

> I know this is a nitty gritty question, but is there a special reason why Damon
> prefers to write

> >     std::auto_ptr<TControlCanvas> MemoCanvas(new TControlCanvas());

> instead of:

>   TControlCanvas *MemoCanvas=new TControlCanvas;

> which seems to be more concise etc. and works just as well??

'cause you don't have to 'manage' an auto_ptr? Since Tom admits to
sparse knowledge, Damon was just making it as simple as possible. ...
;-)

Bob

Re:Row height & Character Heights for a TMemo


std::auto_ptrs are "smart pointers", they take care of their own memory
management for you, you don't have to worry about cleaning them up when
you're done with them like you do when you just use 'new' directly

Gambit

Quote
"zombacity" <zombac...@netscapeonline.co.uk> wrote in message

news:39041B0D.D38F6B07@netscapeonline.co.uk...
Quote
> I know this is a nitty gritty question, but is there a special reason why
> Damon prefers to write
>    std::auto_ptr<TControlCanvas> MemoCanvas(new TControlCanvas());

> instead of:

>   TControlCanvas *MemoCanvas=new TControlCanvas;

> which seems to be more concise etc. and works just as well??

Other Threads