//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "PrintToFile.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: PrintToFile
// Method: Dialogs.TPrintDialog.PrintToFile
// Method: Classes.TStrings.SaveToFile

// BeginCode
/*
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:
Verify that the file is saved by the SaveDialog.
*/
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
  PrintDialog1->Options << poPrintToFile;
  PrintDialog1->PrintToFile = true;
  if (PrintDialog1->Execute())
  {
	if (PrintDialog1->PrintToFile)
    {
	  SaveDialog1->Title = "Print to File:";

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

void __fastcall TForm1::FormCreate(TObject *Sender)
{
// you may need to change this path to suit your environment
  char const *Path = "..\\overview.rtf";
  RichEdit1->PlainText = false;

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

