在VB 2008中打印 [英] Printing in VB 2008

查看:75
本文介绍了在VB 2008中打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的所有程序员,

我在这里需要帮助..我要创建发票表格,然后我陷入了打印发票的困境.我已经使用数据集将datagridview保存到数据库中.

请帮助我打印发票.给我一些有用的代码. :((
也许我可以直接从xml文件或数据集中进行打印,也可以从datagridview中进行打印.

非常感谢:rose:

(注意:我不想使用Crystal Report,因为尝试加载数据时它非常慢)

dear all programmers,

i need help here.. i am about creating invoice form and then i got stuck about printing the invoice. i have save the datagridview into database using dataset.

please help me to print the invoice. give me some usefull code. :((
maybe i can print directly from the xml file or from dataset or maybe from the datagridview.

THANK YOU VERY MUCH :rose:

(NB : i don''t want to use Crystal Report, coz it''s very slow while trying to load the data)

推荐答案

如果您想要的只是在datagridview本身中,那么这将为您提供帮助.

DataGridViewPrinter类 [
If all you want is there in datagridview itself, then this will help you.

The DataGridViewPrinter Class[^]


此代码是我的.
打印和打印.

此代码在我的计算机上运行.






使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Text;
使用System.Windows.Forms;
使用System.Drawing.Printing;

命名空间printing_a_form
{
公共局部类Form1:Form
{
私人PrintDocument pd = new PrintDocument();
私人PrintDialog pd1 =新的PrintDialog();
私人PrintPreviewDialog ppd =新的PrintPreviewDialog();
private PageSetupDialog pst = new PageSetupDialog();
私人PageSettings ps = new PageSettings();
位图m;
int x = 0;
int y = 0;
公共Form1()
{
InitializeComponent();
}

private void button4_Click(对象发送者,EventArgs e)
{
CaptureScreen();
pd1.Document = pd;
DialogResult res = pd1.ShowDialog();
如果(res == DialogResult.OK)
{
pd.Print();
}

}
私有void CaptureScreen()
{
图形g = this.CreateGraphics();
大小s = this.Size;
m =新的位图(s.Width,s.Height,g);
图形g1 = Graphics.FromImage(m);
g1.CopyFromScreen(this.Location.X,this.Location.Y,0,0,s);
}
私人void pd_PrintPage(System.Object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(m,x,y);
}

私有void Form1_Load(对象发送者,EventArgs e)
{
pd.PrintPage + =新的PrintPageEventHandler(pd_PrintPage);

}

private void button5_Click(对象发送者,EventArgs e)
{
CaptureScreen();
ppd.Document = pd;
ppd.ShowDialog();
}

private void button6_Click(对象发送者,EventArgs e)
{
pst.PageSettings = ps;
如果(pst.ShowDialog()== DialogResult.OK)
x = pst.PageSettings.Margins.Left;
y = pst.PageSettings.Margins.Right;
MessageBox.Show(pst.PageSettings.Landscape.ToString());
MessageBox.Show(pst.PageSettings.Margins.ToString());
}

private void button1_Click(对象发送者,EventArgs e)
{

}

private void button2_Click(对象发送者,EventArgs e)
{

}

private void button3_Click(对象发送者,EventArgs e)
{

}

}
}
This code is my.
print previw and print.

this code is run in my computer.






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace printing_a_form
{
public partial class Form1 : Form
{
private PrintDocument pd = new PrintDocument();
private PrintDialog pd1 = new PrintDialog();
private PrintPreviewDialog ppd = new PrintPreviewDialog();
private PageSetupDialog pst = new PageSetupDialog();
private PageSettings ps = new PageSettings();
Bitmap m;
int x = 0;
int y = 0;
public Form1()
{
InitializeComponent();
}

private void button4_Click(object sender, EventArgs e)
{
CaptureScreen();
pd1.Document = pd;
DialogResult res = pd1.ShowDialog();
if (res == DialogResult.OK )
{
pd.Print();
}

}
private void CaptureScreen()
{
Graphics g = this.CreateGraphics();
Size s = this.Size;
m = new Bitmap(s.Width, s.Height, g);
Graphics g1 = Graphics.FromImage(m);
g1.CopyFromScreen(this.Location.X, this.Location.Y,0,0,s);
}
private void pd_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(m, x, y);
}

private void Form1_Load(object sender, EventArgs e)
{
pd.PrintPage +=new PrintPageEventHandler(pd_PrintPage);

}

private void button5_Click(object sender, EventArgs e)
{
CaptureScreen();
ppd.Document = pd;
ppd.ShowDialog();
}

private void button6_Click(object sender, EventArgs e)
{
pst.PageSettings = ps;
if (pst.ShowDialog() == DialogResult.OK)
x = pst.PageSettings.Margins.Left;
y = pst.PageSettings.Margins.Right;
MessageBox.Show(pst.PageSettings.Landscape.ToString());
MessageBox.Show(pst.PageSettings.Margins.ToString() );
}

private void button1_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

}

private void button3_Click(object sender, EventArgs e)
{

}

}
}


这篇关于在VB 2008中打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