C# 打印特定选项卡中的富文本框多页C
我正在做一个有多个选项卡的web浏览器,每个选项卡可能都有一个不同于其他选项卡的新网站。 现在我要做的是在一个特定的选项卡上打印页面,当我尝试打印时,页面可能由多个页面组成。 这是我的代码,代码的问题是它只打印了一页,而最后一个选项卡已经打开。任何建议:C# 打印特定选项卡中的富文本框多页C,c#,winforms,printdocument,printdialog,C#,Winforms,Printdocument,Printdialog,我正在做一个有多个选项卡的web浏览器,每个选项卡可能都有一个不同于其他选项卡的新网站。 现在我要做的是在一个特定的选项卡上打印页面,当我尝试打印时,页面可能由多个页面组成。 这是我的代码,代码的问题是它只打印了一页,而最后一个选项卡已经打开。任何建议: //this is the printDocemnt from the toolbox private void printDocument1_PrintPage(object sender, System.Drawing.Printi
//this is the printDocemnt from the toolbox
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font font1 = new Font("Arial", 16, FontStyle.Regular);
e.Graphics.DrawString(rtb.Text, font1, Brushes.Black, 100, 100);//rtb.Text is a richtextbox object that i initialize in the beginning of the form
}
//this is the printbutton just a normal button
private void PrintButton_Click(object sender, EventArgs e)
{
printDialog1.ShowDialog();
printDocument1.Print();
}
我就是这样做的:打印文档包含以下代码:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font font1 = new Font("Arial", 10, FontStyle.Regular);
//e.Graphics.DrawString(tabsProperties[tabsProperties.IndexOf(new TabProperties(this.tabControl1.SelectedIndex))].TabHtml, font1, Brushes.Black, 100, 100);
int charactersOnPage = 0;
int linesPerPage = 0;
// Sets the value of charactersOnPage to the number of characters
// of stringToPrint that will fit within the bounds of the page.
e.Graphics.MeasureString(stringToPrint, font1,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
// Draws the string within the bounds of the page
e.Graphics.DrawString(stringToPrint, font1, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic);
// Remove the portion of the string that has been printed.
stringToPrint = stringToPrint.Substring(charactersOnPage);
// Check to see if more pages are to be printed.
e.HasMorePages = (stringToPrint.Length > 0);
}
这是“打印”按钮:
private void PrintButton_Click(object sender, EventArgs e)
{
stringToPrint = tabsProperties[tabsProperties.IndexOf(new TabProperties(this.tabControl1.SelectedIndex))].TabHtml;
printDialog1.ShowDialog();
printDocument1.Print();
}
如果您使用的是标准浏览器类型的对象,它应该有自己的打印方法。对于一个支持多个web浏览器实例的程序,如何有一个RichTextBox?RTB与浏览器的关系如何?我正在发送http请求并以html代码的形式检索数据。我没有使用渲染或webbroswer工具,并且在每个新选项卡上都创建了富文本框