Board index » cppbuilder » TMemo stretching down problem...

TMemo stretching down problem...


2005-02-07 06:14:19 PM
cppbuilder35
Hi!
i have the following problem:
On my form i have one panel and one Memo within that panel . The Memo align
property is set to alClient. Now what i want - is there a way to handle an
event when the caret goes below the lowest line of memo so the whole text
rise up and top string becomes invisible? At this moment i need to stretch
the panel down to have my memo stretched and have all the text visible.
This moment can be explained this way as well - if you for example have the
Memo scrollbars setting set to ssVertical, you would have vertical
scrollbar shown up at this moment. - i dont want to have this happened, but
want to stretch my memo down.
Thanks in advance,
Andrew
 
 

Re:TMemo stretching down problem...

AndrewFx wrote:
Quote
On my form i have one panel and one Memo within that panel . The Memo align
property is set to alClient. Now what i want - is there a way to handle an
event when the caret goes below the lowest line of memo so the whole text
rise up and top string becomes invisible?
That happens just automatically when the user types.
Quote
At this moment i need to stretch
the panel down to have my memo stretched and have all the text visible.
You mean: the text does not scroll and you ave to adjust the Heigth of the
TMemo ? How do you add text then ?
Quote
This moment can be explained this way as well - if you for example have the
Memo scrollbars setting set to ssVertical, you would have vertical
scrollbar shown up at this moment. - i dont want to have this happened, but
want to stretch my memo down.
But stretching (changing Height) is something different as scrolling. With
or without scrollbar.
Please explain what you want exactly.
Hans.
 

Re:TMemo stretching down problem...

AndrewFx wrote:
Quote
Hi!

i have the following problem:
On my form i have one panel and one Memo within that panel . The Memo align
property is set to alClient. Now what i want - is there a way to handle an
event when the caret goes below the lowest line of memo so the whole text
rise up and top string becomes invisible? At this moment i need to stretch
the panel down to have my memo stretched and have all the text visible.
This moment can be explained this way as well - if you for example have the
Memo scrollbars setting set to ssVertical, you would have vertical
scrollbar shown up at this moment. - i dont want to have this happened, but
want to stretch my memo down.
Memo1->SetFocus(); Memo1->Perform(EM_SCROLLCARET,0,0);
MJ
 

{smallsort}

Re:TMemo stretching down problem...

Thanks for reply, Hans. Below are my comments.
Q:"You mean: the text does not scroll and you ave to adjust the Heigth of
the
TMemo ? How do you add text then ?"
A: text does. but i want to see all the text WITHOUT scrolling bars. only
way to do it - is resize TMemo (or resize panel). if you resize Tmemo you
put the text in as you always do.
C:"But stretching (changing Height) is something different as scrolling.
With
or without scrollbar."
A: Right - i need to change height. But how do i recognise this moment?
"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
AndrewFx wrote:

>On my form i have one panel and one Memo within that panel . The Memo
align
>property is set to alClient. Now what i want - is there a way to handle
an
>event when the caret goes below the lowest line of memo so the whole
text
>rise up and top string becomes invisible?

That happens just automatically when the user types.

>At this moment i need to stretch
>the panel down to have my memo stretched and have all the text visible.

You mean: the text does not scroll and you ave to adjust the Heigth of the
TMemo ? How do you add text then ?

>This moment can be explained this way as well - if you for example have
the
>Memo scrollbars setting set to ssVertical, you would have vertical
>scrollbar shown up at this moment. - i dont want to have this happened,
but
>want to stretch my memo down.

But stretching (changing Height) is something different as scrolling. With
or without scrollbar.

Please explain what you want exactly.

Hans.
 

Re:TMemo stretching down problem...

Thanks for reply, MJ.
i just took a look at MSDN help files searhing for EM_SCROLLCARET parameter
you gave and ran into this :
"The EM_SCROLL message scrolls the text vertically in a multiline edit
control. This message is equivalent to sending a WM_VSCROLL message to the
edit control. You can send this message to either an edit control or a rich
edit control"
So, the moment i've been looking for is found! When the application send
this message (EM_SCROLL) the top line becomes invisible and text scrolls
down... BUT how do i intercept this message????
"Mark Jacobs" <www.jacobsm.com/mjmsg.htm?mj@critical>wrote in
message news:42075933$ XXXX@XXXXX.COM ...
Quote
AndrewFx wrote:
>Hi!
>
>i have the following problem:
>On my form i have one panel and one Memo within that panel . The Memo
align
>property is set to alClient. Now what i want - is there a way to handle
an
>event when the caret goes below the lowest line of memo so the whole
text
>rise up and top string becomes invisible? At this moment i need to
stretch
>the panel down to have my memo stretched and have all the text visible.
>This moment can be explained this way as well - if you for example have
the
>Memo scrollbars setting set to ssVertical, you would have vertical
>scrollbar shown up at this moment. - i dont want to have this happened,
but
>want to stretch my memo down.

Memo1->SetFocus(); Memo1->Perform(EM_SCROLLCARET,0,0);

MJ
 

Re:TMemo stretching down problem...

"AndrewFx" < XXXX@XXXXX.COM >wrote:
Quote

[...] BUT how do i intercept this message????
You don't. You send it. How it works is that you position the
caret and then send the message which will cause the memo to
scroll so that the caret is visible.
The 'moment' that you're looking for is found using the
TPanel::OnResize event.
~ JD
 

Re:TMemo stretching down problem...

thanks for reply, JD.
Maybe i'm totally dumb, but:
i dont send it by myself... it's being send by an application when the caret
reachs the "end" of TMemo. i cant control this since i dont know when caret
is "reached the end". wish i knew...
"The 'moment' that you're looking for is found using the
TPanel::OnResize event." - didnt understand you, please clarify.
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"AndrewFx" < XXXX@XXXXX.COM >wrote:
>
>[...] BUT how do i intercept this message????

