Print Preview Control Problem

  • Thread starter Thread starter Alex Clark
  • Start date Start date
A

Alex Clark

Hi all,

I'm having a few problems doing print previews in my app. I've made a
custom Print Preview dialog (because for what I want, the PreviewDialog that
ships with .NET just doesn't cut it), which has a Print Preview control on
it.

The problems arise when I try and manually navigate to a different page ---
I tried setting the StartPage property but it had no effect, it stuck on
Page 1. Is this by design, and if so, what is the StartPage property for??

Cheers
Alex Clark
 
"The page number of the upper left page. The default is 0."

Sadly, this doesn't fix the problem I'm having, and is another example of
sparse documentation in the help files :-( It doesn't really explain
anything!




Herfried K. Wagner said:
Hello,

Alex Clark said:
I'm having a few problems doing print previews in my app. [...]
The problems arise when I try and manually navigate to
a different page --- I tried setting the StartPage property but
it had no effect, it stuck on Page 1. Is this by design, and if
so, what is the StartPage property for??

StartPage Property (.NET Framework Class Library)
http://msdn.microsoft.com/library/e...rmsPrintPreviewControlClassStartPageTopic.asp
 
Hi Alex,
I'm not clear that how you navigate the StartPage?
I tried to set StartPage value after setting the Document property and it
works fine.
Is it helpful to your problem? If you still have problem on this issue,
please sent me an simple project to repro your problem. I'll do investigate
on it, thanks!!

Here is my test code, click "SetDoc" button first.
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace PrintPreviewControl
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PrintPreviewControl printPreviewControl1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private StreamReader streamToPrint = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
streamToPrint.Close();
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.printPreviewControl1 = new
System.Windows.Forms.PrintPreviewControl();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// printPreviewControl1
//
this.printPreviewControl1.AutoZoom = false;
this.printPreviewControl1.Location = new System.Drawing.Point(264, 24);
this.printPreviewControl1.Name = "printPreviewControl1";
this.printPreviewControl1.Size = new System.Drawing.Size(320, 352);
this.printPreviewControl1.TabIndex = 0;
this.printPreviewControl1.Zoom = 0.3;
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Next";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(48, 88);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "SetDoc";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(48, 128);
this.button3.Name = "button3";
this.button3.TabIndex = 3;
this.button3.Text = "Prev";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(616, 413);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.printPreviewControl1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button2_Click(object sender, System.EventArgs e)
{
try
{

streamToPrint = new StreamReader ("PrintMe.Txt");
try
{
TextFilePrintDocument pd = new TextFilePrintDocument(streamToPrint);
//Assumes the default printer
pd.DefaultPageSettings = new PageSettings();

printPreviewControl1.Document = pd;
}
finally
{

}
}
catch(Exception ex)
{
MessageBox.Show("An error occurred attempting to preview the file to
print - " + ex.Message);
}
}

private void button1_Click(object sender, System.EventArgs e)
{
printPreviewControl1.StartPage = printPreviewControl1.StartPage + 1;
}

private void button3_Click(object sender, System.EventArgs e)
{
printPreviewControl1.StartPage = printPreviewControl1.StartPage - 1;
}
}
public class TextFilePrintDocument : PrintDocument
{
private Font printFont = null ;
private StreamReader streamToPrint = null ;

public TextFilePrintDocument(StreamReader streamToPrint) : base ()
{
this.streamToPrint = streamToPrint ;
}

//Override OnBeginPrint to set up the font we are going to use
protected override void OnBeginPrint(PrintEventArgs ev)
{
base.OnBeginPrint(ev) ;
printFont = new Font("Arial", 10);
}

//Override the OnPrintPage to provide the printing logic for the document
protected override void OnPrintPage(PrintPageEventArgs ev)
{

base.OnPrintPage(ev) ;

float lpp = 0 ;
float yPos = 0 ;
int count = 0 ;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
String line=null;

//Work out the number of lines per page
//Use the MarginBounds on the event to do this
lpp = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ;

//Now iterate over the file printing out each line
//NOTE WELL: This assumes that a single line is not wider than the page
width
//Check count first so that we don't read line that we won't print
while (count < lpp && ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin,
yPos, new StringFormat());

count++;
}

//If we have more lines then print another page
if (line != null)
ev.HasMorePages = true ;
else
ev.HasMorePages = false ;
}

}

}


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!



