Click here to Skip to main content
15,888,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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);    //A4 paper
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;
 
/* 
HERE I WANT TO WRITE THE CODE FOR PRINT THE CONTENT OF THE "Sample.rtf"\
(OR)
PRINT THE CONTENT OF Richtextbox - TmpRTBx with out changing the font settings and styles.
Note: I already have a Wordpad file called "Sample.rtf" in the location of my Executable Path. Each line of Sample.rtf contains different font settings and styles.
*/
}

/*
In vb6 i was used the VSPrinter tool for printing output. In that i have written the code for print the "Sample.rtf" into VSPrint component's document
 
VSPrint1.PrintFile("Sample.rtf")
 
Using this code line i have complete many of projects. In this same way i am trying to print the Sample.rtf into Printpreview's document.
*/
Posted
Updated 10-Aug-11 21:23pm
v5
Comments
Dalek Dave 11-Aug-11 3:24am    
Edited for Grammar and Readability.

1 solution

Hey first don't shout. Bold and bigger font seems like you are shouting.
And explain what is the exact problem or error. Post your code snippet that causes problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900