473,414 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Print Screen has trouble after first time

Hi,
I have a tabpage with a print button. This button tries to do a print
screen, and it works fine the first time, but if I try to press print again,
I get error:
An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.drawing.dll
Additional information: A generic error occurred in GDI+.

I'm going about print-screening by first capturing a bitmap of the screen,
saving it, and then calling for the print. Here is the code that I have when
the print button is pressed:
(CurrentPage is declared as a private Bitmap)
Graphics currentTab = this.CreateGraphics();
Size s = this.Size;
Bitmap memoryImage = new Bitmap(s.Width - 10, s.Height - 36, currentTab);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = currentTab.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 2, 2, 13369376);
CurrentPage = memoryImage;
currentTab.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
CurrentPage.Save("sCurrentPage.bmp",System.Drawing .Imaging.ImageFormat.Bmp);

PrintDocument pd = new PrintDocument();
PageSetupDialog pg = new PageSetupDialog();
printDialog1.Document = pd;
pg.Document = pd;
pg.PageSettings.Landscape = true;
DialogResult result = printDialog1.ShowDialog();

if (result==DialogResult.OK)
{
pd.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler(Prin tCurrentPage);
pd.Print();
}
pd.Dispose();

The PrintCurrentPage event handler follows:
private void PrintCurrentPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
CurrentPage = new Bitmap(@"C:\sCurrentPage.bmp");}
e.Graphics.DrawImage(CurrentPage, 0, 0);
}

I'm guessing there's a problem using Print Document pd more than once. Any
suggestions on what to do?
Thanks,
Mel

Nov 18 '05 #1
0 1582

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Samantha | last post by:
I am new to Python and I am having considerable trouble trying to print (using a simple script) to the default printer rather than the screen. Thanks for any help. S
4
by: Julie Siebel | last post by:
Apologies...I'm sure this has been asked before, but I can't seem to come up with the correct Google search terms. While my problem is with stylesheets, the errors are being caused by my...
3
by: Jared Frailey | last post by:
I'm new to CSS and I want to show URLs for links in parentheses when printing. Example: Given the html: <a href="http://www.google.com">Google</a> Print: Google (http://www.google.com) ...
48
by: David J Patrick | last post by:
I'm trying to rewrite the CSS used in http://s92415866.onlinehome.us/files/ScreenplayCSSv2.html. using the w3.org paged media standards as described at http://www.w3.org/TR/REC-CSS2/page.html ...
3
by: Garmt de Vries | last post by:
On the website of the Dutch Jules Verne Society (www.jules-verne.nl), we have several forms that visitors can use to order something, or to apply for membership. Of course, a form's primary purpose...
24
by: Rhino | last post by:
I am dabbling with print CSS for the first time and I need some guidance. The web pages on my site look fine - to my untrained eye - when displayed on the monitor in any of the standard browsers....
13
by: katysei | last post by:
I have to print several large structs to print the screen. I was wondering if thers a tool to do so automaticly struct A { int i; char * s; }
10
by: Ed Jay | last post by:
I do not want to load two style sheets for screen and print media. I'm having difficulty grasping the use of the @print statement, or its syntax. Would someone please provide a simple explanation....
2
nathj
by: nathj | last post by:
Hi, I've just developed a print style sheet for a site I'm working on and it's pretty much working as expected. The only trouble is that links aren't displaying. I know that a link on printed...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.