C# 将价格添加到条形码生成的序列号
我已经创建了一个在条形码打印机上打印条形码的代码,但现在我正在尝试将文本框中产品的价格添加到打印中 这是我的密码C# 将价格添加到条形码生成的序列号,c#,winforms,barcode,C#,Winforms,Barcode,我已经创建了一个在条形码打印机上打印条形码的代码,但现在我正在尝试将文本框中产品的价格添加到打印中 这是我的密码 private void frmAddProduct_Load(object sender, EventArgs e) { string barcode = txtCode.Text; Bitmap bitm = new Bitmap(barcode.Length * 40, 110);
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);
这是你的问题,
点
实际上是你画条形码的点,你也在用它来画你的价格。您将需要创建一个新点,即不同的坐标
...
// 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
的值来确定所需的放置位置
祝你好运
我尝试的每件事都会使条形码不起作用
更好地解释这一点,我的意思是它是如何使条形码不起作用的,你能举一个例子说明你是如何使条形码不起作用的吗编辑该部分的问题你能编辑第一句话吗?语法上我不清楚“但现在我想在打印文本框中添加产品的价格”。Mohammed,这很简单。。我将条形码显示为图像进行打印,我希望产品价格显示在其上方。我上一次尝试使价格出现,但更像是在条形码图像的背景中,我想让它出现在它的上方。不要玩弄PointPrice的值,根据它生成的字符串大小计算它。