Jump to content

Impressão Código de Barras


yozhi

Recommended Posts

Bom dia , é o seguinte elaborei um programa de impressão de códigos de barras, só que agora gostaria de colocar também a descrição por cima do código do barras só que me deu um bloqueio e não sei como o fazer, se alguém pudesse ajudar, agradecia.

Eis o código:

Public Class Form1
Dim cb As String
Dim stringtodraw As String
Private impressora As String = "TSC TTP-244 Pro(CB)"
Dim fontsize As Single
Dim copias As Single = 1
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs, e As Printing.PrintPageEventArgs) Handles PictureBox1.Paint
 e.Graphics.Clear(Color.White)
 Dim MyBrush As New SolidBrush(Color.Black)
 Dim StringFontpic As New Font("IDAutomationHC39M Free Version", 13)
 Dim textArea As Rectangle = New Rectangle(0, 30, PictureBox1.Width, PictureBox1.Height)
 Dim textformat As StringFormat = New StringFormat
 textformat.Alignment = StringAlignment.Center
 e.Graphics.DrawString(stringtodraw, StringFontpic, MyBrush, textArea, textformat)
 PictureBox1.Size = New Size(360, 97)
 Refresh()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnimpr.Click
 copias = TextBox2.Text
 PrintDocument1.PrinterSettings.PrinterName = impressora
 PrintDocument1.PrinterSettings.Copies = copias
 PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
 e.Graphics.Clear(Color.White)
 Dim MyBrush As New SolidBrush(Color.Black)
 Dim stringfont As New Font("IDAutomationHC39M Free Version", fontsize)
 Dim textArea As Rectangle = New Rectangle(0, 40, 207.874015748, 94.488188976)
 Dim textformat As StringFormat = New StringFormat
 textformat.Alignment = StringAlignment.Center
 e.Graphics.DrawString(stringtodraw, stringfont, MyBrush, textArea, textformat)
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
 If TextBox1.Text.Length > 10 Then
	 fontsize = 9
 Else
	 fontsize = 10
 End If
 stringtodraw = "*" & TextBox1.Text & "*"
 PictureBox1.Refresh()
End Sub
Private Sub btnsair_Click(sender As Object, e As EventArgs) Handles btnsair.Click
 Application.Exit()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 If impressoratexto.Visible = True Then
	 impressoratexto.Hide()
 Else
	 impressoratexto.Show()
 End If
 impressoratexto.Text = impressora
End Sub
Private Sub impressoratexto_TextChanged(sender As Object, e As EventArgs) Handles impressoratexto.TextChanged
 impressora = impressoratexto.Text
End Sub
Private Sub rad1lt_CheckedChanged(sender As Object, e As EventArgs) Handles rad1lt.CheckedChanged
 stringtodraw = "*" & TextBox1.Text & "C" & "*"
 PictureBox1.Refresh()
End Sub
Private Sub rad5lt_CheckedChanged(sender As Object, e As EventArgs) Handles rad5lt.CheckedChanged
 stringtodraw = "*" & TextBox1.Text & "T" & "*"
 PictureBox1.Refresh()
End Sub
Private Sub rad10lt_CheckedChanged(sender As Object, e As EventArgs) Handles rad10lt.CheckedChanged
 stringtodraw = "*" & TextBox1.Text & "U" & "*"
 PictureBox1.Refresh()
End Sub
Private Sub rad25lt_CheckedChanged(sender As Object, e As EventArgs) Handles rad25lt.CheckedChanged
 stringtodraw = "*" & TextBox1.Text & "P" & "*"
 PictureBox1.Refresh()
End Sub
End Class

PS: Sou novo nisto por isso 😄

Link to comment
Share on other sites

Dim x As Integer = 0
Dim y As Integer = 0
Dim rec As New Rectangle(x, y, 196.535433071, 94.488188976)
Using font As New Font("Arial", 12)
Dim textformat As StringFormat = New StringFormat
textformat.Alignment = StringAlignment.Center
e.Graphics.DrawString(teste, font, Brushes.Black, x, y, textformat)
Dim size As SizeF = e.Graphics.MeasureString(teste, font)
e.Graphics.DrawRectangle(Pens.Transparent, rec)
y += size.Height
End Using
Using font As New Font("IDAutomationHC39M Free Version", 9)
e.Graphics.DrawString(stringtodraw, font, Brushes.Black, x, y)
Dim size1 As SizeF = e.Graphics.MeasureString(stringtodraw, font)
e.Graphics.DrawRectangle(Pens.Transparent, rec)
y += Size.Height
End Using

Já consegui o que queria alterando desta forma o código, mas o texto não me aparece centrado.

Link to comment
Share on other sites

Dim x As Integer = 0
Dim y As Integer = 0
Dim rec As New Rectangle(x, y, 196.535433071, 94.488188976)
Using font As New Font("Arial", 10)
y = 5
Dim textformat As StringFormat = New StringFormat
textformat.Alignment = StringAlignment.Center
e.Graphics.DrawString(teste, font, Brushes.Black, rec, textformat)
Dim size As SizeF = e.Graphics.MeasureString(teste, font)
y += size.Height
End Using

Dim x1 As Integer = 0
Dim y1 As Integer

If WaterMarkTextBox2.Text = "" Then
y1 = 20
Else
y1 = 40
End If
Dim rec1 As New Rectangle(x1, y1, 196.535433071, 94.488188976)
Using font As New Font("IDAutomationHC39M Free Version", fontsize)
Dim textformat1 As StringFormat = New StringFormat
textformat1.Alignment = StringAlignment.Center
e.Graphics.DrawString(stringtodraw, font, Brushes.Black, rec1, textformat1)
Dim size1 As SizeF = e.Graphics.MeasureString(stringtodraw, font)
y1 += Size.Height
End Using

aqui está as alterações , não me pergunte o que alterei, já foi ontem e não me lembro e agora já estou com outra dúvida 😄

obrigado na mesma 😉

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.