/
CodigoBarras.cs
66 lines (59 loc) · 2.19 KB
/
CodigoBarras.cs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GatoAbarrotero
{
public partial class frmCodigoBarras : Form
{
public frmCodigoBarras()
{
InitializeComponent();
btnGuardarCodigo.Enabled = false;
btnImprimirCodigo.Enabled = false;
}
private void BtnGenerarCodigo_Click(object sender, EventArgs e)
{
BarcodeLib.Barcode codigo = new BarcodeLib.Barcode();
codigo.IncludeLabel = true;
pnlCodigoBarras.BackgroundImage = codigo.Encode(BarcodeLib.TYPE.CODE128, txtCodigo.Text, Color.Black, Color.White, 400, 100);
btnGuardarCodigo.Enabled = true;
btnImprimirCodigo.Enabled = true;
}
private void BtnGuardarCodigo_Click(object sender, EventArgs e)
{
Image imgFinal = (Image)pnlCodigoBarras.BackgroundImage.Clone();
SaveFileDialog dialogoGuardar = new SaveFileDialog();
dialogoGuardar.AddExtension = true;
dialogoGuardar.Filter = "Image PNG (*.png)|*.png";
dialogoGuardar.ShowDialog();
if (!string.IsNullOrEmpty(dialogoGuardar.FileName))
{
imgFinal.Save(dialogoGuardar.FileName, ImageFormat.Png);
}
imgFinal.Dispose();
}
private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bm = new Bitmap(this.pnlCodigoBarras.Width, this.pnlCodigoBarras.Height);
pnlCodigoBarras.DrawToBitmap(bm, new Rectangle(0, 0, this.pnlCodigoBarras.Width, this.pnlCodigoBarras.Height));
e.Graphics.DrawImage(bm, 0, 0);
}
private void BtnImprimirCodigo_Click(object sender, EventArgs e)
{
printDocument1.Print();
}
private void MenúToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
frmMenu menu = new frmMenu();
menu.Show();
}
}
}