You don't. You send it. How it works is that you position the
caret and then send the message which will cause the memo to
scroll so that the caret is visible.

The 'moment' that you're looking for is found using the
TPanel::OnResize event.

~ JD

 

Re:TMemo stretching down problem...

i think there is another way to do it. if i would know how many strings (x)
Memo can contain without being scrolled then i could work on Keypress event
when Key = VK_RETURN. Bbut TMemo font size seems to be a bit strange and it
cant be compute as easy as this : x = TMemo::Height/Font::size;
any advices would be very appreciated.
"Mark Jacobs" <www.jacobsm.com/mjmsg.htm?mj@critical>wrote in
message news:42075933$ XXXX@XXXXX.COM ...
Quote
AndrewFx wrote:
>Hi!
>
>i have the following problem:
>On my form i have one panel and one Memo within that panel . The Memo
align
>property is set to alClient. Now what i want - is there a way to handle
an
>event when the caret goes below the lowest line of memo so the whole
text
>rise up and top string becomes invisible? At this moment i need to
stretch
>the panel down to have my memo stretched and have all the text visible.
>This moment can be explained this way as well - if you for example have
the
>Memo scrollbars setting set to ssVertical, you would have vertical
>scrollbar shown up at this moment. - i dont want to have this happened,
but
>want to stretch my memo down.

Memo1->SetFocus(); Memo1->Perform(EM_SCROLLCARET,0,0);

MJ
 

Re:TMemo stretching down problem...

ok, seems i found the decision. the function below calculatesnumber of
visible lines in TMemo.
function LinesVisible( Memo: TMemo ): integer;
var
OldFont: HFont;
Hand: THandle;
TM: TTextMetric;
Rect: TRect;
TempInt: integer;
begin
Hand := GetDC( Memo.Handle );
try
OldFont := SelectObject( Hand, Memo.Font.Handle );
try
GetTextMetrics( Hand, TM );
Memo.Perform( EM_GETRECT, 0, Longint( @Rect ) );
TempInt := ( Rect.Bottom - Rect.Top ) div ( TM.tmHeight +
TM.tmExternalLeading );
finally
SelectObject( Hand, OldFont );
end;
finally
ReleaseDC( Memo.Handle, Hand );
end;
Result := TempInt;
end;
( from decoding.narod.ru/faq/component/memo/memo001.html)
"AndrewFx" < XXXX@XXXXX.COM >wrote in message
Quote
i think there is another way to do it. if i would know how many strings
(x)
Memo can contain without being scrolled then i could work on Keypress
event
when Key = VK_RETURN. Bbut TMemo font size seems to be a bit strange and
it
cant be compute as easy as this : x = TMemo::Height/Font::size;

any advices would be very appreciated.
"Mark Jacobs" <www.jacobsm.com/mjmsg.htm?mj@critical>wrote in
message news:42075933$ XXXX@XXXXX.COM ...
>AndrewFx wrote:
>>Hi!
>>
>>i have the following problem:
>>On my form i have one panel and one Memo within that panel . The Memo
align
>>property is set to alClient. Now what i want - is there a way to
handle
an
>>event when the caret goes below the lowest line of memo so the whole
text
>>rise up and top string becomes invisible? At this moment i need to
stretch
>>the panel down to have my memo stretched and have all the text
visible.
>>This moment can be explained this way as well - if you for example
have
the
>>Memo scrollbars setting set to ssVertical, you would have vertical
>>scrollbar shown up at this moment. - i dont want to have this
happened,
but
>>want to stretch my memo down.
>
>Memo1->SetFocus(); Memo1->Perform(EM_SCROLLCARET,0,0);
>
>MJ


 

Re:TMemo stretching down problem...

"AndrewFx" < XXXX@XXXXX.COM >wrote:
Quote

[...] didnt understand you, please clarify.
You want to resize the TMemo so that all of the text is
visible. To this end, you have the TMemo::Align property set
to alClient. That means that when ever the Parent of the
TMemo - a TPanel in this case - is resized, the size of the
TMemo changes as well.
TPanel has an OnResize event so you can use that event to know
when ever the size of the TMemo has changed. So ... instead of
trying to trap EM_SCROLL, in the OnResize event, simply scroll
the TMemo to it's first line:
void __fastcall TForm1::Panel1Resize(TObject *Sender)
{
// make sure that no text is selected
Memo1->SelLength = 0;
// position the caret
Memo1->SelPos = 0;
// scroll to the caret
Memo1->Perform( EM_SCROLL, 0, 0 );
}
~ JD
 

Re:TMemo stretching down problem...

thanks, JD.
i tryed it without result. Seems like Memo has no SelPos method in Borland
builder...
anyway thank you for help.
P.S. i worked it out with "visible lines count" method i gave in previous
message.
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"AndrewFx" < XXXX@XXXXX.COM >wrote:
>
>[...] didnt understand you, please clarify.

You want to resize the TMemo so that all of the text is
visible. To this end, you have the TMemo::Align property set
to alClient. That means that when ever the Parent of the
TMemo - a TPanel in this case - is resized, the size of the
TMemo changes as well.

TPanel has an OnResize event so you can use that event to know
when ever the size of the TMemo has changed. So ... instead of
trying to trap EM_SCROLL, in the OnResize event, simply scroll
the TMemo to it's first line:

void __fastcall TForm1::Panel1Resize(TObject *Sender)
{
// make sure that no text is selected
Memo1->SelLength = 0;
// position the caret
Memo1->SelPos = 0;
// scroll to the caret
Memo1->Perform( EM_SCROLL, 0, 0 );
}

~ JD