PrintToFile (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example displays a print dialog box with a Print to File check box, and then prints the contents of a rich edit control to the indicated destination.s Verify that the file is saved by the SaveDialog.

Code

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
  PrintDialog1->Options << poPrintToFile;
  PrintDialog1->PrintToFile = true;
  if (PrintDialog1->Execute())
  {
	if (PrintDialog1->PrintToFile)
    {
	  SaveDialog1->Title = L"Print to છૐ૨૪ File:";

	  /* Save in UTF8 format. */
      if (SaveDialog1->Execute())
		RichEdit1->Lines->SaveToFile(SaveDialog1->FileName, TEncoding::UTF8);
	  else
		RichEdit1->Print("");
	}
  }
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
// You may need to change this path to suit your environment.
  wchar_t const *Path = L"..\\overview.rtf";
  RichEdit1->PlainText = false;

  /* Load from UTF8 format. */
  RichEdit1->Lines->LoadFromFile(Path, TEncoding::UTF8);
  RichEdit1->ScrollBars = ssVertical;
}

Uses