1

私は C# にはかなり慣れていませんが、ようやく最初のプログラムを起動して実行し、それを印刷する必要があります。Excel に似た、さまざまなタブ コントロールに情報と計算を表示するウィンドウ フォームです。現在表示されているページは copyfromscreen メソッドで正常に印刷されますが、追加のページを正しく印刷することができません。一度に印刷できるようにしたいタブが約 20 あります。コントロールの内容をテキストファイルに印刷する方法を見つけましたが、フォームがどのように見えるかを印刷できるようにしたいと思っています。ありがとう。

    Bitmap memoryImage;
    Bitmap memoryImage2;
    private void CaptureScreen()
    {

        Graphics myGraphics = this.CreateGraphics();
        Size s = tabControlMain.Size;
        s.Width = s.Width + 20;
        memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
        Graphics memoryGraphics = Graphics.FromImage(memoryImage);
        memoryGraphics.CopyFromScreen(this.Location.X+15, this.Location.Y+80, 0, 0, s);

        tabControlMain.SelectedIndex = 1;
        memoryImage2 = new Bitmap(s.Width, s.Height, myGraphics);
        Graphics memoryGraphics2 = Graphics.FromImage(memoryImage2);
        memoryGraphics2.CopyFromScreen(this.Location.X + 15, this.Location.Y + 80, 0, 0, s);


    }
    private void printDocumentReal_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(memoryImage, 0, 0);
        e.Graphics.DrawImage(memoryImage2, 0, 550);

    }
    private void printToolStripButton_Click(object sender, EventArgs e)
    {
        CaptureScreen();
        printDocumentReal.Print();
    }
4

2 に答える 2

0

代わりに次DrawToBitmapのメソッドを使用してみてください:TabPage

private void CaptureScreen()
{
    memoryImage = new Bitmap(tabControlMain.SelectedTab.Width, tabControlMain.SelectedTab.Height);
    tabControlMain.SelectedTab.DrawToBitmap(memoryImage, tabControlMain.SelectedTab.ClientRectangle);
    tabControlMain.SelectedIndex = 1;
    memoryImage2 = new Bitmap(tabControlMain.SelectedTab.Width, tabControlMain.SelectedTab.Height);        
    tabControlMain.SelectedTab.DrawToBitmap(memoryImage2, tabControlMain.SelectedTab.ClientRectangle);
}

のすべての画像を取得するにはTabPages、次のようなループを作成できます。

List<Bitmap> images = new List<Bitmap>();
private void CaptureScreen(){
   foreach(TabPage page in tabControlMain.TabPages){
      Bitmap bm = new Bitmap(page.Width, page.Height);
      tabControlMain.SelectedTab = page;
      page.DrawToBitmap(bm, page.ClientRectangle);
      images.Add(bm);
   }
}
//Then you can access the images of your TabPages in the list images
//the index of TabPage is corresponding to its image index in the list images
于 2013-08-18T07:04:23.270 に答える