I have developed a windows application in C#.
I am using Printpreview control for showing outputs
(just like VSPrinter7 tools in VB6).
In C# I am trying to print the content of a WORDPAD file into Printpreview's document.
I can not get exact output that I want.
Can any one help me to paste the content of RTF file into Printpreview control in C#?
Here is my code snippet. If you know the solution please help me.
private PrintPreviewControl PrintCtrl = null;
public RichTextBox TmpRTBx = null;
public void CreatePrintComponents()
{
try
{
#region Create the PrintPreviewControl and its Document
PrintCtrl = new PrintPreviewControl();
PrintCtrl.Name = "PrintCtrl1";
PrintCtrl.Location = new Point(10, 30);
PrintCtrl.Size = new Size(800, 680);
PrintCtrl.Document = PrintDoc;
AppPath = Path.GetDirectoryName(Application.ExecutablePath);
PrintCtrl.Document.DocumentName = @"C:\Docum.doc";
PrintCtrl.Zoom = 0.5;
PrintCtrl.UseAntiAlias = true;
PrintCtrl.Visible = true;
this.PrintDoc.PrintPage += new PrintPageEventHandler(PrintDoc_PrintPage);
this.PrintDoc.QueryPageSettings += new QueryPageSettingsEventHandler(PrintDoc_QueryPageSettings);
#endregion
TmpRTBx = new RichTextBox();
TmpRTBx.Name = "TmpRTBx";
TmpRTBx.Size = new Size(1000, 200);
TmpRTBx.Location = new Point(1, 750);
TmpRTBx.Visible = false;
#region Add All Created Components into the form
Controls.Add(this.PrintCtrl);
Controls.Add(this.TmpRTBx);
#endregion
}
catch (Exception ex)
{
MessageBox.Show("btnINSTANTPREVIEW_CLICK error :\n" + ex.Message);
}
}
void PrintDoc_QueryPageSettings(Object sender, QueryPageSettingsEventArgs e)
{
e.PageSettings.Landscape = false;
e.PageSettings.PaperSize = new PaperSize("Paper", 827, 1169);
e.PageSettings.Margins = new Margins(250, 250, 250, 250);
}
public string AppPath=string.empty;
void PrintDoc_PrintPage(Object sender, PrintPageEventArgs e)
{
AppPath = Path.GetDirectoryName(Application.ExecutablePath);
text = AppPath + @"\Sample.rtf";
TmpRTBx.LoadFile(text);
TmpRTBx.Visible = true;
}