Unable to print on the specified location on Labels

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top