--------------------
| From: "Alex Clark" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Print Preview Control Problem
| Date: Tue, 16 Sep 2003 00:09:20 +0100
| Lines: 33
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: pc4-basf3-5-cust169.nott.cable.ntl.com 81.106.151.169
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
..phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52288
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| "The page number of the upper left page. The default is 0."
|
| Sadly, this doesn't fix the problem I'm having, and is another example of
| sparse documentation in the help files :-( It doesn't really explain
| anything!
|
|
|
|
| | > Hello,
| >
| > > I'm having a few problems doing print previews in my app.
| > [...]
| > > The problems arise when I try and manually navigate to
| > > a different page --- I tried setting the StartPage property but
| > > it had no effect, it stuck on Page 1. Is this by design, and if
| > > so, what is the StartPage property for??
| >
| > StartPage Property (.NET Framework Class Library)
| >
|
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsPr
intPreviewControlClassStartPageTopic.asp
| >
| > --
| > Herfried K. Wagner
| > MVP · VB Classic, VB.NET
| > http://www.mvps.org/dotnet
| >
| >
|
|
|
 
Hi Ying-Shen

Thanks for your example (although I'm more of a VB.NET programmer :-). I
was actually handling the ValueChanged event of a NumericUpDown control and
then setting the StartPage value accordingly, like so:

Private Sub updPage_ValueChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles updPage.ValueChanged

pvwPrint.StartPage = CInt(updPage.Value)

End Sub

However, this event was being fired when the form loaded, and I think for
some reason it was confusing the Print Preview control, which was then
displaying the last page of the document and not responding to requests to
change to another page when I changed the updPage control.

After putting code into a button which simply says:
pvwPrint.StartPage += 1

I've found that it switches pages just fine. Thanks for pointing me in the
right direction, and this will be fine for my app, but is this perhaps a bug
in the Print Preview Control? It seems that setting the StartPage to 1
before anything has been printed to it seems to really confuse it's
page-handling.

Many Thanks,

Alex Clark



Hi Alex,
I'm not clear that how you navigate the StartPage?
I tried to set StartPage value after setting the Document property and it
works fine.
Is it helpful to your problem? If you still have problem on this issue,
please sent me an simple project to repro your problem. I'll do investigate
on it, thanks!!

Here is my test code, click "SetDoc" button first.
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace PrintPreviewControl
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PrintPreviewControl printPreviewControl1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private StreamReader streamToPrint = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
streamToPrint.Close();
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.printPreviewControl1 = new
System.Windows.Forms.PrintPreviewControl();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// printPreviewControl1
//
this.printPreviewControl1.AutoZoom = false;
this.printPreviewControl1.Location = new System.Drawing.Point(264, 24);
this.printPreviewControl1.Name = "printPreviewControl1";
this.printPreviewControl1.Size = new System.Drawing.Size(320, 352);
this.printPreviewControl1.TabIndex = 0;
this.printPreviewControl1.Zoom = 0.3;
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Next";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(48, 88);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "SetDoc";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(48, 128);
this.button3.Name = "button3";
this.button3.TabIndex = 3;
this.button3.Text = "Prev";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(616, 413);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.printPreviewControl1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button2_Click(object sender, System.EventArgs e)
{
try
{

streamToPrint = new StreamReader ("PrintMe.Txt");
try
{
TextFilePrintDocument pd = new TextFilePrintDocument(streamToPrint);
//Assumes the default printer
pd.DefaultPageSettings = new PageSettings();

printPreviewControl1.Document = pd;
}
finally
{

}
}
catch(Exception ex)
{
MessageBox.Show("An error occurred attempting to preview the file to
print - " + ex.Message);
}
}

private void button1_Click(object sender, System.EventArgs e)
{
printPreviewControl1.StartPage = printPreviewControl1.StartPage + 1;
}

private void button3_Click(object sender, System.EventArgs e)
{
printPreviewControl1.StartPage = printPreviewControl1.StartPage - 1;
}
}
public class TextFilePrintDocument : PrintDocument
{
private Font printFont = null ;
private StreamReader streamToPrint = null ;

public TextFilePrintDocument(StreamReader streamToPrint) : base ()
{
this.streamToPrint = streamToPrint ;
}

//Override OnBeginPrint to set up the font we are going to use
protected override void OnBeginPrint(PrintEventArgs ev)
{
base.OnBeginPrint(ev) ;
printFont = new Font("Arial", 10);
}

//Override the OnPrintPage to provide the printing logic for the document
protected override void OnPrintPage(PrintPageEventArgs ev)
{

base.OnPrintPage(ev) ;

float lpp = 0 ;
float yPos = 0 ;
int count = 0 ;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
String line=null;

//Work out the number of lines per page
//Use the MarginBounds on the event to do this
lpp = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ;

//Now iterate over the file printing out each line
//NOTE WELL: This assumes that a single line is not wider than the page
width
//Check count first so that we don't read line that we won't print
while (count < lpp && ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin,
yPos, new StringFormat());

count++;
}

//If we have more lines then print another page
if (line != null)
ev.HasMorePages = true ;
else
ev.HasMorePages = false ;
}

}

}


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!



