G
Guest
I have implemented some label printing code that prints to a (you guessed it)
label printer. I have derived my class from the
System.Drawing.Printing.PrintDocument class ond overriden some of the
protected methods. I pass into the constructor a custom Label object that
contains the layout and data and has rendering code.
public LabelPrint(Label label) : base()
{
this.label = label;
}
The key override is the OnPrintPage method.
protected override void OnPrintPage(PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
e.Graphics.PageScale = this.pageScale;
label.Render(e.Graphics);
e.HasMorePages = false;
}
To initiate this for print preview, I have placed a
System.Windows.Forms.PrintPreviewControl on a form and use the following code.
private void PrintPreviewLabel_Click(object sender, EventArgs e)
{
MyLabel label = GetLabel();
LabelPrint labelPrint = new LabelPrint(label);
this.printPreviewControl1.InvalidatePreview();
this.printPreviewControl1.Document = labelPrint;
}
Now to the point. I had this code on both a test form and a user control and
they both worked well as I created different labels to preview. That was on
the beta2 release.
We upgraded to the August CTP release a week or so ago, and the code on the
user control stopped working. It displays the first preview ok, but will not
update as different labels are presented. I placed a breakpoint in the
OnPrintPage method and it was reached for the first label but not for
subsequent labels.
As can be seen from the code, I am creating new MyLabel and LabelPrint
objects each time. I have tried creating a new PrintPreviewControl object
each time and dynamically placing it on the form. I've tried putting the
this.printPreviewControl1.InvalidatePreview(); line after setting the
document. I've tried refreshing the form and printPreviewControl1 object.
Basically I'm stuck!
As I said, the wierd thing is that it works on the form but not the user
control. Also, despite a new set of objects, the overriden method is only
executed onece.
Any help appreciated before I rip it all out and do it another way.
Ian
As an aside, the actual printing to the label printer seems to have flipped
as well, but one problem at a time.
label printer. I have derived my class from the
System.Drawing.Printing.PrintDocument class ond overriden some of the
protected methods. I pass into the constructor a custom Label object that
contains the layout and data and has rendering code.
public LabelPrint(Label label) : base()
{
this.label = label;
}
The key override is the OnPrintPage method.
protected override void OnPrintPage(PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
e.Graphics.PageScale = this.pageScale;
label.Render(e.Graphics);
e.HasMorePages = false;
}
To initiate this for print preview, I have placed a
System.Windows.Forms.PrintPreviewControl on a form and use the following code.
private void PrintPreviewLabel_Click(object sender, EventArgs e)
{
MyLabel label = GetLabel();
LabelPrint labelPrint = new LabelPrint(label);
this.printPreviewControl1.InvalidatePreview();
this.printPreviewControl1.Document = labelPrint;
}
Now to the point. I had this code on both a test form and a user control and
they both worked well as I created different labels to preview. That was on
the beta2 release.
We upgraded to the August CTP release a week or so ago, and the code on the
user control stopped working. It displays the first preview ok, but will not
update as different labels are presented. I placed a breakpoint in the
OnPrintPage method and it was reached for the first label but not for
subsequent labels.
As can be seen from the code, I am creating new MyLabel and LabelPrint
objects each time. I have tried creating a new PrintPreviewControl object
each time and dynamically placing it on the form. I've tried putting the
this.printPreviewControl1.InvalidatePreview(); line after setting the
document. I've tried refreshing the form and printPreviewControl1 object.
Basically I'm stuck!
As I said, the wierd thing is that it works on the form but not the user
control. Also, despite a new set of objects, the overriden method is only
executed onece.
Any help appreciated before I rip it all out and do it another way.
Ian
As an aside, the actual printing to the label printer seems to have flipped
as well, but one problem at a time.