Мне нужно распечатать все инвентарные элементы за один раз.Для печати я выбрал все элементы нажатием кнопки и выполняю печать, используя функцию DrawString
или DrawImage
, которая работает нормально, но проблема в том, что если имена элементов слишком длинные, тогда у меня ширина клипа до 100px, а текст обернут и напечатанвызов функции, но при печати 2-й строки элементы, начинающиеся с точки Y, не могут определить, что создает проблему.если я правильно определил высоту 1-й строки, то я могу установить координаты Y 2-й строки соответственно, эту проблему можно решить, но я не знаю, как это сделать.Как вы можете видеть результат на рисунке ниже.
* Проблема в этом куске кода:
if (numbarcode < NBbarcode_perLine)
startX += 150;
else
{
//MessageBox.Show(rectangleHeight.ToString());
startX = 5;
startY += 150; // space between 2 lines
numbarcode = 0;
}
код:
// The PrintPage event is raised for each page to be printed.
private void PrintBarcodeEvent_PrintPage(object sender, PrintPageEventArgs e)
{
int startX = 5;
int startY = 5;
Database db = new Database();
db.DBOpen();
int NBbarcode_perLine = 5;
int numbarcode = 0;
int barcodePerPage = 35;
int totalcodebar = listTobePrint.Count;
for (int i = 0; i < barcodePerPage; i++)
{
String code = listTobePrint[countbarcode].Code;
String name = db.GetByValue(Database.TABLE_ITEMS, Database.CODE_ITEMS, code, 2);
String price = db.GetByValueForInt(Database.TABLE_ITEMS, Database.CODE_ITEMS, code, 8);
Font printFont = new Font("Arial", 10.0f);
e.Graphics.DrawString("Phulkari by VIRSA", printFont, System.Drawing.Brushes.Black,
startX, startY, new StringFormat());
int x2 = startX + 3;
int y2 = startY + 15;
e.Graphics.DrawImage(Util.ImageWpfToGDI(Util.GenerateBarcode(code)), x2, y2, 100, 50);
int x3 = startX;
int y3 = y2 + 50;
e.Graphics.DrawString(code, printFont, System.Drawing.Brushes.Black,
x3, y3, new StringFormat());
int x4 = startX;
int y4 = y3 + 15;
e.Graphics.DrawString("Rs." + price, printFont, System.Drawing.Brushes.Black,
x4, y4, new StringFormat());
// Measure string.
SizeF stringSize = new SizeF();
stringSize = e.Graphics.MeasureString(name, printFont);
int width = (int)stringSize.Width;
int height = (int)stringSize.Height;
//MessageBox.Show(width.ToString() + ", Height: "+height);
int x5 = startX;
int y5 = y4 + 15;
RectangleF rectangle = new RectangleF(x5, y5, 100, 0);
int rectangleWidht = (int)rectangle.Width;
int rectangleHeight = (int)rectangle.Height;
//MessageBox.Show(rectangleHeight.ToString());
e.Graphics.DrawString(name, printFont, System.Drawing.Brushes.Black,
rectangle, new StringFormat());
numbarcode++;
countbarcode++;
if (numbarcode < NBbarcode_perLine)
startX += 150;
else
{
//MessageBox.Show(rectangleHeight.ToString());
startX = 5;
startY += 150; // space between 2 lines
numbarcode = 0;
}
if (countbarcode == totalcodebar) break;
if (i == barcodePerPage - 1)
{
e.HasMorePages = true;
return;
}
}
countbarcode = 0;
e.HasMorePages = false;
db.DBClose();
}