Printing in Form

Posted on 2004-11-24
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
Question by:Ashwin_shastry
    1 Comment

    Accepted Solution

    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.

                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);

    private void print_Click(object sender, System.EventArgs e) // onclick of print button
                      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);


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


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now