Board index » cppbuilder » How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?


2006-08-20 06:36:26 AM
cppbuilder47
dear builders,
the following function saves the text of a "visible" part of the TRichEdit into a TImage->Canvas...
my question is, how can i save the ENTIRE text, where you have to scroll down the
TRichEdit...??
with other words: How do i save the entire text of the TRichEdit into a graphic ? (TImage->Canvas)
can someone drop me please a helpful hint ??
thanks for any help on this...
Oren
/**************************************************************/
void __fastcall TfrmDetails::cmdSave_TextAsGraphicClick( TObject *Sender)
{
Image1->Width = RichEdit1->Width;
Image1->Height = RichEdit1->Height;
TRect R = Rect(RichEdit1->Left, RichEdit1->Top, RichEdit1->Left + RichEdit1->Width, RichEdit1->Top + RichEdit1->Height);
Image1->Canvas->CopyRect(Image1->ClientRect, Canvas, R);
if(SaveBild_Dialog->Execute()) {Image1->Picture->SaveToFile(SaveBild_Dialog->FileName);}
}
 
 

Re:How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
the following function saves the text of a "visible" part of the TRichEdit
into a TImage->Canvas...
As it should be, because that is all you are actually copying. You are
sizing the Image to the visible dimensions of the RichEdit, and then copying
only the content within that area (even then, you are copying from the
Form's Canvas, not the RichEdit itself).
Quote
how can i save the ENTIRE text, where you have to scroll down the
TRichEdit...??
Have you tried the PaintTo() method yet?
Gambit
 

Re:How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
As it should be, because that is all you are actually copying. You are sizing the Image to the visible dimensions of the
RichEdit, and then copying only the content within that area (even then, you are copying from the Form's Canvas, not the RichEdit
itself).
Have you tried the PaintTo() method yet?


Gambit
Hi Remy,
could you explain me how to use PaintTo() correctly....?
as you see, i've tried: Image1->Canvas->PaintTo(...)
but of course it's not correct...
RichEdit1->PaintTo(...) seems to be correct, but what should be
the device context..? the handle of the RichEdit himself ??
could you show me the correct usage ?
thanks...
Oren
/**************************************************/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Image1->Width = RichEdit1->Width; Image1->Height = RichEdit1->Height;
// TRect R = Rect(RichEdit1->Left, RichEdit1->Top, RichEdit1->Left + RichEdit1->Width, RichEdit1->Top + RichEdit1->Height);
// Image1->Canvas->CopyRect(Image1->ClientRect, Canvas, R);
// use: void __fastcall PaintTo(HDC DC, int X, int Y);
// RichEdit1->PaintTo(RichEdit1->Handle, RichEdit1->Left + RichEdit1->Width, RichEdit1->Top + RichEdit1->Height);
Image1->Canvas->PaintTo(RichEdit1->Handle, RichEdit1->Left + RichEdit1->Width, RichEdit1->Top + RichEdit1->Height);
Image1->Picture->SaveToFile("C:\\down\\RichEdit_graphic.bmp");
}
 

{smallsort}

Re:How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

Oren Halvani wrote:
Quote
could you explain me how to use PaintTo() correctly....?
as you see, i've tried: Image1->Canvas->PaintTo(...)
but of course it's not correct...

RichEdit1->PaintTo(...) seems to be correct, but what should be
the device context..? the handle of the RichEdit himself ??

could you show me the correct usage ?
It paints *to* a device context:
RichEdit1->PaintTo(Image1->Canvas->Handle, 0, 0);
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

"Michel Leunen" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
RichEdit1->PaintTo(Image1->Canvas->Handle, 0, 0);

hi Michel,
now i have the following...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Image1->Width = RichEdit1->Width;
Image1->Height = RichEdit1->Height;
RichEdit1->PaintTo(Image1->Canvas->Handle, 0, 0);
Image1->Picture->SaveToFile("C:\\down\\RichEdit_graphic.bmp");
}
but all it returns is a blank graphic (without any text...)
where is the mistake..?
Oren
 

Re:How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

Oren Halvani wrote:
Quote
but all it returns is a blank graphic (without any text...)
where is the mistake..?
PaintTo() doesn't seem to work with edit controls. Try this:
TControlCanvas *cCanvas = new TControlCanvas;
cCanvas->Control = RichEdit1;
TRect sRect,dRect;
sRect = Rect(0,0,RichEdit1->Width,RichEdit1->Height);
dRect = Rect(0,0,Image5->Width,Image5->Height);
Image1->Canvas->CopyRect(dRect,cCanvas,sRect);
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

"Michel Leunen" < XXXX@XXXXX.COM >schrieb im Newsbeitrag news: XXXX@XXXXX.COM ...
Quote
Michel Leunen wrote:

>TControlCanvas *cCanvas = new TControlCanvas;
>cCanvas->Control = RichEdit1;
>TRect sRect,dRect;
>sRect = Rect(0,0,RichEdit1->Width,RichEdit1->Height);
>dRect = Rect(0,0,Image5->Width,Image5->Height);
>Image1->Canvas->CopyRect(dRect,cCanvas,sRect);

delete cCanvas;

Michel
hi Michel,
well it still's the same old problem....
only the visible text of the RichEdit is saved correctly...not the ENTIRE text...
what is wrong ???
here's the code i now working with...
/**********************************************/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Image1->Width = RichEdit1->Width;
Image1->Height = RichEdit1->Height;
TControlCanvas *cCanvas = new TControlCanvas;
cCanvas->Control = RichEdit1;
TRect sRect,dRect;
sRect = Rect(0,0,RichEdit1->Width,RichEdit1->Height);
dRect = Rect(0,0,Image1->Width,Image1->Height);
Image1->Canvas->CopyRect(dRect,cCanvas,sRect);
Image1->Picture->SaveToFile("C:\\down\\RichEdit_graphic.bmp");
delete cCanvas;
}
/**********************************************/
Oren
 

Re:How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

Oren Halvani wrote:
Quote

well it still's the same old problem....
Oops, sorry, I didn't read your first post.
I don't know. Did you try creating an invisible TRichEdit with a width
and height large enough to hold all the lines and then copying its
canvas to a bitmap?
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:How to save the ENTIRE text of a TRichEdit into a graphic ( TImage->Canvas ) ?

"Michel Leunen" < XXXX@XXXXX.COM >schrieb im Newsbeitrag.......
Quote
Oops, sorry, I didn't read your first post.
I don't know. Did you try creating an invisible TRichEdit with a width and height large enough to hold all the lines and then
copying its canvas to a bitmap?

Michel
hi Michel,
well, actually not... but it sounds a bit cheesy, isn't there a safer way to handle the problem ?
thanks for any hint....
Oren