473,231 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

I need some help here

Hi,
I found this code that can solve a problem I have. It sends print direct to
printer.

Imports System
Imports System.Text
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential)> _
Public Structure DOCINFO<MarshalAs(UnmanagedType.LPWStr)>
Public pDocName As String<MarshalAs(UnmanagedType.LPWStr)>
Public pOutputFile As String<MarshalAs(UnmanagedType.LPWStr)>
Public pDataType As String
End Structure 'DOCINFO

Public Class PrintDirect

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
False, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(pPrinterName As String, ByRef phPrinter
As IntPtr, pDefault As Integer) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
False, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function StartDocPrinter(hPrinter As IntPtr, Level As Integer,
ByRef pDocInfo As DOCINFO) As Long
<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function StartPagePrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Ansi, ExactSpelling := True,
CallingConvention := CallingConvention.StdCall)> _
Public Shared Function WritePrinter(hPrinter As IntPtr, data As String, buf
As Integer, ByRef pcWritten As Integer) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function EndPagePrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function EndDocPrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(hPrinter As IntPtr) As Long
End Class 'PrintDirect

Public Class App

Public Shared Sub Main()
Dim lhPrinter As New System.IntPtr()

Dim di As New DOCINFO()
Dim pcWritten As Integer = 0
Dim st1 As String
' text to print with a form feed character
st1 = "This is an example of printing directly to a printer" +
ControlChars.FormFeed
di.pDocName = "my test document"
di.pDataType = "RAW"
' the \x1b means an ascii escape character
st1 = ChrW(27) + "*c600a6b0P" + ControlChars.FormFeed
'lhPrinter contains the handle for the printer opened
'If lhPrinter is 0 then an error has occured
PrintDirect.OpenPrinter("\\192.168.1.101\hpl", lhPrinter, 0)
PrintDirect.StartDocPrinter(lhPrinter, 1, di)
PrintDirect.StartPagePrinter(lhPrinter)
Try
' Moves the cursor 900 dots (3 inches at 300 dpi) in from the left margin, and
' 600 dots (2 inches at 300 dpi) down from the top margin.
st1 = ChrW(27) + "*p900x600Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Using the print model commands for rectangle dimensions, "600a" specifies
a rectangle
' with a horizontal size or width of 600 dots, and "6b" specifies a vertical
' size or height of 6 dots. The 0P selects the solid black rectangular area
fill.
st1 = ChrW(27) + "*c600a6b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with width of 6 dots, height of 600 dots, and a
' fill pattern of solid black.
st1 = ChrW(27) + "*c6a600b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Moves the current cursor position to 900 dots, from the left margin and
' 1200 dots down from the top margin.
st1 = ChrW(27) + "*p900x1200Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with a width of 606 dots, a height of 6 dots and a
// fill pattern of solid black.
st1 = ChrW(27) + "*c606a6b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Moves the current cursor position to 1500 dots from the left margin and
' 600 dots down from the top margin.
st1 = ChrW(27) + "*p1500x600Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with a width of 6 dots, a height of 600 dots and a
' fill pattern of solid black.
st1 = ChrW(27) + "*c6a600b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten) ' Send a
form feed character to the printer
st1 = ControlChars.FormFeed
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
PrintDirect.EndPagePrinter(lhPrinter)
PrintDirect.EndDocPrinter(lhPrinter)
PrintDirect.ClosePrinter(lhPrinter)
End Sub 'Main
End Class 'App
It works fine. I now wanted to include a barcode so I added the foll code
between the "TRY" "CATCH"

Dim pbox As New PictureBox
Dim NewBarcode As IDAutomation.Windows.Forms.LinearBarCode.Barcode =
New Barcode
NewBarcode.Size = New System.Drawing.Size(148, 64)
NewBarcode.Location = New System.Drawing.Point(176, 7)
NewBarcode.Name = "NewBarcode"
NewBarcode.DataToEncode = "999928829"
NewBarcode.RefreshImage()
pbox.Image = NewBarcode.Picture

st1 = pbox.ToString
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)

st1 = ChrW(27) + "*p50x400Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)

but that didn't work. The barcode dll was downloaded from
http://www.idautomation.com/formscon...rolManual.html

I get the license prompt when I run my program but where the barcode should
be on the page have "System.Windows.Forms.PictureBox, SizeMode: Normal"

I guess there is a problem converting the barcode o string. How can I fix
this?

