2011-10-28 6 views
0

複数のタブを持つWebブラウザを実行しており、それぞれのタブには新しいWebサイトが他のタブと異なる可能性があります。 今私がしようとしているのは、特定のタブにページを印刷することです。印刷しようとしているときにページが複数のページで構成されている可能性があります。 これは私のコードであり、コードの問題は1ページだけを印刷し、最後のタブを開いていたことです。任意の提案:特定のタブのリッチテキストボックスを複数のページに印刷するC#

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

あなたは、標準を使用している場合ブラウザタイプのオブジェクトには、独自の印刷メソッドが必要です。 – Kell

+1

Webブラウザの*複数のインスタンスをサポートするプログラム用に* RichTextBoxを1つ持つことはできますか? RTBはブラウザとどのように関連していますか? –

+0

httpリクエストを送信し、データをHTMLコードとして取得しています。レンダリングまたはwebbroswerツールを使用していないため、リッチテキストボックスは新しいタブごとに作成されます –

答えて

0

これは私がそれをやった方法です:印刷文書は、このコードが含まれています

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

    }