Unable to print on the specified location on Labels

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm having difficulty printing on a 4"x3" labels . I set the left margin to
0 but it always prints starting from the middle of the label on the X-axis
(no matter what the margin settings are.) I should note that I was able to
view the label fine in the PrintPreviewDialog.
I checked similar posting but it didn't work for me. I have the following
code prior of calling the Print():

PaperSize CustomSize = new PaperSize("CustomSize", 400, 300);
printID.DefaultPageSettings.PaperSize = CustomSize;
printID.PrinterSettings.PrinterName = IDLabelPrinter;
printID.DefaultPageSettings.PaperSize.Width = 400;
printID.DefaultPageSettings.PaperSize.Height = 300;
Margins margins = new Margins(0,0,0,0);
printID.DefaultPageSettings.Margins = margins;
printID.Print();

then in the PrintPageEventHandler I have what suppose to print a circle in
the upper left corner with a text inside it but the output is in the middle
of the label:

float X = 0.0F; // x-coordinate of the upper-left corner
float Y = 0.0F; // y-coordinate of the upper-left corner
float circleWidth = 64.0F;
float circleHeight = 64.0F;
// Create start and sweep angles.
float startAngle = 0.0F;
float sweepAngle = 360.0F;
// Fill pie to screen.
e.Graphics.FillPie(FillBrush, X, Y, circleWidth, circleHeight, startAngle,
sweepAngle);

StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
Font printFont = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
Y = (float)(printFont.GetHeight(e.Graphics));
float Y2 = (circleHeight/2.0F) - (Y/2.0F);
X = circleWidth/2.0F;
e.Graphics.DrawString(BxTypelabel.Text,printFont,Brushes.White,X,
Y2,drawFormat);


Any help would be greatly appreciated.
Thank you
 
The label prints fine now. I added some code that offsets the marginbound
to the printer's Real margin bound.
But what really made the difference is commenting the following code that
sets the papersize. Although that's the actual size of the label being
printed.

PaperSize CustomSize = new PaperSize("CustomSize",400,300);
printID.DefaultPageSettings.PaperSize = CustomSize;

Thank you
 
Back
Top