我将根据用户在numericUpDown控件中设置的输入数来生成条形码。问题是,当生成许多条形码时,其他条形码在printpreviewdialog中看不到,因为它不能每隔4-5个图像应用下一行或\n。
int x = 0, y = 10;
for (int i = 1; i <= int.Parse(txtCount.Text); i++)
{
idcount++;
connection.Close();
Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
Random random = new Random();
string randomtext = "MLQ-";
int j;
for (j = 1; j <= 6; j++)
{
randomtext += random.Next(0, 9).ToString();
Image barcodeimg = barcode.Draw(randomtext, 50);
resultimage = new Bitmap(barcodeimg.Width, barcodeimg.Height + 20);
using (var graphics = Graphics.FromImage(resultimage))
using (var font = new Font("Arial", 11)) // Any font you want
using (var brush = new SolidBrush(Color.Black))
using (var format = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far}) // Also, horizontally centered text, as in your example of the expected output
{
graphics.Clear(Color.White);
graphics.DrawImage(barcodeimg, 0, 0);
graphics.DrawString(randomtext, font, brush, resultimage.Width / 2, resultimage.Height, format);
}
x += 25;
}
e.Graphics.DrawImage(resultimage, x, y);
}

发布于 2018-10-10 22:53:28
在光栅化的图形中没有“新线条”。这是像素。你有正确的想法,每n个图像,添加一个新的行。但是由于你使用的是像素,假设每4个图像你需要通过修改所有图形绘制调用的y坐标来添加一个垂直偏移。此偏移量与以像素为单位的行高相结合,可能如下所示:
var rowHeight = 250; // pixels
var maxColumns = 4;
var verticalOffset = (i % maxColums) * rowHeight;然后,当可以提供从0开始或接近0的y坐标时,向其添加垂直偏移。
https://stackoverflow.com/questions/52742729
复制相似问题