将价格添加到条形码生成的序列号
add price to barcode generated serial
我已经创建了一个代码来在条码打印机上打印条码,但现在试图将文本框中的产品价格添加到打印中
这是我的代码
private void frmAddProduct_Load(object sender, EventArgs e)
{
string barcode = txtCode.Text;
Bitmap bitm = new Bitmap(barcode.Length * 40, 110);
using (Graphics graphic = Graphics.FromImage(bitm))
{
Font newfont = new Font("IDAutomationHC39M", 14);
PointF point = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
graphic.FillRectangle(white, 0, 0, bitm.Width, bitm.Height);
graphic.DrawString("*" + barcode + "*", newfont, black, point);
}
using (MemoryStream Mmst = new MemoryStream())
{
bitm.Save("ms", ImageFormat.Jpeg);
pictureBox1.Image = bitm;
pictureBox1.Width = bitm.Width;
pictureBox1.Height = bitm.Height;
}
}
private void btnCodePrint_Click(object sender, EventArgs e)
{
short numCopies = 0;
numCopies = Convert.ToInt16(txtCodeNo.Text);
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
PrintDocument pdoc = new PrintDocument();
pdoc.PrintPage += new PrintPageEventHandler(pqr);
pdoc.PrinterSettings.Copies = numCopies;
pdoc.Print();
}
}
这就是我目前遇到的问题,我想将文本框中的价格添加到所附图片中条形码上方或下方的条形码中,但我似乎无法找到解决此问题的方法,我尝试的一切都使条形码不起作用
编辑
我试过了,但价格显示在条形码上方
string barcode = txtCode.Text;
string price = txtPprice.Text;
Bitmap bitm = new Bitmap(barcode.Length * 40, 110);
using (Graphics graphic = Graphics.FromImage(bitm))
{
Font newfont = new Font("IDAutomationHC39M", 14);
Font newfont2 = new Font("Arial", 14);
PointF point = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
graphic.FillRectangle(white, 0, 0, bitm.Width, bitm.Height);
graphic.DrawString("*" + price + "*", newfont2, black, point);
graphic.DrawString("*" + barcode + "*", newfont, black, point);
这是你的问题,point
实际上是你绘制条形码的地方,你也用它来绘制你的价格。您需要创建一个新点,即不同的坐标
...
// a new point for your price
PointF pointPrice = new PointF(20f, 20f);
// Draw your price
graphic.DrawString("*" + price + "*", newfont2, black, pointPrice);
// Draw your barcode
graphic.DrawString("*" + barcode + "*", newfont, black, point);
只需使用 pointPrice
的值来确定您想要的放置位置
祝你好运
我已经创建了一个代码来在条码打印机上打印条码,但现在试图将文本框中的产品价格添加到打印中
这是我的代码
private void frmAddProduct_Load(object sender, EventArgs e)
{
string barcode = txtCode.Text;
Bitmap bitm = new Bitmap(barcode.Length * 40, 110);
using (Graphics graphic = Graphics.FromImage(bitm))
{
Font newfont = new Font("IDAutomationHC39M", 14);
PointF point = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
graphic.FillRectangle(white, 0, 0, bitm.Width, bitm.Height);
graphic.DrawString("*" + barcode + "*", newfont, black, point);
}
using (MemoryStream Mmst = new MemoryStream())
{
bitm.Save("ms", ImageFormat.Jpeg);
pictureBox1.Image = bitm;
pictureBox1.Width = bitm.Width;
pictureBox1.Height = bitm.Height;
}
}
private void btnCodePrint_Click(object sender, EventArgs e)
{
short numCopies = 0;
numCopies = Convert.ToInt16(txtCodeNo.Text);
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
PrintDocument pdoc = new PrintDocument();
pdoc.PrintPage += new PrintPageEventHandler(pqr);
pdoc.PrinterSettings.Copies = numCopies;
pdoc.Print();
}
}
这就是我目前遇到的问题,我想将文本框中的价格添加到所附图片中条形码上方或下方的条形码中,但我似乎无法找到解决此问题的方法,我尝试的一切都使条形码不起作用
编辑
我试过了,但价格显示在条形码上方
string barcode = txtCode.Text;
string price = txtPprice.Text;
Bitmap bitm = new Bitmap(barcode.Length * 40, 110);
using (Graphics graphic = Graphics.FromImage(bitm))
{
Font newfont = new Font("IDAutomationHC39M", 14);
Font newfont2 = new Font("Arial", 14);
PointF point = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
graphic.FillRectangle(white, 0, 0, bitm.Width, bitm.Height);
graphic.DrawString("*" + price + "*", newfont2, black, point);
graphic.DrawString("*" + barcode + "*", newfont, black, point);
这是你的问题,point
实际上是你绘制条形码的地方,你也用它来绘制你的价格。您需要创建一个新点,即不同的坐标
...
// a new point for your price
PointF pointPrice = new PointF(20f, 20f);
// Draw your price
graphic.DrawString("*" + price + "*", newfont2, black, pointPrice);
// Draw your barcode
graphic.DrawString("*" + barcode + "*", newfont, black, point);
只需使用 pointPrice
的值来确定您想要的放置位置
祝你好运