我創建標籤一個WinForm。C#WinForm的PrintPreviewDialog上:打印預覽顯示多個標籤每頁
它調用在使用PrintPageEventArgs
一個PrintPreviewDialog
並顯示信息的PrintDocument
的PrintPageEventHandler
。
void Document_Printed(object sender, PrintPageEventArgs e) {
// Code goes here
}
如果標籤是一個小的地址標籤去,而不是在PrintPreviewDialog
看到一個標籤到8.5x11信,我想看到適合對PageSettings.PaperSize
標籤的數量。
示例:假設四(4)項適合選定的媒體(艾利打印機標籤或任何東西)上。
如果我的最終用戶指定了1到4份要打印的副本,我希望我的「打印預覽」對話框顯示所有副本。
如果我的最終用戶指定超過四(4)項,打印預覽對話框應該顯示多個頁面(我以前從來沒有解決多頁)。
我大小我的數據,以滿足我的標籤尺寸,但我不知道如何讓我的PrintPageEventHandler
對PrintPreviewDialog
顯示超過1個標籤。
有人能告訴我如何做到這一點?如何顯示和打印每張紙上的多個標籤(文檔?)?
編輯:這裏是我的代碼,這是基於2個的RectangleF對象:pageRect和LabelRect:
void Document_Printed(object sender, PrintPageEventArgs e) {
if (printPreview == null) return;
int labelSupport = 1;
RectangleF pageRect = new RectangleF(0, 0, printPreview.Document.DefaultPageSettings.PaperSize.Width, printPreview.Document.DefaultPageSettings.PaperSize.Height);
float fW = (pageRect.Width < LabelRect.Width) ? (pageRect.Width/LabelRect.Width) : (LabelRect.Width/pageRect.Width);
float fH = (pageRect.Height < LabelRect.Height) ? (pageRect.Height/LabelRect.Height) : (LabelRect.Height/pageRect.Height);
// START Portion I need HELP with!
if (1 < LabelsPerPage) {
if (Landscape) {
} else {
}
} else {
if (Landscape) {
} else {
}
}
// END (I think) Portion I need HELP with!
SizeF ratio = new SizeF(fW, fH);
Graphics G = e.Graphics;
foreach (Label item in labelList) {
Console.WriteLine(item.Name);
using (SolidBrush b = new SolidBrush(Color.Black)) {
using (Pen p = new Pen(b)) {
float x = ratio.Width * (float)item.Location.X;
float y = ratio.Height * (float)item.Location.Y;
float w = ratio.Width * (float)item.Size.Width;
float h = ratio.Height * (float)item.Size.Height;
RectangleF r = new RectangleF(x, y, w, h);
G.DrawString(item.Text, item.Font, b, r);
}
}
}
}
編輯2:我需要一種方法來打印1頁上的2頁或更多的文檔。到目前爲止還沒有任何東西能夠解決這個關鍵問題這是我需要的答案。
瞭解PrintPageEventHandler – 2011-04-27 20:41:16
的一些渲染代碼可能會很有用。已經添加了一個代碼示例,從** EDIT:**部分開始。 – jp2code 2011-04-27 20:48:52
這看起來沒問題。我會在該方法的頂部放置一個斷點,然後逐行放置,以確保您期望發生的事情實際上正在發生。例如,您的繪圖循環中的每個項目的大小和位置值是否更改?看起來他們應該但是如果你沒有在別處正確地分配這些值,那麼你可能再次繪製相同的東西,或者在前面的標籤上繪製每個新的標籤。 – 2011-04-27 21:01:44