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.