PrinterPageWidth (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses a button and a memo on a form. When you click the button, the content of the memo is printed, with a 200-pixel border around the page. Note: The TMemo wraps the lines of the text files, so, in order to see the TextRect clip, the memo width must be large and the lines in the text file must be long.

Code

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  Memo1->Width = 1000;
  Memo1->Lines->LoadFromFile("..\\readme.txt");
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Printer()->BeginDoc();
  int margin = 1000;
  int X = margin;
  int Y = margin;
  int I = 0;
  while(Y < Printer()->PageHeight)
  {
	Canvas->TextRect(Rect(X, Y, Printer()->PageWidth-margin, Printer()->PageHeight-margin),
					X, Y, Memo1->Lines->Strings[I]);
	Y = Y + 100;
	I = I + 1;
  }
  Printer()->EndDoc();
}

Uses