Click here to Skip to main content
15,920,029 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to print a Form generated by Visual Studio using C#.NET. I am trying to use tabControl. I don't get any errors. But when I print, I get the blank paper. I don't get the content in the tabControl. The code I am using is below:

What I have tried:

C#
Bitmap memoryImage;
private void CaptureScreen()
        {
            Graphics myGraphics = this.CreateGraphics();
            Size s = tabControlMain.Size;

            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
     memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
         }

private void printDocumentReal_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 0, 0);
        }

        private PrintDocument printDocumentReal = new PrintDocument();
        
        private void printToolStripButton_Click(object sender, EventArgs e)
        {
            CaptureScreen();
            printDocumentReal.Print();
        }
Posted
Updated 22-Sep-16 4:46am
v2
Comments
[no name] 22-Sep-16 10:08am    
https://msdn.microsoft.com/en-us/library/6he9hz8c(v=vs.110).aspx

 
Share this answer
 
Comments
Savi kolla 22-Sep-16 14:27pm    
Thanks so much !!!
Maciej Los 22-Sep-16 14:49pm    
You're very welcome.
If you are the one who down-voted my answer, i'm asking you: why? It wasn't helpful? Note, that 3 stars means neutral...
Savi kolla 22-Sep-16 16:44pm    
Your answer really worked and I am able to print now. I wanted to give all the stars but, it didn't let me. Even now I am able to click on only on 2nd star!
Maciej Los 22-Sep-16 16:48pm    
;)

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