473,837 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing an Form

Hi

I have designed a form containing data and I want to print that form and the
data as it appears in the Windows Form. I am a beginner with C# and I have
read several "help"s on PrintPage, PrintDialog, etc. but none seem to address
the issue of printing directly from the form. They all talk about printing
from a text file.

Can someone tell me how to print the form and maybe direct me on which to
use PrintPage, PrintDialog.... which?

Thanks
D
Nov 17 '05 #1
4 2822
I can give you some generic information. It depends on what version of
VS you're using. You need to "take a picture" of the form, and pass
that to the drawing object when you print. With VS 2005, there is
actually a copy function you can use. With older versions you may need
to import GDI32 and make calls to that.

This is the code I use to print a form:

protected void PrintActiveForm (object sender, EventArgs e)
{
ToolStripMenuIt em MenuItem=(ToolS tripMenuItem)se nder;
//MessageBox.Show (MenuItem.Name) ;
PrintDialog PD = new PrintDialog();
PrinterSettings PS = new PrinterSettings ();
PrintDocument PrtDoc = new PrintDocument() ;

_ActiveFormImag e = SetSeg_Library. SetCapture.Form (this);

PrtDoc.PrintPag e += new PrintPageEventH andler(PrtDoc_P rintPage);
PD.Document = PrtDoc;
PD.ShowDialog() ;
PrtDoc.Print();

}

void PrtDoc_PrintPag e(object sender, PrintPageEventA rgs e)
{
e.Graphics.Draw Image(this._Act iveFormImage, 0, 0);
}

CsharpNewcommer wrote:
Hi

I have designed a form containing data and I want to print that form and the
data as it appears in the Windows Form. I am a beginner with C# and I have
read several "help"s on PrintPage, PrintDialog, etc. but none seem to address
the issue of printing directly from the form. They all talk about printing
from a text file.

Can someone tell me how to print the form and maybe direct me on which to
use PrintPage, PrintDialog.... which?

Thanks
D

Nov 17 '05 #2
Thanks Gary,

I am using VS 2003. I will tryyour suggestion.

Thanks
D.

"Gary Holbrook" wrote:
I can give you some generic information. It depends on what version of
VS you're using. You need to "take a picture" of the form, and pass
that to the drawing object when you print. With VS 2005, there is
actually a copy function you can use. With older versions you may need
to import GDI32 and make calls to that.

This is the code I use to print a form:

protected void PrintActiveForm (object sender, EventArgs e)
{
ToolStripMenuIt em MenuItem=(ToolS tripMenuItem)se nder;
//MessageBox.Show (MenuItem.Name) ;
PrintDialog PD = new PrintDialog();
PrinterSettings PS = new PrinterSettings ();
PrintDocument PrtDoc = new PrintDocument() ;

_ActiveFormImag e = SetSeg_Library. SetCapture.Form (this);

PrtDoc.PrintPag e += new PrintPageEventH andler(PrtDoc_P rintPage);
PD.Document = PrtDoc;
PD.ShowDialog() ;
PrtDoc.Print();

}

void PrtDoc_PrintPag e(object sender, PrintPageEventA rgs e)
{
e.Graphics.Draw Image(this._Act iveFormImage, 0, 0);
}

CsharpNewcommer wrote:
Hi

I have designed a form containing data and I want to print that form and the
data as it appears in the Windows Form. I am a beginner with C# and I have
read several "help"s on PrintPage, PrintDialog, etc. but none seem to address
the issue of printing directly from the form. They all talk about printing
from a text file.

Can someone tell me how to print the form and maybe direct me on which to
use PrintPage, PrintDialog.... which?

Thanks
D

Nov 17 '05 #3
Hey Gary,

Thanks for the code. As I said in my earlier reply I'm using VS2003 and I
guess I have to import that "gdi32.dll" but using your example I'm not sure
how to do that other than it requires "static extern". This is a little over
my head at this point.

