在特定选项卡中打印多页富文本框 C#

发布于 2024-12-12 15:05:11 字数 727 浏览 3 评论 0原文

我正在做一个带有多个选项卡的网络浏览器,每个选项卡可能会有一个与其他选项卡不同的新网站。 现在我想做的是在特定选项卡上打印页面,当我尝试打印时该页面可能包含多个页面。 这是我的代码,代码的问题是它只打印一页并且在最后一个选项卡上已打开。任何建议:

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

I am doing a web browser with multiple tabs and each tab probably will have a new website differs from the other tabs.
now what i am trying to do is to print the page on a specific tab and the page might consists of multiple pages when i am trying to print.
this is my code and the problem with the code is it is only printing one page and on the last tab had been opened. any suggestions:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再浓的妆也掩不了殇 2024-12-19 15:05:12

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

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

    }

This is how i did it: the Print document contains this code:

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

    }

this is the print button:

   private void PrintButton_Click(object sender, EventArgs e)
    {
        stringToPrint = tabsProperties[tabsProperties.IndexOf(new TabProperties(this.tabControl1.SelectedIndex))].TabHtml;

        printDialog1.ShowDialog();
        printDocument1.Print();

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文