本文介绍了具有RTF文件的C#中的PrintPreview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经用C#开发了Windows应用程序.
我正在使用Printpreview控件显示输出(就像VB6中的VSPrinter7工具一样).
在C#中,我试图将WORDPAD文件的内容打印到Printpreview的文档中.
我无法获得所需的确切输出.
任何人都可以帮助我将RTF文件的内容粘贴到C#中的Printpreview控件中吗?
这是我的代码段.如果您知道解决方案,请帮助我.
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); //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.
*/
推荐答案
这篇关于具有RTF文件的C#中的PrintPreview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!