Thanks
Jul 21 '05 #1
4 2178
The code that you are using goes around the driver. The driver is what
converts bitmaps to printer codes. Therefore, if you go around the driver,
you cannot send a bitmap to the printer.

Some printers have native support for barcodes and you use a printer code to
get it to print a barcode. I'm pretty sure this is the case with Zebra
printers.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi,
I found this code that can solve a problem I have. It sends print direct
to
printer.

Imports System
Imports System.Text
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential)> _
Public Structure DOCINFO<MarshalAs(UnmanagedType.LPWStr)>
Public pDocName As String<MarshalAs(UnmanagedType.LPWStr)>
Public pOutputFile As String<MarshalAs(UnmanagedType.LPWStr)>
Public pDataType As String
End Structure 'DOCINFO

Public Class PrintDirect

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
False, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(pPrinterName As String, ByRef phPrinter
As IntPtr, pDefault As Integer) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
False, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function StartDocPrinter(hPrinter As IntPtr, Level As
Integer,
ByRef pDocInfo As DOCINFO) As Long
<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function StartPagePrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Ansi, ExactSpelling := True,
CallingConvention := CallingConvention.StdCall)> _
Public Shared Function WritePrinter(hPrinter As IntPtr, data As String,
buf
As Integer, ByRef pcWritten As Integer) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function EndPagePrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function EndDocPrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(hPrinter As IntPtr) As Long
End Class 'PrintDirect

Public Class App

Public Shared Sub Main()
Dim lhPrinter As New System.IntPtr()

Dim di As New DOCINFO()
Dim pcWritten As Integer = 0
Dim st1 As String
' text to print with a form feed character
st1 = "This is an example of printing directly to a printer" +
ControlChars.FormFeed
di.pDocName = "my test document"
di.pDataType = "RAW"
' the \x1b means an ascii escape character
st1 = ChrW(27) + "*c600a6b0P" + ControlChars.FormFeed
'lhPrinter contains the handle for the printer opened
'If lhPrinter is 0 then an error has occured
PrintDirect.OpenPrinter("\\192.168.1.101\hpl", lhPrinter, 0)
PrintDirect.StartDocPrinter(lhPrinter, 1, di)
PrintDirect.StartPagePrinter(lhPrinter)
Try
' Moves the cursor 900 dots (3 inches at 300 dpi) in from the left margin,
and
' 600 dots (2 inches at 300 dpi) down from the top margin.
st1 = ChrW(27) + "*p900x600Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Using the print model commands for rectangle dimensions, "600a"
specifies
a rectangle
' with a horizontal size or width of 600 dots, and "6b" specifies a
vertical
' size or height of 6 dots. The 0P selects the solid black rectangular
area
fill.
st1 = ChrW(27) + "*c600a6b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with width of 6 dots, height of 600 dots, and a
' fill pattern of solid black.
st1 = ChrW(27) + "*c6a600b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Moves the current cursor position to 900 dots, from the left margin and
' 1200 dots down from the top margin.
st1 = ChrW(27) + "*p900x1200Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with a width of 606 dots, a height of 6 dots and a
// fill pattern of solid black.
st1 = ChrW(27) + "*c606a6b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Moves the current cursor position to 1500 dots from the left margin and
' 600 dots down from the top margin.
st1 = ChrW(27) + "*p1500x600Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with a width of 6 dots, a height of 600 dots and a
' fill pattern of solid black.
st1 = ChrW(27) + "*c6a600b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten) ' Send a
form feed character to the printer
st1 = ControlChars.FormFeed
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
PrintDirect.EndPagePrinter(lhPrinter)
PrintDirect.EndDocPrinter(lhPrinter)
PrintDirect.ClosePrinter(lhPrinter)
End Sub 'Main
End Class 'App
It works fine. I now wanted to include a barcode so I added the foll code
between the "TRY" "CATCH"

Dim pbox As New PictureBox
Dim NewBarcode As IDAutomation.Windows.Forms.LinearBarCode.Barcode
=
New Barcode
NewBarcode.Size = New System.Drawing.Size(148, 64)
NewBarcode.Location = New System.Drawing.Point(176, 7)
NewBarcode.Name = "NewBarcode"
NewBarcode.DataToEncode = "999928829"
NewBarcode.RefreshImage()
pbox.Image = NewBarcode.Picture

st1 = pbox.ToString
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)

st1 = ChrW(27) + "*p50x400Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)

