473,587 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing long form in C# 2005

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.CreateGrap hics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromIm age(memoryImage );
IntPtr dc1 = mygraphics.GetH dc();
IntPtr dc2 = memoryGraphics. GetHdc();
BitBlt(dc2, 0, 0, this.ClientRect angle.Width, this.ClientRect angle.Height,
dc1, 0, 0, 13369376);
mygraphics.Rele aseHdc(dc1);
memoryGraphics. ReleaseHdc(dc2) ;

Jun 27 '08 #1
2 1764
On Tue, 17 Jun 2008 15:48:01 -0700, RickSean
<Ri******@discu ssions.microsof t.comwrote:
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?
The short answer is "you don't".

You undoubtedly could shoe-horn the form into printing the entire thing.
One approach would be to repeatedly move the form so incremental portions
are visible, building the entire page up one screen-full at a time.
Another might be to send the WM_PRINT message to the form window handle
and hope that everything in the form handles that message properly (not
guaranteed).

But basically, printing forms is just not well supported. Using an
on-screen user-interface just isn't a great way to create printed pages.
This is one reason that it's not well-supported, and at the same time it's
a bit of a self-fulfilling prophecy, since the fact that it's not
well-supported also means it's not a great way to create printed pages. :)

But really, it's true that the on-screen representation of a
user-interface is really just not a great way to display things on a
printed page. There are too many significant differences between an
interactive display and a static, printed page.

A common strategy for applications that have a lot of custom
user-interface stuff that they also want to be able to print is to create
a shared rendering engine that can handle both. Typically the engine
would include some special-case things to deal with the differences
between the too, but otherwise would emit rendered data to an arbitrary
Graphics instance. When displaying on-screen, this would be the Graphics
instance for the Paint event, and when printing this would be the instance
for the PrintPage event.

And of course, you could have printing code that doesn't interact at all
with the on-screen UI. This would be reasonably common for applications
that have a very simple presentation on-screen and printed (just plain
text, for example), and as well for applications that print the data in a
very specific way that's not closely related to the on-screen display (a
database report using some specific criteria set in the UI, for example).

By the way, using BitBlt probably doesn't make much sense. At the very
least, you should probably change your code so that it uses either
Graphics.CopyFr omScreen() or, even better, Control.DrawToB itmap(). Either
will still have some limitations, and which will likely cause issues. But
at least you won't have to be going writing p/invoked stuff in your own
code. :)

Pete
Jun 27 '08 #2
Thanks for you detailed answer.
"Peter Duniho" wrote:
On Tue, 17 Jun 2008 15:48:01 -0700, RickSean
<Ri******@discu ssions.microsof t.comwrote:
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?

The short answer is "you don't".

You undoubtedly could shoe-horn the form into printing the entire thing.
One approach would be to repeatedly move the form so incremental portions
are visible, building the entire page up one screen-full at a time.
Another might be to send the WM_PRINT message to the form window handle
and hope that everything in the form handles that message properly (not
guaranteed).

But basically, printing forms is just not well supported. Using an
on-screen user-interface just isn't a great way to create printed pages.
This is one reason that it's not well-supported, and at the same time it's
a bit of a self-fulfilling prophecy, since the fact that it's not
well-supported also means it's not a great way to create printed pages. :)

But really, it's true that the on-screen representation of a
user-interface is really just not a great way to display things on a
printed page. There are too many significant differences between an
interactive display and a static, printed page.

A common strategy for applications that have a lot of custom
user-interface stuff that they also want to be able to print is to create
a shared rendering engine that can handle both. Typically the engine
would include some special-case things to deal with the differences
between the too, but otherwise would emit rendered data to an arbitrary
Graphics instance. When displaying on-screen, this would be the Graphics
instance for the Paint event, and when printing this would be the instance
for the PrintPage event.

And of course, you could have printing code that doesn't interact at all
with the on-screen UI. This would be reasonably common for applications
that have a very simple presentation on-screen and printed (just plain
text, for example), and as well for applications that print the data in a
very specific way that's not closely related to the on-screen display (a
database report using some specific criteria set in the UI, for example).

By the way, using BitBlt probably doesn't make much sense. At the very
least, you should probably change your code so that it uses either
Graphics.CopyFr omScreen() or, even better, Control.DrawToB itmap(). Either
will still have some limitations, and which will likely cause issues. But
at least you won't have to be going writing p/invoked stuff in your own
code. :)

Pete
Jun 27 '08 #3

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

Similar topics

0
2351
by: Chris | last post by:
Hi, I found this code to send print direct to printer. It works perfect. Imports System Imports System.Text Imports System.Runtime.InteropServices <StructLayout(LayoutKind.Sequential)> _ Public Structure DOCINFO<MarshalAs(UnmanagedType.LPWStr)> Public pDocName As String<MarshalAs(UnmanagedType.LPWStr)>
4
4712
by: Sami | last post by:
I hope someone will tell me how to do this without having to do any VB as I know nothing in that area. I am a rank beginner in using Access. I have created a database consisting of student athletes.  I have now learned how to join two different tables in a query so that I might generate a report. Specifically, student athletes at a community college are required to graduate with an AA or AS degree.  Consequently, various steps are in...
2
1974
by: Dave | last post by:
How do I hide the buttons when I'm printing a form off? I want the buttons on the form normally but not on the printed version. Another problem I've encountered is how do you get rid of the record navigation bar at the bottom of the form?
4
2808
by: CsharpNewcommer | last post by:
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?
7
1676
by: Amirallia | last post by:
Hello! I have a wecontrol table in a page, this table has a number of variable rows depending of the choice of the user. But when the table has a large number of rows, the printing of the page requires 2 pages . The first page is ok, but in the second page of the printing I have no ligne of the row and no ligne of the column printing on the page!
5
7096
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
6
14902
by: randy1200 | last post by:
I'm using Visual Studio 2005 and C#. I need to print a WinForm used for data entry as a graphic. In other words, I need to print the exact WinForm the user sees on the screen. I searched through the newsgroups, and found the code below. This seems reasonable, except for the fact that the author does not provide his SetSeq_Library. This is needed to load the Bitmap variable _ActiveFormImage. Any suggestions on how to capture a WinForm...
2
1494
by: pedestrian via SQLMonster.com | last post by:
I wonder is there any way I can turn off the "Documentation Feedback" section of the Books Online at the bottom of the pages... I'm printing some Books Online pages for own reference. Thanks in advance... -- Message posted via SQLMonster.com http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-general/200706/1
0
2832
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
8220
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
8352
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...
0
8222
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
6632
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
5723
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...
0
5396
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1457
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1194
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.