PrintPageEventArgs MarginBounds

  • Thread starter Thread starter Jen
  • Start date Start date
J

Jen

I am trying to print barcode labels directly to a Sato label printer.
The problem that I am having is that the MarginBound properties are
set to one inch margins. I cannot seem to figure out when and where
these properties are being set. I am using the following code,
pDlgBarcode is a PrintDialog control. I have a PrintDocument attached
to the PrintDialog control. It prints one inch from the left edge. My
little labels are only 2" wide. Thanks for any help.
Jennifer

private void PrintBarcode()
{
if(DialogResult.OK == pDlgBarcode.ShowDialog())
{
pDlgBarcode.Document.Print();
}
}

private void pDocBarcode_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
//They can only print one part at a time from this screen.
Barcode bc = new Barcode();
double dLabelHeight = e.PageSettings.PaperSize.Height;
double dLabelWidth = e.PageSettings.PaperSize.Width;
bool bLarge = false;
Brush bBrush = Brushes.Black;
int iLineSpace = 0;
int iLineAt = 0;
Font fFont;

if(dLabelWidth > 200 && dLabelHeight > 150)
bLarge = true;

if(bLarge == true)
{
fFont = new Font("Times New Roman", 18, FontStyle.Regular,
GraphicsUnit.Point);
iLineSpace = 50;
}
else
{
fFont = new Font("Times New Roman", 7, FontStyle.Regular,
GraphicsUnit.Point);
iLineSpace = 13;
}

//Print Barcode text
GetBarcodeInfo();

e.Graphics.DrawString(msDescription, fFont, bBrush, 0,
iLineAt); //Description
iLineAt += iLineSpace;
e.Graphics.DrawString("VPN#"+msVPN, fFont, bBrush, 0,
iLineAt); //VPN#
iLineAt += iLineSpace;
e.Graphics.DrawString("SN#"+msSN, fFont, bBrush, 0, iLineAt); //SN#
iLineAt += iLineSpace;
e.Graphics.DrawString("ORD#"+msOrder+msLoc+msShelfLife,
fFont, bBrush, 0, iLineAt); //ORD# Loc SLL

e.HasMorePages = false;
}
 
Alright, it looked great in print preview, but when I got back to work
this morning and sent it to the printer it still used 1 inch left and
right margins. It looks like it is clipping my strings. I noticed that
the VisibleClipBounds are set {X=0.0 Y=0.0 Width=78.81774
Height=59.113308}, the MarginBounds are set {X=10 Y=10 Width=180
Height=130}. My pageBounds are X=0 Y=0 Width=200 Height=150}.
Shouldn't it print to my printer with 10/100 inch margins?

Jennifer
 
Jen said:
Alright, it looked great in print preview, but when I got back to work
this morning and sent it to the printer it still used 1 inch left and
right margins. It looks like it is clipping my strings. I noticed that
the VisibleClipBounds are set {X=0.0 Y=0.0 Width=78.81774
Height=59.113308}, the MarginBounds are set {X=10 Y=10 Width=180
Height=130}. My pageBounds are X=0 Y=0 Width=200 Height=150}.
Shouldn't it print to my printer with 10/100 inch margins?

Jennifer

What if you hit print from the print preview dialog? I'd be somewhat
surprised if it rendered differently between there and the printer
(but I haven't done anything with page size ever). If it prints fine
there, then there's probably something setup differently within the
PrintDocument between the print dialog and the preview dialog.
Otherwise, I'm out of ideas at the moment. But I've never
printed on anything other than "normal" paper.
 
Another interesting thing, when I print this same thing to my laser
printer, the margins are exactly the way I would expect them to be. It
prints just fine on 8.5 X 11 paper. Anyone else have any ideas?
 
The problem was not related at all to the margins. The problem was
with the DrawString call. I changed the DrawString function to take a
Rectangle instead of x,y coordinates and it printed just fine.

RectangleF rect = new RectangleF(15, fLineAt, (float)dLabelWidth,
(float)dLabelHeight);

e.Graphics.DrawString(msDescription, fFont, bBrush, rect, sfFormat);
fLineAt += iLineSpace;
rect.Y = fLineAt;
e.Graphics.DrawString("VPN#"+msVPN, fFont, bBrush, rect, sfFormat);
fLineAt += iLineSpace;
rect.Y = fLineAt;
e.Graphics.DrawString("SN#"+msSN, fFont, bBrush, rect, sfFormat);
fLineAt += iLineSpace;
rect.Y = fLineAt;
e.Graphics.DrawString("ORD#"+msOrder+" "+msLoc+" "+msShelfLife, fFont,
bBrush, rect, sfFormat);
fLineAt += iLineSpace;

rect.Y = fLineAt;
 
Back
Top