but that didn't work. The barcode dll was downloaded from
http://www.idautomation.com/formscon...rolManual.html

I get the license prompt when I run my program but where the barcode
should
be on the page have "System.Windows.Forms.PictureBox, SizeMode: Normal"

I guess there is a problem converting the barcode o string. How can I fix
this?

Thanks

Jul 21 '05 #2
Hi,
Where can I find code on using the driver instead? I want to print invoices
with a barcode on them. The invoice data will be pulled from database and
sent to printer.

Thanks

"Nick Malik [Microsoft]" wrote:
The code that you are using goes around the driver. The driver is what
converts bitmaps to printer codes. Therefore, if you go around the driver,
you cannot send a bitmap to the printer.

Some printers have native support for barcodes and you use a printer code to
get it to print a barcode. I'm pretty sure this is the case with Zebra
printers.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi,
I found this code that can solve a problem I have. It sends print direct
to
printer.

Imports System
Imports System.Text
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential)> _
Public Structure DOCINFO<MarshalAs(UnmanagedType.LPWStr)>
Public pDocName As String<MarshalAs(UnmanagedType.LPWStr)>
Public pOutputFile As String<MarshalAs(UnmanagedType.LPWStr)>
Public pDataType As String
End Structure 'DOCINFO

Public Class PrintDirect

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
False, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(pPrinterName As String, ByRef phPrinter
As IntPtr, pDefault As Integer) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
False, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function StartDocPrinter(hPrinter As IntPtr, Level As
Integer,
ByRef pDocInfo As DOCINFO) As Long
<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function StartPagePrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Ansi, ExactSpelling := True,
CallingConvention := CallingConvention.StdCall)> _
Public Shared Function WritePrinter(hPrinter As IntPtr, data As String,
buf
As Integer, ByRef pcWritten As Integer) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function EndPagePrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function EndDocPrinter(hPrinter As IntPtr) As Long

<DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(hPrinter As IntPtr) As Long
End Class 'PrintDirect

Public Class App

Public Shared Sub Main()
Dim lhPrinter As New System.IntPtr()

Dim di As New DOCINFO()
Dim pcWritten As Integer = 0
Dim st1 As String
' text to print with a form feed character
st1 = "This is an example of printing directly to a printer" +
ControlChars.FormFeed
di.pDocName = "my test document"
di.pDataType = "RAW"
' the \x1b means an ascii escape character
st1 = ChrW(27) + "*c600a6b0P" + ControlChars.FormFeed
'lhPrinter contains the handle for the printer opened
'If lhPrinter is 0 then an error has occured
PrintDirect.OpenPrinter("\\192.168.1.101\hpl", lhPrinter, 0)
PrintDirect.StartDocPrinter(lhPrinter, 1, di)
PrintDirect.StartPagePrinter(lhPrinter)
Try
' Moves the cursor 900 dots (3 inches at 300 dpi) in from the left margin,
and
' 600 dots (2 inches at 300 dpi) down from the top margin.
st1 = ChrW(27) + "*p900x600Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Using the print model commands for rectangle dimensions, "600a"
specifies
a rectangle
' with a horizontal size or width of 600 dots, and "6b" specifies a
vertical
' size or height of 6 dots. The 0P selects the solid black rectangular
area
fill.
st1 = ChrW(27) + "*c600a6b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with width of 6 dots, height of 600 dots, and a
' fill pattern of solid black.
st1 = ChrW(27) + "*c6a600b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Moves the current cursor position to 900 dots, from the left margin and
' 1200 dots down from the top margin.
st1 = ChrW(27) + "*p900x1200Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with a width of 606 dots, a height of 6 dots and a
// fill pattern of solid black.
st1 = ChrW(27) + "*c606a6b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Moves the current cursor position to 1500 dots from the left margin and
' 600 dots down from the top margin.
st1 = ChrW(27) + "*p1500x600Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
' Specifies a rectangle with a width of 6 dots, a height of 600 dots and a
' fill pattern of solid black.
st1 = ChrW(27) + "*c6a600b0P"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten) ' Send a
form feed character to the printer
st1 = ControlChars.FormFeed
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
PrintDirect.EndPagePrinter(lhPrinter)
PrintDirect.EndDocPrinter(lhPrinter)
PrintDirect.ClosePrinter(lhPrinter)
End Sub 'Main
End Class 'App
It works fine. I now wanted to include a barcode so I added the foll code
between the "TRY" "CATCH"

