Unable to execute the VB.Net code even can't view in Print Preview after clicked. Anyone there to help me. I'm new to VB.Net.
Imports System.Drawing.Imaging
'Imports IDAutomation.Windows.Forms.LinearBarCode
Imports System.Drawing.Printing
Imports System.Configuration
'Imports GenCode128
Imports System.Data.SqlClient
Public Class Form1
Dim table2 As New DataTable
Dim dte = Date.Now()
Dim PrintDoc As New Printing.PrintDocument()
Dim pd_PrintDialog As New PrintDialog
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub txtbarcode_TextChanged(sender As Object, e As EventArgs) Handles txtbarcode.TextChanged
Dim Generator As New MessagingToolkit.Barcode.BarcodeEncoder
Generator.BackColor = Color.Transparent
Generator.LabelFont = New Font("Arial", 5, FontStyle.Regular)
Generator.IncludeLabel = True
Generator.CustomLabel = txtbarcode.Text
Generator.Height = 100
Try
PbBarcode.Image = New Bitmap(Generator.Encode(MessagingToolkit.Barcode.BarcodeFormat.Code93, txtbarcode.Text))
Catch
End Try
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtbarcode.TextChanged
PbBarcode.Image = Code128(txtbarcode.Text, "A")
End Sub
Private Sub btnprintbarcode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprintbarcode.Click
'Barcode printing
If txtbarcode.Text = "" Then 'Barcode is empty
MsgBox("Please make sure you type the text to be converted to a barcode")
Exit Sub
Else
pd_PrintDialog.UseEXDialog = True
pd_PrintDialog.AllowPrintToFile = False
If pd_PrintDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDoc.PrinterSettings = pd_PrintDialog.PrinterSettings
AddHandler PrintDoc.PrintPage, AddressOf PrintDocHandler
'Print
PrintDoc.Print()
ElseIf pd_PrintDialog.ShowDialog = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
End If
End Sub
'This is the event handler for printing bar codes
Private Sub PrintDocHandler(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
Dim rect As New Rectangle(50, 75, 750, 1000)
Dim rect1 As New Rectangle(50, 75, 750, 1000)
ev.Graphics.DrawString(txtpartnumber.Text, New Font("Arial", 5, FontStyle.Regular), Brushes.Black, rect)
ev.Graphics.DrawString(txtqty.Text, New Font("Arial", 5, FontStyle.Regular), Brushes.Black, rect)
ev.Graphics.DrawImage(PbBarcode.Image, rect1)
End Sub
Private Sub butPageSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
PageSetupDialog1.Document = PrintDoc
PageSetupDialog1.ShowDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub btnpreview_Click(sender As Object, e As EventArgs) Handles btnpreview.Click
AddHandler PrintDoc.PrintPage, AddressOf PrintDocHandler
PrintDocument1.Document = PrintDoc
PrintDocument1.ShowDialog()
End Sub
End Class