打印富文本框在一个特定的选项卡多个页面c#

本文关键字:选项 一个 文本 打印 | 更新日期: 2023-09-27 18:12:45

我正在做一个有多个选项卡的网页浏览器,每个选项卡可能会有一个新的网站不同于其他选项卡。现在我要做的是在特定的TAB上打印页面,当我试图打印时,页面可能包含多个页面。这是我的代码和代码的问题是,它只是打印一页,并在最后一个选项卡已打开。有什么建议:

  //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();
    }

打印富文本框在一个特定的选项卡多个页面c#

我是这样做的:打印文档包含以下代码:

        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();
    }