?
Solved

Printing a paper form (in BMP) from windows application. The Windows application plugs in values...

Posted on 2004-09-01
4
Medium Priority
?
319 Views
Last Modified: 2010-04-15
I have a BMP image (the form is also in PDF) that contains a scanned copy of a paper form that we need to fill out. Is it possible to use this image in my application so that the application can print out the form and the data that the user entered? For example, the user loads the application and a normal Windows Form asks for the user's name. When the user enters the name
and clicks on the "Print" button, I'd like to print the form in the jpg
image and include the person's name in that form (in the appropriate
position).
I wanted to use a Windows Form (whose background would be the image), add a
textbox, and then print the Windows Form (with the txtbox that includes the
user's name), but the Windows Form's size is limited to the screen
resolution.
Someone suggested using PrintDocument but from what I understand, that'll only print the document. I still need to insert some values at run-time before printing it.
Any suggestions are appreciated.
Thanks.
0
Comment
Question by:MyersA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:GrumbleBot
ID: 11953576
Here is an example from MSDN.

Hope it Helps.

Good Luck

Example
[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 CaptureScreen()
{
   Graphics mygraphics = this.CreateGraphics();
   Size s = this.Size;
   memoryImage = new Bitmap(s.Width, s.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 printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
   e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printButton_Click(System.Object sender, System.EventArgs e)
{
   CaptureScreen();
   printDocument1.Print();
}
Compiling the Code
This example requires:

A PrintDocument component named printDocument1 with a PrintPage event handler.
A Button named printButton with a Click event handler.
The example code replaces the existing event handlers. The form is printed when printButton is clicked.

Robust Programming
The following conditions may cause an exception:

You do not have permission to access the printer.
You do not have permission to use unmanaged code.
There is no printer installed.
Security
In order to run this example, you must have permission to execute unmanaged code and to access the printer.

0
 
LVL 2

Author Comment

by:MyersA
ID: 11954053
Thanks for the info.
It didn't work quite as expected. First, it prints out the Windows taskbar. Also, Form class limits the size of the form so it's not larger than the screen size, so I won't be ablt to create a form that's as big as the bmp I'll be importing. And I don't think I can plug in the values during runtime.

0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12040533
PAQed, with points refunded (100)

Computer101
E-E Admin
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question