Anyway I tried your code and I seem to be missing some key points. For one
I'm using the click event of a button so I don't think I need:
"ToolStripMenuI tem MenuItem=(ToolS tripMenuItem)se nder;"
MessageBox.Show (MenuItem.Name) ;
Two, don't I need to call PrintActiveForm () and PrtDoc() ? And three, these
are some of the build errors I'm getting:

'TestDB.fclsPas tInfo' does not contain a definition for '_ActiveFormIma ge'

'The name '_ActiveFormIma ge' does not exist in the class or namespace
'TestDB.fclsPas tInfo'

The type or namespace name 'PrtDoc' could not be found (are you missing a
using directive or an assembly reference?)

The type or namespace name 'PrtDoc' could not be found (are you missing a
using directive or an assembly reference?)
D.

"Gary Holbrook" wrote:
I can give you some generic information. It depends on what version of
VS you're using. You need to "take a picture" of the form, and pass
that to the drawing object when you print. With VS 2005, there is
actually a copy function you can use. With older versions you may need
to import GDI32 and make calls to that.

This is the code I use to print a form:

protected void PrintActiveForm (object sender, EventArgs e)
{
ToolStripMenuIt em MenuItem=(ToolS tripMenuItem)se nder;
//MessageBox.Show (MenuItem.Name) ;
PrintDialog PD = new PrintDialog();
PrinterSettings PS = new PrinterSettings ();
PrintDocument PrtDoc = new PrintDocument() ;

_ActiveFormImag e = SetSeg_Library. SetCapture.Form (this);

PrtDoc.PrintPag e += new PrintPageEventH andler(PrtDoc_P rintPage);
PD.Document = PrtDoc;
PD.ShowDialog() ;
PrtDoc.Print();

}

void PrtDoc_PrintPag e(object sender, PrintPageEventA rgs e)
{
e.Graphics.Draw Image(this._Act iveFormImage, 0, 0);
}

CsharpNewcommer wrote:
Hi

I have designed a form containing data and I want to print that form and the
data as it appears in the Windows Form. I am a beginner with C# and I have
read several "help"s on PrintPage, PrintDialog, etc. but none seem to address
the issue of printing directly from the form. They all talk about printing
from a text file.

Can someone tell me how to print the form and maybe direct me on which to
use PrintPage, PrintDialog.... which?

Thanks
D

Nov 17 '05 #4
Some of the code in there is specific to my program. I didn't sanitize
before I sent it. Oddly enough, you will need to attach to the printing
events though.

_ActiveFormImag e is a private type of bitmap that I'm using to pass the
image around between methods which are managing printing events.

Check this site out...it was made for you:
http://www.codeproject.com/csharp/ImageCapture.asp
CsharpNewcommer wrote:
Hey Gary,

Thanks for the code. As I said in my earlier reply I'm using VS2003 and I
guess I have to import that "gdi32.dll" but using your example I'm not sure
how to do that other than it requires "static extern". This is a little over
my head at this point.

Anyway I tried your code and I seem to be missing some key points. For one
I'm using the click event of a button so I don't think I need:
"ToolStripMenuI tem MenuItem=(ToolS tripMenuItem)se nder;"
MessageBox.Show (MenuItem.Name) ;
Two, don't I need to call PrintActiveForm () and PrtDoc() ? And three, these
are some of the build errors I'm getting:

'TestDB.fclsPas tInfo' does not contain a definition for '_ActiveFormIma ge'

'The name '_ActiveFormIma ge' does not exist in the class or namespace
'TestDB.fclsPas tInfo'

The type or namespace name 'PrtDoc' could not be found (are you missing a
using directive or an assembly reference?)

The type or namespace name 'PrtDoc' could not be found (are you missing a
using directive or an assembly reference?)
D.

"Gary Holbrook" wrote:

I can give you some generic information. It depends on what version of
VS you're using. You need to "take a picture" of the form, and pass
that to the drawing object when you print. With VS 2005, there is
actually a copy function you can use. With older versions you may need
to import GDI32 and make calls to that.

This is the code I use to print a form:

