I have a working code, on both the target machine, and my own machine. However, my machine is a W10, and the target is a W7. The code below should draw 5 barcodes on the right half of the page, however, when I use it on the target machine, one of two scenarios happen, depending on how I change the code. If I make the width of the barcode too big, it will go beyond the edge of the page and it will not be readable. If I make the width slightly too small, it resizes the whole barcode, and it becomes to small, again unreadable. I assume that this is a problem with the print drivers in which, they are different for both W10 and W7 (I used the same printer on both machines, same settings as well). Is there a problem with my code and how do I change it?
private void DocumentDrucker_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics graphic = e.Graphics;
//SolidBrush brush = new SolidBrush(Color.Black);
Font font = new Font("Courier New", 80, FontStyle.Bold);
Font fontK = new Font("Courier New", 30, FontStyle.Bold);
Font fontKleinst = new Font("Courier New", 15, FontStyle.Bold);
float pageWidth = e.PageSettings.PrintableArea.Width;
float pageHeight = e.PageSettings.PrintableArea.Height;
float fontHeight = font.GetHeight();
int startX = 0;
int startY = 0;
int offsetY = 0;
float imageH = Properties.Resources.pfeilO.Height;
float imageW = Properties.Resources.pfeilO.Width;
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
//var imagePoint = new Point(Convert.ToInt32(pageWidth * 0.55), offsetY);
var barcodePoint = new Point(Convert.ToInt32(pageWidth * 0.66), 0);
for (; elemente < ZumDrucken.Items.Count; elemente++)
{
var currentItem = ZumDrucken.Items[elemente];
graphic.DrawString(currentItem.Text.Substring(4, 3), fontK, Brushes.Black, startX, startY +offsetY+20);
graphic.DrawString("Typ:"+currentItem.Text.Substring(0,3), fontKleinst, Brushes.Black, startX, (startY + offsetY + 30+fontK.Height));
graphic.DrawString(currentItem.Text.Substring(7), font, Brushes.Black, (startX+75), startY + offsetY);
var currentImage = Properties.Resources.pfeilU;
bool lastCharIsAOne = currentItem.Text[currentItem.Text.Length - 1] == '1';
if (currentItem.Checked == lastCharIsAOne)
{
currentImage = Properties.Resources.pfeilO;
}
graphic.DrawImage(currentImage, Convert.ToInt32((pageWidth * 0.55)), offsetY+20, imageW, imageH);
b.EncodedImage?.Dispose();
//b.Encode(TYPE.CODE128A, "SBD" + currentItem.Text.Substring(0, 3) + currentItem.Text.Substring(4), Color.Black, Color.Transparent,Convert.ToInt32(pageWidth-50), Convert.ToInt32(pageHeight * 0.151));
b.Encode(TYPE.CODE128A, "SBD" + currentItem.Text.Substring(0, 3) + currentItem.Text.Substring(4), Color.Black, Color.Transparent, 570, 135);
barcodePoint.Y = offsetY;
graphic.DrawImage(b.EncodedImage, barcodePoint);
offsetY = offsetY + 163;
if (offsetY >= pageWidth-120)
{
e.HasMorePages = true;
offsetY = 0;
elemente++;
graphic.Dispose();
b.Dispose();
font.Dispose();
fontK.Dispose();
fontKleinst.Dispose();
return;
}
else
{
e.HasMorePages = false;
}
}
graphic.Dispose();
b.Dispose();
font.Dispose();
fontK.Dispose();
fontKleinst.Dispose();
}
Here is also the code where I set all the margins to 0, and change the paper mode to landscape.
private void Drucken_Click(object sender, EventArgs e)
{
DocumentDrucker.DocumentName = "Dokument";
elemente = 0;
DruckDialog.Document = DocumentDrucker;
DocumentDrucker.DefaultPageSettings.Landscape = true;
DocumentDrucker.DefaultPageSettings.Margins.Top = 0;
DocumentDrucker.DefaultPageSettings.Margins.Left = 0;
DocumentDrucker.DefaultPageSettings.Margins.Right = 0;
DocumentDrucker.DefaultPageSettings.Margins.Bottom = 0;
if (DruckDialog.ShowDialog() == DialogResult.OK)
DocumentDrucker.Print();
}