?
Solved

Printing in Form

Posted on 2004-11-24
1
Medium Priority
?
189 Views
Last Modified: 2008-03-06
HI Everyone:

I have a form which has tabcontrol on it. I have generated a report on one of the tab control. I want to print that report on that tab.  How do i print that tab which has report. I am only getting blank form print when i print it. Could you please help me in this.

Thanks and with regards
Ashwin
0
Comment
Question by:Ashwin_shastry
1 Comment
 

Accepted Solution

by:
pramodsk5 earned 800 total points
ID: 12671922
Hey Ashwin:

Define a Printdocument as docToPrint.
Define printDialog printDialog1 and use the following code.This will print anything it does not matter where u use tab or any other control. This basically captures the screen and print it.

[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 docToPrint_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}


private void CaptureScreen()
{
                  test.Text ="In capture Screen";
                  Graphics mygraphics = this.CreateGraphics();
                  Size s = this.Size;
                  test.Text = this.Width.ToString() + this.Height.ToString();
                  memoryImage = new Bitmap(this.Width, this.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 print_Click(object sender, System.EventArgs e) // onclick of print button
{
                  CaptureScreen();
                                          
                  PrintDialog1.AllowSomePages = true;

                  PrintDialog1.ShowHelp = true;
            
                  PrintDialog1.Document = docToPrint;

                  DialogResult result = PrintDialog1.ShowDialog();

                  // If the result is OK then print the document.
                  if (result==DialogResult.OK)
                  {
                        //docToPrint.PrintPage += new PrintPageEventHandler(this.docToPrint_PrintPage);
                        
                        

                        docToPrint.Print();
                  }
            }


I think this would work for you.Have fun...

Pramod
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question