473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

PrintPreviewControl - Hide "Generating Previews" Dialog

I'm trying to write a label printing SDI app with a small preview on the main form itself. Every time I run the InvalidatePreview event on the preview
control to redraw the preview I get the "Generating Previews" dialog box while the preview is being generated. I want to suppress this. I've been able
to find this from another forum:

"The 'Generating Previews' dialog is shown while calculating the layout for pages in OnPaint(). One of our devs suggested the only way to avoid this
dialog is to override the OnPaint, do your own layout- passing your own PrintController and not calling the base."

I tried to create a custom control and override onpaint, but I could not get it to work.

I have been able to hide the dialog if I print directly to the printer by using the StandardPrintController, but this does not work with the preview.

Has anybody found another solution to this, or have other suggestions?

Thanks.

May 31 '07 #1
3 8771
On Thu, 31 May 2007 16:49:01 -0700, deciacco <a@awrote:
[...]
I tried to create a custom control and override onpaint, but I could not
get it to work.
What didn't work? What *did* work?
I have been able to hide the dialog if I print directly to the printer
by using the StandardPrintController, but this does not work with the
preview.
What dialog did you hide? I would not expect to see the "Generating
Previews" dialog when printing to an actual printer, nor have I in the few
times I've done any printing with the .NET classes. Did you hide some
other dialog instead? If so, in what way would that success be relevant
to this question?
Has anybody found another solution to this, or have other suggestions?
In the overridden OnPaint() method, do you call the base method? If so, I
would guess that's part of your problem. The point to overriding would be
to avoid using the built-in functionality. You can only do that by
implementing the *entire* preview drawing functionality and not calling
the base method (as the quote you offered suggests).

Frankly, this seems like a lot of work for a questionable goal. It's not
clear to me why it's so bad to provide the user with some feedback
regarding what is going on. In fact, usually it's the opposite that users
complain about: some application is busy doing something, but there's no
feedback to the user that that's happening, what the application is doing,
or how long it will take.

At the very least, you may want to consider elaborating on your question.
As it stands now, what information we have regarding your question is
pretty vague. It's hard to offer specific, useful advice when the problem
description isn't very clear.

Pete
Jun 1 '07 #2
Here is a link to an app that is currently written in foxpro 9. I want to build
the exact same application in c# 2.

http://deciacco.com/blog/wp-content/.../lblprint1.gif

The user is able to search for a record and when they click on the record in the
data grid a quick label preview is generated.

In C#, I figured the best way to do this, is to use the printpreviewcontrol on the sdi form.

I started experimenting with the control on a form and I got it to do a basic print preview,
the problem was that every time the preview got generated I got the dialog box.

Normally, it would be good to give the user some feedback, but I think in an application like
this, the preview is generated so quickly that the busy cursor is more than sufficient, instead
of having a dialog pop up every time a user selects a different record or uses one of the radio
buttons to add more information to the label.

If I were to print the document, there is a status dialog that pops up that is very similar to
the "Generating Preview" dialog, and this dialog can be suppressed by setting the printcontroller
of the printdocument to a standardprintcontroller.

When I tried to create my own custom printpreviewcontrol I started out to override the OnPaint method.
I used Reflector to get the code in the OnPaint method of the .net 2 printpreviewcontrol, because I have
no idea how to implement it, but I was able to determine what not to include so that the
"Generating Preview" dialog would not show.

What I discovered is that the printpreviewcontrol has a private method ComputePreview where it uses a
printcontrollerwithstatusdialog as the printcontroller. I believe this is what is causing the "Gen Prev"
dialog that I want to suppress. The problem is that this method is private and therefor cannot be overwritten.
So, not only do you have to override the onpaint, you also have to create your own version of this method
that calls the standardprintcontroller.

I was going to attempt this, but as I started to implement the OnPaint of my custom control and copied over
the code, there were a few lines of code that gave me problems.

format.Alignment = ControlPaint.TranslateAlignment(ContentAlignment.M iddleCenter);
format.LineAlignment = ControlPaint.TranslateLineAlignment(ContentAlignme nt.MiddleCenter);

The error I got with these two lines is that the ControlPaint class did not have a TranslateAlignmet method,
nor did it have a TranslateLineAlignment method.

Another line of code that did not work for me was this one:

pevent.Graphics.DrawString(SR.GetString("PrintPrev iewExceptionPrinting"), this.Font, brush2, base.ClientRectangle, format);

The error here was with SR. I could not get access to it because of it's protection level.

When I got these two errors I gave up.

Thanks!

This is where I got Reflector from:
http://www.aisto.com/roeder/dotnet/
Peter Duniho wrote:
On Thu, 31 May 2007 16:49:01 -0700, deciacco <a@awrote:
>[...]
I tried to create a custom control and override onpaint, but I could
not get it to work.