--------------------
| From: "Alex Clark" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Print Preview Control Problem
| Date: Tue, 16 Sep 2003 00:09:20 +0100
| Lines: 33
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: pc4-basf3-5-cust169.nott.cable.ntl.com 81.106.151.169
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52288
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| "The page number of the upper left page. The default is 0."
|
| Sadly, this doesn't fix the problem I'm having, and is another example of
| sparse documentation in the help files :-( It doesn't really explain
| anything!
|
|
|
|
| | > Hello,
| >
| > > I'm having a few problems doing print previews in my app.
| > [...]
| > > The problems arise when I try and manually navigate to
| > > a different page --- I tried setting the StartPage property but
| > > it had no effect, it stuck on Page 1. Is this by design, and if
| > > so, what is the StartPage property for??
| >
| > StartPage Property (.NET Framework Class Library)
| >
|
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsPr
intPreviewControlClassStartPageTopic.asp
| >
| > --
| > Herfried K. Wagner
| > MVP · VB Classic, VB.NET
| > http://www.mvps.org/dotnet
| >
| >
|
|
|
 
Hi,

Think I've found the bug - it's me, lol. The StartPage property is 0 based
when I thought it was 1 based, which is why it was defaulting to the last
page (it was a 2 page document), the Numeric UpDown had a min-value of 1.

Thanks for all your help,
Alex



Ying-Shen Yu said:
Hi Alex,
I'm not clear that how you navigate the StartPage?
I tried to set StartPage value after setting the Document property and it
works fine.
Is it helpful to your problem? If you still have problem on this issue,
please sent me an simple project to repro your problem. I'll do investigate
on it, thanks!!

Here is my test code, click "SetDoc" button first.
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace PrintPreviewControl
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PrintPreviewControl printPreviewControl1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private StreamReader streamToPrint = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
streamToPrint.Close();
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.printPreviewControl1 = new
System.Windows.Forms.PrintPreviewControl();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// printPreviewControl1
//
this.printPreviewControl1.AutoZoom = false;
this.printPreviewControl1.Location = new System.Drawing.Point(264, 24);
this.printPreviewControl1.Name = "printPreviewControl1";
this.printPreviewControl1.Size = new System.Drawing.Size(320, 352);
this.printPreviewControl1.TabIndex = 0;
this.printPreviewControl1.Zoom = 0.3;
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Next";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(48, 88);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "SetDoc";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(48, 128);
this.button3.Name = "button3";
this.button3.TabIndex = 3;
this.button3.Text = "Prev";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(616, 413);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.printPreviewControl1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button2_Click(object sender, System.EventArgs e)
{
try
{

streamToPrint = new StreamReader ("PrintMe.Txt");
try
{
TextFilePrintDocument pd = new TextFilePrintDocument(streamToPrint);
//Assumes the default printer
pd.DefaultPageSettings = new PageSettings();

printPreviewControl1.Document = pd;
}
finally
{

}
}
catch(Exception ex)
{
MessageBox.Show("An error occurred attempting to preview the file to
print - " + ex.Message);
}
}

private void button1_Click(object sender, System.EventArgs e)
{
printPreviewControl1.StartPage = printPreviewControl1.StartPage + 1;
}

private void button3_Click(object sender, System.EventArgs e)
{
printPreviewControl1.StartPage = printPreviewControl1.StartPage - 1;
}
}
public class TextFilePrintDocument : PrintDocument
{
private Font printFont = null ;
private StreamReader streamToPrint = null ;

public TextFilePrintDocument(StreamReader streamToPrint) : base ()
{
this.streamToPrint = streamToPrint ;
}

//Override OnBeginPrint to set up the font we are going to use
protected override void OnBeginPrint(PrintEventArgs ev)
{
base.OnBeginPrint(ev) ;
printFont = new Font("Arial", 10);
}

//Override the OnPrintPage to provide the printing logic for the document
protected override void OnPrintPage(PrintPageEventArgs ev)
{

base.OnPrintPage(ev) ;

float lpp = 0 ;
float yPos = 0 ;
int count = 0 ;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
String line=null;

//Work out the number of lines per page
//Use the MarginBounds on the event to do this
lpp = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ;

//Now iterate over the file printing out each line
//NOTE WELL: This assumes that a single line is not wider than the page
width
//Check count first so that we don't read line that we won't print
while (count < lpp && ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin,
yPos, new StringFormat());

count++;
}

//If we have more lines then print another page
if (line != null)
ev.HasMorePages = true ;
else
ev.HasMorePages = false ;
}

}

}


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!



