gpt4 book ai didi

c# - 将价格添加到条形码生成的序列号

转载 作者:太空狗 更新时间:2023-10-30 01:13:25 24 4
gpt4 key购买 nike

我已经创建了一个代码来在条形码打印机上打印条形码,但现在试图将文本框中产品的价格添加到打印中

这是我的代码

        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();

}
}

enter image description here

这就是我目前遇到的问题,我想将文本框中的价格添加到所附图像中条形码上方或下方的条形码中,但我似乎无法找到一种方法来完成这项工作,我所做的一切尝试使条形码不起作用

编辑

我试过了,但价格显示在条形码上方

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 的值来确定您想要的放置位置

祝你好运

关于c# - 将价格添加到条形码生成的序列号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50340872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com