i made a form that consists of labels !! this form is like an invoice .. all labels and lists contains the items and its const and at the end the total cost ..

now i have a print button, and i would like to print the contents of the labels??

how can i do this ??

pls help

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
   Graphics mygraphics = this.CreateGraphics();
   Size s = this.Size;
   memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
   Graphics memoryGraphics = Graphics.FromImage(memoryImage);
   IntPtr dc1 = mygraphics.GetHdc();
   IntPtr dc2 = memoryGraphics.GetHdc();
   BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
   mygraphics.ReleaseHdc(dc1);
   memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
   e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printButton_Click(System.Object sender, System.EventArgs e)
{
   CaptureScreen();
   printDocument1.Print();
}

Hi try this.... it will print the entire form and its contents.. hope it helps...

but does this become like a print screen?

since i dont want it like a print screen

Use this MSDN link to print the Text property of your Labels.

tnks !! i'll try it in the morning :)

One more suggestion: You can create a report (Crystal Report would be perfect), pass data of label to it, design it by your needs, and print it out.
Thats why Reports are made for.

In that case crystal report is the only option for u... and it is the best... try it

tnkls !! i manage to print and print preview !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.