Dim pbox As New PictureBox
Dim NewBarcode As IDAutomation.Windows.Forms.LinearBarCode.Barcode
=
New Barcode
NewBarcode.Size = New System.Drawing.Size(148, 64)
NewBarcode.Location = New System.Drawing.Point(176, 7)
NewBarcode.Name = "NewBarcode"
NewBarcode.DataToEncode = "999928829"
NewBarcode.RefreshImage()
pbox.Image = NewBarcode.Picture

st1 = pbox.ToString
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)

st1 = ChrW(27) + "*p50x400Y"
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)

but that didn't work. The barcode dll was downloaded from
http://www.idautomation.com/formscon...rolManual.html

I get the license prompt when I run my program but where the barcode
should
be on the page have "System.Windows.Forms.PictureBox, SizeMode: Normal"

I guess there is a problem converting the barcode o string. How can I fix
this?

Thanks


Jul 21 '05 #3
You need to use the System.Drawing.Printing class in order to print your
document using the print driver

http://msdn.microsoft.com/library/de...ngPrinting.asp

On the bottom of that page, there is a long set of "related links". Three
of them are to code examples, in VB, for printing.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
Hi,
Where can I find code on using the driver instead? I want to print
invoices
with a barcode on them. The invoice data will be pulled from database and
sent to printer.

Thanks

"Nick Malik [Microsoft]" wrote:
The code that you are using goes around the driver. The driver is what
converts bitmaps to printer codes. Therefore, if you go around the
driver,
you cannot send a bitmap to the printer.