protected void PrintActiveForm (object sender, EventArgs e)
{
ToolStripMenuIt em MenuItem=(ToolS tripMenuItem)se nder;
//MessageBox.Show (MenuItem.Name) ;
PrintDialog PD = new PrintDialog();
PrinterSettings PS = new PrinterSettings ();
PrintDocument PrtDoc = new PrintDocument() ;

_ActiveFormImag e = SetSeg_Library. SetCapture.Form (this);

PrtDoc.PrintPag e += new PrintPageEventH andler(PrtDoc_P rintPage);
PD.Document = PrtDoc;
PD.ShowDialog() ;
PrtDoc.Print();

}

void PrtDoc_PrintPag e(object sender, PrintPageEventA rgs e)
{
e.Graphics.Draw Image(this._Act iveFormImage, 0, 0);
}

CsharpNewcomm er wrote:
Hi

I have designed a form containing data and I want to print that form and the
data as it appears in the Windows Form. I am a beginner with C# and I have
read several "help"s on PrintPage, PrintDialog, etc. but none seem to address
the issue of printing directly from the form. They all talk about printing
from a text file.

Can someone tell me how to print the form and maybe direct me on which to
use PrintPage, PrintDialog.... which?

Thanks
D

Nov 17 '05 #5

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

Similar topics

4
4863
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been selected. For example, if I were to have 5 pages with every second page printing, I would get the following results: Page 1 = Print OK Page 2 = Blank Page 3 = Print OK Page 4 = Blank
4
8454
by: John Baker | last post by:
Hi: I have a form, which contains a sub form (Employee main record and payment record). It all shows up fine in a screen view, but when I come to print it I find that I cannot get the sub form to print on the same page as the form. I have sized the whole thing, and in theory it should fit into a single 8 1/2 x 11 page, but it just wont perform. I have the sub sheet components set to "can shrink". Are there any special things that one...
5
5390
by: Randy | last post by:
In my MDI parent, I can do the following: Form childForm = (Form)this.ActiveMdiChild; I'd like to send the childForm in it's current state to the printer. Current state being whatever text is currently in the textboxes on the form also prints. Thanks,
5
3486
by: VMI | last post by:
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...
0
1342
by: Tat | last post by:
Hi, I am printing the form. The code is 100% accurate. It is the same as in MSDN, but in C#. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbcode/html/vbtskCodeExamplePrintingForm.asp What happens is that if during printing any window happens to be on the top
0
1810
by: Ann | last post by:
I have a C# application that uses PrintDocument and PrintPage to draw reports. Now I need to integrate a tax form printing from a legacy VC++ DLL into the C# application. One of the important requirements is that the printing of the reports (implemented by C#) and the tax form (implemented by VC++) to be on the same print job. For example, if there are 10 clients we need to print the reports and tax form for, then 10 print jobs will be...
2
6410
by: sitemap | last post by:
Hello guys, I have a big problem with printing of windows.Forms :( I have application with "print" button. I am trying to use "e.Graphics.CopyFromScreen"... but in final result, over the printing form appears other controls from the existing or new applications in the screen ( Printing.. Please wait... - form for example). I mean that "CopyFromScreen" getting all the forms in defined coordinates and does not matter that the form that...
2
1775
by: =?Utf-8?B?Umlja1NlYW4=?= | last post by:
I have a long form within a panel which exceeds the maximum height of 876. I use the following code to print the form but it prints only the portion of the form that is displayed on the screen (max sized to 876). How do I print the entire form? Graphics mygraphics = this.CreateGraphics(); Size s = this.Size; memoryImage = new Bitmap(s.Width, s.Height, mygraphics); Graphics memoryGraphics = Graphics.FromImage(memoryImage); IntPtr dc1 =...
0
2856
it0ny
by: it0ny | last post by:
Hi guys, thanks I am fairly new to this forum so I hope I chose the right place to post this question. I try to make my program printout a deposit's report. I created a class to store the printing printing data and the actual database data in a recordset. the class looks like this: Public Class BRPDD 'Balance Report PrintingDocument Data Public totalReceiptsNum As Integer Public totalLicFee As Double
0
9827
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9678
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10560
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10609
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10263
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4468
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.