--------------------
| From: "Alex Clark" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Print Preview Control Problem
| Date: Tue, 16 Sep 2003 00:09:20 +0100
| Lines: 33
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: pc4-basf3-5-cust169.nott.cable.ntl.com 81.106.151.169
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52288
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| "The page number of the upper left page. The default is 0."
|
| Sadly, this doesn't fix the problem I'm having, and is another example of
| sparse documentation in the help files :-( It doesn't really explain
| anything!
|
|
|
|
| | > Hello,
| >
| > > I'm having a few problems doing print previews in my app.
| > [...]
| > > The problems arise when I try and manually navigate to
| > > a different page --- I tried setting the StartPage property but
| > > it had no effect, it stuck on Page 1. Is this by design, and if
| > > so, what is the StartPage property for??
| >
| > StartPage Property (.NET Framework Class Library)
| >
|
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsPr
intPreviewControlClassStartPageTopic.asp
| >
| > --
| > Herfried K. Wagner
| > MVP · VB Classic, VB.NET
| > http://www.mvps.org/dotnet
| >
| >
|
|
|
 
Hi Alex,
It's my pleasure to help you with your problem.
Thanks for using MSDN Newsgroup!

BTW: You can set the minimal value in NumericUpDown.Minimal property,
I think you had known this. just for sure :-)

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!