Some printers have native support for barcodes and you use a printer code
to
get it to print a barcode. I'm pretty sure this is the case with Zebra
printers.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
> Hi,
> I found this code that can solve a problem I have. It sends print
> direct
> to
> printer.
>
> Imports System
> Imports System.Text
> Imports System.Runtime.InteropServices
>
> <StructLayout(LayoutKind.Sequential)> _
> Public Structure DOCINFO<MarshalAs(UnmanagedType.LPWStr)>
> Public pDocName As String<MarshalAs(UnmanagedType.LPWStr)>
> Public pOutputFile As String<MarshalAs(UnmanagedType.LPWStr)>
> Public pDataType As String
> End Structure 'DOCINFO
>
> Public Class PrintDirect
>
> <DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
> False, CallingConvention := CallingConvention.StdCall)> _
> Public Shared Function OpenPrinter(pPrinterName As String, ByRef
> phPrinter
> As IntPtr, pDefault As Integer) As Long
>
> <DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
> False, CallingConvention := CallingConvention.StdCall)> _
> Public Shared Function StartDocPrinter(hPrinter As IntPtr, Level As
> Integer,
> ByRef pDocInfo As DOCINFO) As Long
>
>
> <DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
> True, CallingConvention := CallingConvention.StdCall)> _
> Public Shared Function StartPagePrinter(hPrinter As IntPtr) As Long
>
> <DllImport("winspool.drv", CharSet := CharSet.Ansi, ExactSpelling :=
> True,
> CallingConvention := CallingConvention.StdCall)> _
> Public Shared Function WritePrinter(hPrinter As IntPtr, data As String,
> buf
> As Integer, ByRef pcWritten As Integer) As Long
>
> <DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
> True, CallingConvention := CallingConvention.StdCall)> _
> Public Shared Function EndPagePrinter(hPrinter As IntPtr) As Long
>
> <DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
> True, CallingConvention := CallingConvention.StdCall)> _
> Public Shared Function EndDocPrinter(hPrinter As IntPtr) As Long
>
> <DllImport("winspool.drv", CharSet := CharSet.Unicode, ExactSpelling :=
> True, CallingConvention := CallingConvention.StdCall)> _
> Public Shared Function ClosePrinter(hPrinter As IntPtr) As Long
> End Class 'PrintDirect
>
> Public Class App
>
> Public Shared Sub Main()
> Dim lhPrinter As New System.IntPtr()
>
> Dim di As New DOCINFO()
> Dim pcWritten As Integer = 0
> Dim st1 As String
> ' text to print with a form feed character
> st1 = "This is an example of printing directly to a printer" +
> ControlChars.FormFeed
> di.pDocName = "my test document"
> di.pDataType = "RAW"
> ' the \x1b means an ascii escape character
> st1 = ChrW(27) + "*c600a6b0P" + ControlChars.FormFeed
> 'lhPrinter contains the handle for the printer opened
> 'If lhPrinter is 0 then an error has occured
> PrintDirect.OpenPrinter("\\192.168.1.101\hpl", lhPrinter, 0)
> PrintDirect.StartDocPrinter(lhPrinter, 1, di)
> PrintDirect.StartPagePrinter(lhPrinter)
> Try
> ' Moves the cursor 900 dots (3 inches at 300 dpi) in from the left
> margin,
> and
> ' 600 dots (2 inches at 300 dpi) down from the top margin.
> st1 = ChrW(27) + "*p900x600Y"
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
> ' Using the print model commands for rectangle dimensions, "600a"
> specifies
> a rectangle
> ' with a horizontal size or width of 600 dots, and "6b" specifies a
> vertical
> ' size or height of 6 dots. The 0P selects the solid black rectangular
> area
> fill.
> st1 = ChrW(27) + "*c600a6b0P"
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
> ' Specifies a rectangle with width of 6 dots, height of 600 dots, and a
> ' fill pattern of solid black.
> st1 = ChrW(27) + "*c6a600b0P"
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
> ' Moves the current cursor position to 900 dots, from the left margin
> and
> ' 1200 dots down from the top margin.
> st1 = ChrW(27) + "*p900x1200Y"
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
> ' Specifies a rectangle with a width of 606 dots, a height of 6 dots
> and a
> // fill pattern of solid black.
> st1 = ChrW(27) + "*c606a6b0P"
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
> ' Moves the current cursor position to 1500 dots from the left margin
> and
> ' 600 dots down from the top margin.
> st1 = ChrW(27) + "*p1500x600Y"
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
> ' Specifies a rectangle with a width of 6 dots, a height of 600 dots
> and a
> ' fill pattern of solid black.
> st1 = ChrW(27) + "*c6a600b0P"
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten) ' Send
> a
> form feed character to the printer
> st1 = ControlChars.FormFeed
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, pcWritten)
> Catch e As Exception
> Console.WriteLine(e.Message)
> End Try
> PrintDirect.EndPagePrinter(lhPrinter)
> PrintDirect.EndDocPrinter(lhPrinter)
> PrintDirect.ClosePrinter(lhPrinter)
> End Sub 'Main
> End Class 'App
>
>
> It works fine. I now wanted to include a barcode so I added the foll
> code
> between the "TRY" "CATCH"
>
>
>
> Dim pbox As New PictureBox
> Dim NewBarcode As
> IDAutomation.Windows.Forms.LinearBarCode.Barcode
> =
> New Barcode
> NewBarcode.Size = New System.Drawing.Size(148, 64)
> NewBarcode.Location = New System.Drawing.Point(176, 7)
> NewBarcode.Name = "NewBarcode"
> NewBarcode.DataToEncode = "999928829"
> NewBarcode.RefreshImage()
> pbox.Image = NewBarcode.Picture
>
> st1 = pbox.ToString
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length,
> pcWritten)
>
> st1 = ChrW(27) + "*p50x400Y"
> PrintDirect.WritePrinter(lhPrinter, st1, st1.Length,
> pcWritten)
>
> but that didn't work. The barcode dll was downloaded from
> http://www.idautomation.com/formscon...rolManual.html
>
> I get the license prompt when I run my program but where the barcode
> should
> be on the page have "System.Windows.Forms.PictureBox, SizeMode: Normal"
>
> I guess there is a problem converting the barcode o string. How can I
> fix
> this?
>
> Thanks
>
>


Jul 21 '05 #4
PictureBox.ToString() returns "System.Windows.Forms.PictureBox,
SizeMode: Normal"

You can extend PictureBox so that it draws itself:

[Serializable]
public class PictureBox : System.Windows.Forms.PictureBox,
IPrintElement
{
...

public bool Draw(IPrintEngine pe,
float xPos,
float yPos,
Graphics g,
RectangleF pageRect)
{
Bitmap myBitmap = new Bitmap(this.Image);

RectangleF destRectangle = new RectangleF(new
PointF(xPos+this.horizontalMargin,
yPos+this.verticalMargin),
this.Size);

g.DrawImage(myBitmap,destRectangle);

return false;
}
Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
5
by: John Flynn | last post by:
hi all i'm going to be quick i have an assignment due which i have no idea how to do. i work full time so i dont have the time to learn it and its due date has crept up on me .. As follows:...
34
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.