Printing in Form

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
Ashwin_shastryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pramodsk5Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.