--------------------
| From: "Alex Clark" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Print Preview Control Problem
| Date: Tue, 16 Sep 2003 12:19:50 +0100
| Lines: 319
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#s#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: pc4-basf3-5-cust169.nott.cable.ntl.com 81.106.151.169
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA07.phx.gbl!TK2MSFTNGXA0
6.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52319
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Hi,
|
| Think I've found the bug - it's me, lol. The StartPage property is 0
based
| when I thought it was 1 based, which is why it was defaulting to the last
| page (it was a 2 page document), the Numeric UpDown had a min-value of 1.
|
| Thanks for all your help,
| Alex
|
|
|
| | > Hi Alex,
| > I'm not clear that how you navigate the StartPage?
| > I tried to set StartPage value after setting the Document property and
it
| > works fine.
| > Is it helpful to your problem? If you still have problem on this issue,
| > please sent me an simple project to repro your problem. I'll do
| investigate
| > on it, thanks!!
| >
| > Here is my test code, click "SetDoc" button first.
| > using System;
| > using System.Drawing;
| > using System.Drawing.Printing;
| > using System.Collections;
| > using System.ComponentModel;
| > using System.Windows.Forms;
| > using System.Data;
| > using System.IO;
| >
| > namespace PrintPreviewControl
| > {
| > /// <summary>
| > /// Summary description for Form1.
| > /// </summary>
| > public class Form1 : System.Windows.Forms.Form
| > {
| > private System.Windows.Forms.PrintPreviewControl printPreviewControl1;
| > private System.Windows.Forms.Button button1;
| > private System.Windows.Forms.Button button2;
| > private System.Windows.Forms.Button button3;
| > /// <summary>
| > /// Required designer variable.
| > /// </summary>
| > private System.ComponentModel.Container components = null;
| > private StreamReader streamToPrint = null;
| >
| > public Form1()
| > {
| > //
| > // Required for Windows Form Designer support
| > //
| > InitializeComponent();
| >
| > //
| > // TODO: Add any constructor code after InitializeComponent call
| > //
| > }
| >
| > /// <summary>
| > /// Clean up any resources being used.
| > /// </summary>
| > protected override void Dispose( bool disposing )
| > {
| > if( disposing )
| > {
| > if (components != null)
| > {
| > streamToPrint.Close();
| > components.Dispose();
| > }
| > }
| > base.Dispose( disposing );
| > }
| >
| > #region Windows Form Designer generated code
| > /// <summary>
| > /// Required method for Designer support - do not modify
| > /// the contents of this method with the code editor.
| > /// </summary>
| > private void InitializeComponent()
| > {
| > this.printPreviewControl1 = new
| > System.Windows.Forms.PrintPreviewControl();
| > this.button1 = new System.Windows.Forms.Button();
| > this.button2 = new System.Windows.Forms.Button();
| > this.button3 = new System.Windows.Forms.Button();
| > this.SuspendLayout();
| > //
| > // printPreviewControl1
| > //
| > this.printPreviewControl1.AutoZoom = false;
| > this.printPreviewControl1.Location = new System.Drawing.Point(264, 24);
| > this.printPreviewControl1.Name = "printPreviewControl1";
| > this.printPreviewControl1.Size = new System.Drawing.Size(320, 352);
| > this.printPreviewControl1.TabIndex = 0;
| > this.printPreviewControl1.Zoom = 0.3;
| > //
| > // button1
| > //
| > this.button1.Location = new System.Drawing.Point(48, 48);
| > this.button1.Name = "button1";
| > this.button1.TabIndex = 1;
| > this.button1.Text = "Next";
| > this.button1.Click += new System.EventHandler(this.button1_Click);
| > //
| > // button2
| > //
| > this.button2.Location = new System.Drawing.Point(48, 88);
| > this.button2.Name = "button2";
| > this.button2.TabIndex = 2;
| > this.button2.Text = "SetDoc";
| > this.button2.Click += new System.EventHandler(this.button2_Click);
| > //
| > // button3
| > //
| > this.button3.Location = new System.Drawing.Point(48, 128);
| > this.button3.Name = "button3";
| > this.button3.TabIndex = 3;
| > this.button3.Text = "Prev";
| > this.button3.Click += new System.EventHandler(this.button3_Click);
| > //
| > // Form1
| > //
| > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
| > this.ClientSize = new System.Drawing.Size(616, 413);
| > this.Controls.Add(this.button3);
| > this.Controls.Add(this.button2);
| > this.Controls.Add(this.button1);
| > this.Controls.Add(this.printPreviewControl1);
| > this.Name = "Form1";
| > this.Text = "Form1";
| > this.ResumeLayout(false);
| >
| > }
| > #endregion
| >
| > /// <summary>
| > /// The main entry point for the application.
| > /// </summary>
| > [STAThread]
| > static void Main()
| > {
| > Application.Run(new Form1());
| > }
| >
| > private void button2_Click(object sender, System.EventArgs e)
| > {
| > try
| > {
| >
| > streamToPrint = new StreamReader ("PrintMe.Txt");
| > try
| > {
| > TextFilePrintDocument pd = new TextFilePrintDocument(streamToPrint);
| > //Assumes the default printer
| > pd.DefaultPageSettings = new PageSettings();
| >
| > printPreviewControl1.Document = pd;
| > }
| > finally
| > {
| >
| > }
| > }
| > catch(Exception ex)
| > {
| > MessageBox.Show("An error occurred attempting to preview the file to
| > print - " + ex.Message);
| > }
| > }
| >
| > private void button1_Click(object sender, System.EventArgs e)
| > {
| > printPreviewControl1.StartPage = printPreviewControl1.StartPage + 1;
| > }
| >
| > private void button3_Click(object sender, System.EventArgs e)
| > {
| > printPreviewControl1.StartPage = printPreviewControl1.StartPage - 1;
| > }
| > }
| > public class TextFilePrintDocument : PrintDocument
| > {
| > private Font printFont = null ;
| > private StreamReader streamToPrint = null ;
| >
| > public TextFilePrintDocument(StreamReader streamToPrint) : base ()
| > {
| > this.streamToPrint = streamToPrint ;
| > }
| >
| > //Override OnBeginPrint to set up the font we are going to use
| > protected override void OnBeginPrint(PrintEventArgs ev)
| > {
| > base.OnBeginPrint(ev) ;
| > printFont = new Font("Arial", 10);
| > }
| >
| > //Override the OnPrintPage to provide the printing logic for the
document
| > protected override void OnPrintPage(PrintPageEventArgs ev)
| > {
| >
| > base.OnPrintPage(ev) ;
| >
| > float lpp = 0 ;
| > float yPos = 0 ;
| > int count = 0 ;
| > float leftMargin = ev.MarginBounds.Left;
| > float topMargin = ev.MarginBounds.Top;
| > String line=null;
| >
| > //Work out the number of lines per page
| > //Use the MarginBounds on the event to do this
| > lpp = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ;
| >
| > //Now iterate over the file printing out each line
| > //NOTE WELL: This assumes that a single line is not wider than the page
| > width
| > //Check count first so that we don't read line that we won't print
| > while (count < lpp && ((line=streamToPrint.ReadLine()) != null))
| > {
| > yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
| >
| > ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin,
| > yPos, new StringFormat());
| >
| > count++;
| > }
| >
| > //If we have more lines then print another page
| > if (line != null)
| > ev.HasMorePages = true ;
| > else
| > ev.HasMorePages = false ;
| > }
| >
| > }
| >
| > }
| >
| >
| > Best regards,
| >
| > Ying-Shen Yu [MSFT]
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| >
| > This posting is provided "AS IS" with no warranties and confers no
rights.
| > You should not reply this mail directly, "Online" shouldbe removed
before
| > sending, Thanks!
| >
| >
| >
| > --------------------
| > | From: "Alex Clark" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > | Subject: Re: Print Preview Control Problem
| > | Date: Tue, 16 Sep 2003 00:09:20 +0100
| > | Lines: 33
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.windowsforms
| > | NNTP-Posting-Host: pc4-basf3-5-cust169.nott.cable.ntl.com
81.106.151.169
| > | Path:
| >
|
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
| > phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: cpmsftngxa07.phx.gbl
| > microsoft.public.dotnet.framework.windowsforms:52288
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
| > |
| > | "The page number of the upper left page. The default is 0."
| > |
| > | Sadly, this doesn't fix the problem I'm having, and is another example
| of
| > | sparse documentation in the help files :-( It doesn't really explain
| > | anything!
| > |
| > |
| > |
| > |
| > | | > | > Hello,
| > | >
| > | > > I'm having a few problems doing print previews in my app.
| > | > [...]
| > | > > The problems arise when I try and manually navigate to
| > | > > a different page --- I tried setting the StartPage property but
| > | > > it had no effect, it stuck on Page 1. Is this by design, and if
| > | > > so, what is the StartPage property for??
| > | >
| > | > StartPage Property (.NET Framework Class Library)
| > | >
| > |
| >
|
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsPr
| > intPreviewControlClassStartPageTopic.asp
| > | >
| > | > --
| > | > Herfried K. Wagner
| > | > MVP · VB Classic, VB.NET
| > | > http://www.mvps.org/dotnet
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|
 
Back
Top