Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8616029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:31:23+00:00 2026-06-12T05:31:23+00:00

I have created a Windows Application in Visual Studio 2005. In this application, the

  • 0

I have created a Windows Application in Visual Studio 2005. In this application, the user is able to export the current active form to a PDF file.

The problem is how do I save it with the values of textboxes? When I leave them empty, there’s no problem. Then I give some input and get output in textboxes, I click export, and I get a message “A generic error occurred in GDI+”. And in Output window of Visual Studio:

A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll

Here’s my code:

For capturing active screen:

try
{
    Rectangle bounds = this.Bounds;
    using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
    {
        using (Graphics g = Graphics.FromImage(bitmap))
        {
            g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
        }
        bitmap.Save("C://Rectangle.bmp", ImageFormat.Bmp);
    }
}
catch(Exception e)
{
    MessageBox.Show(e.Message.ToString());
}

For exporting to pdf:

captureScreen();

PdfDocument doc = new PdfDocument();

PdfPage oPage = new PdfPage();

doc.Pages.Add(oPage);
oPage.Rotate = 90;
XGraphics xgr = XGraphics.FromPdfPage(oPage);
XImage img = XImage.FromFile(@"C://Rectangle.bmp");

xgr.DrawImage(img, 0, 0);

doc.Save("C://RectangleDocument.pdf");
doc.Close();

Please help me on exporting the form to pdf including values of textboxes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:31:24+00:00Added an answer on June 12, 2026 at 5:31 am

    I am assuming this exception is thrown when you try to call CopyFromScreen? I have written very similar code before with no problems, but there are a few minor differences.

    The first thing I see is that the Bounds property returns a point as a relative position, but the CopyFromScreen method expects the point as an absolute position. You probably want to call this.PointToScreen to get the absolute screen position of the point before calling CopyFromScreen.

    Second, it should “just work” but just for my own sanity I usually use CopyPixelOption.SourceCopy in the CopyFromScreen call.

    I’m not sure about the implementation of CopyFromScreen and Bitmap.Save, but you might want to move the Save call so it happens before the graphics object is disposed. This is probably not necessary, but if there’s any sort of delayed computation going on that could cause you problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a project in Visual Studio using a Windows Form application C#.
I have created a windows mobile application in Visual Studio. I want to templatize
I have created a standard windows forms application in Visual Studio 2010. public ref
I have created a standard windows forms application in Visual Studio 2010. public ref
I have created a web application using Visual Studio 2010 on a Windows Server
Visual Studio 2005 I have developed an application using C#. I have created an
I have created a windows service using Visual Studio 2005. I have created a
I have created a Windows Forms Application project by Visual Studio.Net 2008. In order
I have a Windows CE Form (NETCF 3.5) application that I've created via Visual
I have a Windows Forms application that was created in Visual Studio 2008 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.