What didn't work? What *did* work?
>I have been able to hide the dialog if I print directly to the printer
by using the StandardPrintController, but this does not work with the
preview.

What dialog did you hide? I would not expect to see the "Generating
Previews" dialog when printing to an actual printer, nor have I in the
few times I've done any printing with the .NET classes. Did you hide
some other dialog instead? If so, in what way would that success be
relevant to this question?
>Has anybody found another solution to this, or have other suggestions?

In the overridden OnPaint() method, do you call the base method? If so,
I would guess that's part of your problem. The point to overriding
would be to avoid using the built-in functionality. You can only do
that by implementing the *entire* preview drawing functionality and not
calling the base method (as the quote you offered suggests).

Frankly, this seems like a lot of work for a questionable goal. It's
not clear to me why it's so bad to provide the user with some feedback
regarding what is going on. In fact, usually it's the opposite that
users complain about: some application is busy doing something, but
there's no feedback to the user that that's happening, what the
application is doing, or how long it will take.

At the very least, you may want to consider elaborating on your
question. As it stands now, what information we have regarding your
question is pretty vague. It's hard to offer specific, useful advice
when the problem description isn't very clear.

Pete
Jun 1 '07 #3
On Fri, 01 Jun 2007 07:24:58 -0700, deciacco <a@awrote:
[...]
Normally, it would be good to give the user some feedback, but I think
in an application like
this, the preview is generated so quickly that the busy cursor is more
than sufficient, instead
of having a dialog pop up every time a user selects a different record
or uses one of the radio
buttons to add more information to the label.
I do agree that it would be better without the status dialog in this
case. On the other hand, you seem to be going to an awful lot of trouble
in order to work around something that, while not perfect, doesn't seem to
me to be a really big problem.

That said, you've selected what *I* think may be a particular difficult
route to reimplementing the OnPaint() method. It seems to me that the key
behavior of the OnPaint() method is to set up a Graphics instance that
looks like a printer page and then pass that off to the PrintPage event
handler. This would involve creating a Bitmap or Metafile into which the
client can draw (Bitmap is probably just fine, but Metafile would allow
for easy reuse of the drawn image at different sizes, if that's something
you think could be useful), setting up the margins, clipping, etc.

I admit, I haven't looked closely enough at the .NET printing API to know
for sure where all of this gets implemented. There seems to be a
PrintController class you need to create, and then perhaps a custom
control to take advantage of that. The basic idea of a print preview is
not hard, so the idea that you should have to dive into the .NET
implementation of a particular class, trying to copy all of its internals
when probably much of what's in there isn't even applicable to the common
case, that doesn't seem right to me.

If you *are* going to try to suppress this dialog, I would think that
coming at it from the other direction, by simply reinventing the basic
functionality you need for print preview, would be more efficient.
There's likely just too much clutter in the existing implementation for it
to be a practical template to use (not that the clutter doesn't have its
use...just that it probably exists to handle a broader variety of
situations than you will need to handle).

Pete
Jun 1 '07 #4

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

Similar topics

4
by: Richard Shea | last post by:
Hi - I've writing a Python script which has a query which looks like this ... select * from T where C1 not in (1,2,3) .... C1 is a numeric column so elements of (1,2,3) must not be quoted...
0
by: Holger Joukl | last post by:
You could use the str() builtin, returning the string representation of the list object: >>> params = (1, 2, 3) >>> "select * from T where C1 not in %s" % str(params) 'select * from T where C1...
2
by: Kent | last post by:
Hi! I think i know whats the problem but not how to solve it. I have two classes, named A and B. The A class has a list<B*> And the B class has an pure virtual method declared as: void...
4
by: David Sworder | last post by:
Consider the following line of code (it's not important what it does): resp.DocItem=Relations.SelectDocItems_BySearchString(req.SearchPhrase); It turns out that this line is in error. The...
2
by: Marco | last post by:
Hi, I've noticed that whenever I'm doing a print preview (and probably doing a regular print) with a lot of pages a window pops up counting the number of pages that it's processed so far. I don't...
0
by: AndyB | last post by:
I'm using xsd.exe to generate a typed-dataset. Then using typed dataset tables (datatables containing two columns--a name and a value) to bind to ASP.NET dropdown list controls (for the dropdown...
2
by: ReGex | last post by:
I have been working on a little project in C# to log into a website (using code inspired/riipped from http://www.codeproject.com/cs/internet/bloglivejournal.asp) but when I request the response,...
2
by: bob.turner.uk | last post by:
Hi, I would like to supress the generating preview dialog of the print preview control. Does anyone know how to do this? Regards, Bob
1
by: R.A.M. | last post by:
Hello, I have started programming ASP.NET application using SQL Server 2005 Express Edition. The problem is that when C# code tries to access aspnetdb database, for example:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.