1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
private void generatecodebarre()
{
string text2 = "*"+TB_nom.Text+"*";
MessageBox.Show(text2);
barcode = text2;
bitmap = new Bitmap(barcode.Length*100 ,150);
string text = TB_nom.Text + "\n" + TB_Prenom.Text;
using (Graphics graphics = Graphics.FromImage(bitmap))
{
//Font ofont = new Font("IDAHC39M Code 39 Barcode", 20);
Font ifont = new Font("Arial", 20);
Font ofont = new Font("Code 128",45);
PointF point = new PointF(2f, 2f);
PointF pt = new PointF(point.X + 50, point.Y + 50);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush White = new SolidBrush(Color.White);
graphics.FillRectangle(White, 0, 0, bitmap.Width, bitmap.Height);
graphics.DrawString(barcode, ofont, black, point);
//graphics.DrawString(text, ifont, black, pt);
}
pictureBox1.Image = bitmap;
pictureBox1.Height = bitmap.Height;
pictureBox1.Width = bitmap.Width;
Imprimez();
}
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(this.pictureBox1.Image,0,0,bitmap.Width,bitmap.Height);
}
private void Imprimez()
{
PrintDialog print1 = new PrintDialog();
print1.Document = this.pd;
if (print1.ShowDialog() == DialogResult.OK)
{
pd.Print();
}
} |
Partager