2016-06-30 4 views
1

Windowsアプリケーションでは、PrintPriviewコントロールに複数のアイテムを印刷しますが、アイテムが25を超えると、次のページに移動して残りのアイテムを印刷しません。私はe.Hasmorepages = trueを使用する必要があることを知っていますが、正しく使用する方法を理解することはできません。助けてください。PrintPreviewコントロールで複数ページを表示する方法#

スクリーンショット - 事前に Click here to see screen shot

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
    { 
     Bitmap bmp = Properties.Resources.logo2; 
     Image image = bmp; 
     e.Graphics.DrawImage(image, 0, 0, image.Width, image.Height); 

     e.Graphics.DrawString("Date: " + DateTime.Now.ToShortDateString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, 160)); 
     e.Graphics.DrawString("Client Name: " + ClientNameTextBox.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, 190)); 

     e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, 235)); 
     e.Graphics.DrawString("Item Name", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(30, 255)); 
     e.Graphics.DrawString("Quantity", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(380, 255)); 
     e.Graphics.DrawString("Unit Price (£)", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(510, 255)); 
     e.Graphics.DrawString("Total Price (£)", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(660, 255)); 
     e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, 270)); 

     int yPos = 295; 

     foreach (var i in shoppingCart) 
     { 
      e.Graphics.DrawString(i.ItemName, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(30, yPos)); 
      e.Graphics.DrawString(i.Quantity.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(400, yPos)); 
      e.Graphics.DrawString(i.UnitPrice.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(550, yPos)); 
      e.Graphics.DrawString(i.TotalPrice.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(700, yPos)); 
      yPos += 30; 

     } 

     e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, yPos)); 

     e.Graphics.DrawString("Total Amount:  £" + TotalAmountTextBox.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(550, yPos + 30)); 
     e.Graphics.DrawString("Sales Tax (16%): £" + SalesTaxTextBox.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(550, yPos + 60)); 
     e.Graphics.DrawString("Total To Pay:  £" + TotalToPayTextBox.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(550, yPos + 90)); 

     e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(25, yPos + 120)); 

    } 

感謝。それが最大ページ高値

c)の上にあるとき

よろしく、

答えて

1

はい、あなたが必要

a)はtrueにHasMorePagesを設定)y値に

Bを見ますprintpageイベントのままにします。

必要な場合は、次のページを印刷またはプレビューするいずれかのとき、それはすなわち、再び呼び出されます。..

また、あなたはクラスレベルの変数に印刷されているのカートを追跡する必要があります; foreachをループ番号forに置き換えてください。ループから抜け出し、yがあなたのページに収まる最大値より大きい場合、イベントからreturnも出ます!

ヘッダーを繰り返すようにも設計されていますが、それは正しいと思います。最後に、別のクラスレベルの変数は、ページ番号を追跡する必要があります。

+0

ありがとう、TaW。 foreachをforループに変更しました。高さを調べる代わりに、表示された項目の数を使用しました。 –

関連する問題