Solved

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

Posted on 2004-09-01
4
303 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
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now