472,958 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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.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);

Jun 27 '08 #1
2 1725
On Tue, 17 Jun 2008 15:48:01 -0700, RickSean
<Ri******@discussions.microsoft.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.CopyFromScreen() or, even better, Control.DrawToBitmap(). 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******@discussions.microsoft.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.CopyFromScreen() or, even better, Control.DrawToBitmap(). 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
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)> _...
4
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...
2
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...
4
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,...
7
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...
5
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
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...
2
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...
0
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.