Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)
Posted

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

The DataGridViewPrinter Class[^]
 
Share this answer
 
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)
{

}

}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900