using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;
namespace kk
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonX1_Click(object sender, EventArgs e)
{
for (int i=1; i <=Int32.Parse(this.textBoxX2.Text); i++)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
PrintPreviewDialog cppd = new PrintPreviewDialog();
cppd.Document = pd;
//cppd.ShowDialog();
pd.Print();
}
}
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = barcodeControl2.ClientRectangle;
//下面是调整打印位置的代码。
rect = new Rectangle(rect.X + (int)13, rect.Y + (int)1, rect.Width, rect.Height);
//打印
barcodeControl2.Draw(g, rect, GraphicsUnit.Inch, 0.01f, 0, null);
g.Dispose();
}
private void Form1_Load(object sender, EventArgs e)
{
this.barcodeControl2.Data = this.textBoxX1.Text;
}
}
}
注rect.X + (int)13, rect.Y + (int)1, rect.Width, rect.Height为调整位置,for (int i=1; i <=Int32.Parse(this.textBoxX2.Text); i++),textBoxX2里输入打印几张。pd.Print();直接打印。
问题解决了,困扰了我几天,现在终于完成,PrintDocument类。