Advertisement

07.04.2008 at 12:04AM PDT, ID: 23538875
[x]
Attachment Details

How to Print data from a Panel Control using C#

Asked by atulmodi in Microsoft Visual C#.Net, C# Programming Language, .NET Framework 2.0

Tags: C#

Hello,
on my windows form i have a panel control which consist of Label for displaying certain information. i want to print those information directly from panel. but i failed. is there any way to print all the data from the Panel Control in the way they are displayed in the Panel.

or is there any to way to save those information to an image file so that i can directly print that image file.

i am using following code for printing.

Please help as soon as possible.

Best Regards.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
public void GetPrintArea(Panel pnl)
 {
 Rectangle rect = new Rectangle(pnl.Location.X, pnl.Location.Y, pnl.Width ,pnl.Height);
            Graphics myGraphics = pnl.CreateGraphics();
            Size s = pnl.PreferredSize;  
            MemoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(MemoryImage);
            memoryGraphics.CopyFromScreen(pnl.Location.X,pnl.Location.Y, 0, 0, s,CopyPixelOperation.SourceCopy);
 }
 
 void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
 {
    e.Graphics.DrawImage(MemoryImage, 0, 0);
 }
 #endregion
 public void Print(Panel pnl)
 {
            pannel = pnl;
            GetPrintArea(pnl); 
            previewdlg.Document = printdoc1;
            previewdlg.ShowDialog();  
 }
 
Loading Advertisement...
 
[+][-]07.04.2008 at 01:53AM PDT, ID: 21931792

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 12:56AM PDT, ID: 21936269

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, C# Programming Language, .NET Framework 2.0
Tags: C#
Sign Up Now!
Solution Provided By: dikshanttyagi
Participating Experts: 2
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628