打印机通用:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font font = new Font("宋体", 12);
Brush bru = Brushes.Black;
Image bitmap = new Bitmap(panel1.BackgroundImage.Width, panel1.BackgroundImage.Height);
Graphics g = e.Graphics; //先建立画布
g.DrawImage(bitmap, 0, 0);
int x = 0;//调整位置信息
int y = 0;
foreach (Control item in panel1.Controls)
{
if (item is TextBox)
{
Control tx = (item as Control);
g.DrawString(tx.Text, font, bru, tx.Left + x, tx.Top + y);
}
if (item is PictureEdit)
{
Control tx = (item as Control);
e.Graphics.DrawImage(pictureEdit1.Image, tx.Left + x, tx.Top + y);
}
}
}
//打印
private void simpleButton1_Click(object sender, EventArgs e)
{
PrintText();
PrintDialog pdia = new PrintDialog();
PrintDocument pdoc = new PrintDocument();
pdoc.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
if (pdia.ShowDialog() == DialogResult.OK)
{
pdoc.Print();
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。