PrintPreviewDialog, How to specify the Page to de display, through code.

V

vanderghast

The PrintPreviewDialog expose a small control allowing the end user to
navigate to the various pages of the printed document, but neither in
PrintPreviewDialog, neither in PrintDocument can I spot a property allowing
to navigate to the various pages, with code. Am I missing something obvious,
or is it embedded in some other places, or...? My final goal is to
increment, decrement, the page to be displayed accordingly to the sign of
e.Delta from a MouseWheel event (exposed by PrintPreviewDialog), in addition
to PgUp/PgDown which are already doing it.



Vanderghast, Access MVP
 
J

Jeff Johnson

The PrintPreviewDialog expose a small control allowing the end user to
navigate to the various pages of the printed document, but neither in
PrintPreviewDialog, neither in PrintDocument can I spot a property
allowing to navigate to the various pages, with code. Am I missing
something obvious, or is it embedded in some other places, or...? My final
goal is to increment, decrement, the page to be displayed accordingly to
the sign of e.Delta from a MouseWheel event (exposed by
PrintPreviewDialog), in addition to PgUp/PgDown which are already doing
it.

I think that's kind of pushing the UI paradigm. I have NEVER looked at an
up/down control and thought to myself "Gee, I wish I could change that value
with my mouse wheel."
 
V

vanderghast

Neither I, but some end user who used Adobe viewer (or something like that)
where the mouse wheel does just that.

Vanderghast, Access MVP
 
J

Jeff Johnson

Neither I, but some end user who used Adobe viewer (or something like
that) where the mouse wheel does just that.

It's possible that that's actually a listbox made so short that it looks
like an up/down control (which should be a capital offense). Just
thinkin'....
 
K

kndg

vanderghast said:
The PrintPreviewDialog expose a small control allowing the end user to
navigate to the various pages of the printed document, but neither in
PrintPreviewDialog, neither in PrintDocument can I spot a property
allowing to navigate to the various pages, with code. Am I missing
something obvious, or is it embedded in some other places, or...? My
final goal is to increment, decrement, the page to be displayed
accordingly to the sign of e.Delta from a MouseWheel event (exposed by
PrintPreviewDialog), in addition to PgUp/PgDown which are already doing it.



Vanderghast, Access MVP

Hi Vanderghast,

PrintPreviewDialog is somewhat limited in what it can do.
My solution is to create a custom form that handle this functionality.
For example, drag a PrintPreviewControl and PrintDocument onto it. Set
the PrintPreviewControl.Document to this PrintDocument. Then
increment/decrement the PrintPreviewControl.StartPage through your
MouseWheel event.

Something like below;

public class PrintPreviewForm : Form
{
private PrintPreviewControl printPreviewControl;
private PrintDocument printDocument;

public PrintPreviewForm()
{
InitializeComponent();

MouseWheel += printPreviewForm_MouseWheel;
}

private void InitializeComponent()
{
printDocument = new PrintDocument();
printDocument.PrintPage += printDocument_PrintPage;
printDocument.EndPrint += printDocument_EndPrint;
printDocument.BeginPrint += printDocument_BeginPrint;

printPreviewControl = new PrintPreviewControl();
printPreviewControl.Document = printDocument;
printPreviewControl.Dock = DockStyle.Fill;

Controls.Add(printPreviewControl);
}

private void NextPage()
{
printPreviewControl.StartPage++;
}

private void PreviousPage()
{
if (printPreviewControl.StartPage > 0)
{
printPreviewControl.StartPage--;
}
}

private void printPreviewForm_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta > 0)
{
NextPage();
}
else if (e.Delta < 0)
{
PreviousPage();
}
}

private void printDocument_BeginPrint(object sender, PrintEventArgs e)
{
// handle printing preparation
}

private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
// draw something to print
}

private void printDocument_EndPrint(object sender, PrintEventArgs e)
{
// printing complete - release all graphics objects
}
}

Regards.
 
K

kndg

kndg said:
Hi Vanderghast,

PrintPreviewDialog is somewhat limited in what it can do.

Okay, I take back my above statement.
PrintPreviewDialog does expose the PrintPreviewControl so you can
actually bind the MouseWheel event to PrintPreviewControl.StartPage;

private void printPreviewDialog1_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta > 0)
{
printPreviewDialog1.PrintPreviewControl.StartPage++;
}
else if (e.Delta < 0)
{
if (printPreviewDialog1.PrintPreviewControl.StartPage > 0)
{
printPreviewDialog1.PrintPreviewControl.StartPage--;
}
}
}

Regards.
 
V

vanderghast

Thanks, I'll try that.

Vanderghast, Access MVP


kndg said:
Okay, I take back my above statement.
PrintPreviewDialog does expose the PrintPreviewControl so you can actually
bind the MouseWheel event to PrintPreviewControl.StartPage;

private void printPreviewDialog1_MouseWheel(object sender, MouseEventArgs
e)
{
if (e.Delta > 0)
{
printPreviewDialog1.PrintPreviewControl.StartPage++;
}
else if (e.Delta < 0)
{
if (printPreviewDialog1.PrintPreviewControl.StartPage > 0)
{
printPreviewDialog1.PrintPreviewControl.StartPage--;
}
}
}

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top