 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Yahia El-Qasem Guest
|
Posted: Mon Jul 28, 2003 10:51 pm Post subject: Re: Report to Screen Option |
|
|
IIRC a TBitmap has a Canvas you can draw on... so just create a TBitmap with
the width / height / color depth you want and draw on its canvas... you can
view it on a form...
Yahia
"Ph.D." <phild (AT) aix (DOT) cc> schrieb im Newsbeitrag
news:3f25a84f (AT) newsgroups (DOT) borland.com...
| Quote: | I have an application which prints a report on demand.
I'm using TPrinter and drawing on the Canvas like this:
TPrinter *ptr = Printer ();
// other code
ptr->Canvas->TextOut (xx, yy, mysting);
This works great for a hard copy report.
However, I'd like to give the user the option to view the
report on the screen. It would seem that I could make
ptr point to a different object and use (most of) the same
code. Can anyone point me in the correct direction?
Any sample code out there?
|
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Jul 29, 2003 12:27 am Post subject: Re: Report to Screen Option |
|
|
"Ph.D." <phild (AT) aix (DOT) cc> wrote:
| Quote: | [...] It would seem that I could make ptr point to a different
object and use (most of) the same code.
|
I like Yahias' suggestion on using a Bitmap but to answer your
question, go a level deeper by skipping the Printer() ptr and
assign a TCanvas* instead. All you should need to do to make
it work with the printer or screen is a check at the start and
then deleting some code:
TCanvas* pCanvas;
TPrinter *ptr = Printer();
Graphics::TBitmap* MyBitMap = NULL;
if( PrintingToScreen )
{
MyBitMap = new Graphics::TBitmap;
MyBitMap->Height = ptr->PageHeight;
MyBitMap->Width = ptr->PageWidth;
pCanvas = MyBitMap->Canvas;
pCanvas->Brush->Color = clWhite;
pCanvas->FillRect( TRect(0, 0, MyBitMap->Height, MyBitMap->Width ) );
}
else pCanvas = ptr->Canvas;
// set the fonts ect
if( !PrintingToScreen ) ptr->BeginDoc();
// Now edit existing code. Change this
ptr->Canvas->TextOut (xx, yy, mysting);
// To this:
pCanvas->TextOut (xx, yy, mysting);
if( !PrintingToScreen ) ptr->EndDoc();
else DisplayBitMap();
// finally
if( MyBitMap ) delete MyBitMap;
~ JD
|
|
| Back to top |
|
 |
Ph.D. Guest
|
Posted: Thu Jul 31, 2003 1:24 am Post subject: Re: Report to Screen Option |
|
|
Thank you to both JD and Yahia for your suggestions.
--Ph. D.
"JD" <nospam (AT) nospam (DOT) com> wrote
| Quote: |
"Ph.D." <phild (AT) aix (DOT) cc> wrote:
[...] It would seem that I could make ptr point to a different
object and use (most of) the same code.
I like Yahias' suggestion on using a Bitmap but to answer your
question, go a level deeper by skipping the Printer() ptr and
assign a TCanvas* instead. All you should need to do to make
it work with the printer or screen is a check at the start and
then deleting some code:
TCanvas* pCanvas;
TPrinter *ptr = Printer();
Graphics::TBitmap* MyBitMap = NULL;
if( PrintingToScreen )
{
MyBitMap = new Graphics::TBitmap;
MyBitMap->Height = ptr->PageHeight;
MyBitMap->Width = ptr->PageWidth;
pCanvas = MyBitMap->Canvas;
pCanvas->Brush->Color = clWhite;
pCanvas->FillRect( TRect(0, 0, MyBitMap->Height, MyBitMap->Width ) );
}
else pCanvas = ptr->Canvas;
// set the fonts ect
if( !PrintingToScreen ) ptr->BeginDoc();
// Now edit existing code. Change this
ptr->Canvas->TextOut (xx, yy, mysting);
// To this:
pCanvas->TextOut (xx, yy, mysting);
if( !PrintingToScreen ) ptr->EndDoc();
else DisplayBitMap();
// finally
if( MyBitMap ) delete MyBitMap;
~ JD
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|