ラベルを作成するための WinForm があります。
を呼び出し、 のを使用しPrintPreviewDialog
て情報を表示します。PrintPageEventArgs
PrintDocument
PrintPageEventHandler
void Document_Printed(object sender, PrintPageEventArgs e) {
// Code goes here
}
ラベルが 8.5x11 レターに向かう小さな住所ラベルである場合PrintPreviewDialog
、PageSettings.PaperSize
.
例: 選択したメディア (Avery プリンター ラベルなど) に 4 つのアイテムが収まるとします。
エンド ユーザーが 1 ~ 4 部の印刷を指定した場合、印刷プレビュー ダイアログにすべての部数が表示されるようにします。
エンド ユーザーが 4 つ以上の項目を指定した場合、印刷プレビュー ダイアログには複数のページが表示されます (これまで複数のページに取り組んだことはありません)。
PrintPageEventHandler
ラベルのサイズに合わせてデータのサイズを変更できますが、に複数のラベルを表示する方法がわかりませんPrintPreviewDialog
。
誰かがこれがどのように行われるかを教えてもらえますか? シートごとに複数のラベル (ドキュメント?) を表示および印刷するにはどうすればよいですか?
編集:これは、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 つ以上のドキュメントを印刷する方法が必要です。この重要な点については、まだ何も触れられていません。それが私が必要とする答えです。