473,387 Members | 1,516 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,387 software developers and data experts.

Printing second time fails

I am using a PrintDocument and PrintDialog to print. The first time that I
print it works, but when I try to print a second time without exiting the
entire program I get an "InvalidPrinterException was unhandled" error. The
error happens in the third line below. The details of the error are below
my signature. Help?

PrintDialog1.PrinterSettings.PrinterName = sLabelPrinterDeviceName

PrintDialog1.Document = PrintDocument1

PrintDialog1.Document.Print() ' the error happens in this line

Any ideas?

--
Rick Lederman
Soaring Software Solutions, Inc.
www.soaringsoftware.com
ri**@soaringsoftware.com

System.Drawing.Printing.InvalidPrinterException was unhandled
Message="Settings to access printer 'Samsung ML-2250 Series (Copy 1)' are
not valid."
Source="System.Drawing"
StackTrace:
at System.Drawing.Printing.PrinterSettings.GetHdevmod eInternal()
at System.Drawing.Printing.PrinterSettings.GetHdevmod e(PageSettings
pageSettings)
at System.Drawing.Printing.PrintController.OnStartPri nt(PrintDocument
document, PrintEventArgs e)
at
System.Windows.Forms.PrintControllerWithStatusDial og.OnStartPrint(PrintDocument
document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(Prin tDocument
document)
at System.Drawing.Printing.PrintDocument.Print()
at TCMaxLabelMaker.frmMain.cmdPrintSequence_Click(Obj ect sender,
EventArgs e) in C:\VS2005\Copy (15) of
TCMaxLabelMaker\TCMaxLabelMaker\frmMain.vb:line 4932
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at TCMaxLabelMaker.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
May 21 '06 #1
8 2373
Rick,

I suspect the problem is in the printdocument's print event.
Could you please post the code in that event.

Ken
----------------

"Rick Lederman" wrote:
I am using a PrintDocument and PrintDialog to print. The first time that I
print it works, but when I try to print a second time without exiting the
entire program I get an "InvalidPrinterException was unhandled" error. The
error happens in the third line below. The details of the error are below
my signature. Help?

PrintDialog1.PrinterSettings.PrinterName = sLabelPrinterDeviceName

PrintDialog1.Document = PrintDocument1

PrintDialog1.Document.Print() ' the error happens in this line

Any ideas?

--
Rick Lederman
Soaring Software Solutions, Inc.
www.soaringsoftware.com
ri**@soaringsoftware.com

System.Drawing.Printing.InvalidPrinterException was unhandled
Message="Settings to access printer 'Samsung ML-2250 Series (Copy 1)' are
not valid."
Source="System.Drawing"
StackTrace:
at System.Drawing.Printing.PrinterSettings.GetHdevmod eInternal()
at System.Drawing.Printing.PrinterSettings.GetHdevmod e(PageSettings
pageSettings)
at System.Drawing.Printing.PrintController.OnStartPri nt(PrintDocument
document, PrintEventArgs e)
at
System.Windows.Forms.PrintControllerWithStatusDial og.OnStartPrint(PrintDocument
document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(Prin tDocument
document)
at System.Drawing.Printing.PrintDocument.Print()
at TCMaxLabelMaker.frmMain.cmdPrintSequence_Click(Obj ect sender,
EventArgs e) in C:\VS2005\Copy (15) of
TCMaxLabelMaker\TCMaxLabelMaker\frmMain.vb:line 4932
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at TCMaxLabelMaker.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

May 21 '06 #2
Ken,

Thanks for the help as I am at a loss. Here is the code:
The code looses its format here ... should I post the code some other way?
--
Rick Lederman
Soaring Software Solutions, Inc.

Dim font As New Font("Times New Roman", CSng(txtFontSize.Text),
FontStyle.Regular, GraphicsUnit.Point)

Dim TextWidth As Single

Dim TextHeight As Single

Dim AdjustedBarcodeScale As Single

lCol = -1

lRow = 1

iX = dLeftMargin

iY = dTopMargin

iStart = iCurrent

For iI = iStart To iEnd

tdbLabels.Row = iI

iCopies = CInt(tdbLabels.Columns(2).Value)

For iJ = 1 To iCopies

AdjustedBarcodeScale = BarcodeScale

BarcodeProfessional1.Code = tdbLabels.Columns(0).Text.ToString

Dim BarcodeImage As Image = BarcodeProfessional1.GetBarcodeImage()

Dim realBarcodeWidth As Integer = BarcodeImage.Width * BarcodeScale ' -
BarcodeProfessional1.QuietZoneWidth * 2

Dim realBarcodeHeight As Integer = BarcodeImage.Height * BarcodeScale

If realBarcodeWidth > (dLabelWidth - dLabelWidth * 0.1) Then

Dim MakeSmaller As Single

MakeSmaller = (dLabelWidth - dLabelWidth * 0.1) / BarcodeImage.Width

AdjustedBarcodeScale = BarcodeScale * MakeSmaller

realBarcodeWidth = BarcodeImage.Width * AdjustedBarcodeScale

realBarcodeHeight = BarcodeImage.Height * AdjustedBarcodeScale

End If

lCol = lCol + 1

iCurrent = iI

If lCol > lColumns - 1 Then

iX = dLeftMargin + dLabelWidth / 2 - realBarcodeWidth / 2 ' this does not
work

iY = iY + dDistanceBetweenRows + dBarcodeHeight

lRow = lRow + 1

lCol = 0

Else

iX = dLeftMargin + dLabelWidth / 2 - realBarcodeWidth / 2 + lCol *
(dDistanceBetweenColumns + dLabelWidth)

End If

If lRow > lRows Then

e.HasMorePages = True

Exit For

Else

e.HasMorePages = False

End If

Dim StringSizeTop As SizeF =
e.Graphics.MeasureString(txtMessage.Text.ToString, font)

TextWidth = StringSizeTop.Width

TextHeight = StringSizeTop.Height

e.Graphics.DrawString(txtMessage.Text.ToString, font, Brushes.Black, New
PointF(dLeftMargin + dLabelWidth / 2 - TextWidth / 2 + lCol *
(dDistanceBetweenColumns + dLabelWidth), iY - TextHeight))

sTemp.Remove(0, sTemp.Length)

sTemp.Append(tdbLabels.Columns(0).Text.ToString & " " &
tdbLabels.Columns(1).Text.ToString)

Dim StringSizeBottom As SizeF = e.Graphics.MeasureString(sTemp.ToString,
font)

TextWidth = StringSizeBottom.Width

TextHeight = StringSizeBottom.Height

e.Graphics.DrawString(sTemp.ToString, font, Brushes.Black, New
PointF(dLeftMargin + dLabelWidth / 2 - TextWidth / 2 + lCol *
(dDistanceBetweenColumns + dLabelWidth), iY + realBarcodeHeight))

BarcodeProfessional1.DrawOnCanvas(e.Graphics, New PointF(iX, iY),
AdjustedBarcodeScale) ' this is in inches!

Next iJ

If e.HasMorePages = True Then

Exit For

End If

Next iI
May 21 '06 #3
Ken,

I just took ALL of the code out of the PrintDocument2_PrintPage event and it
feeds a page the first time that it is run and has the error the second
time! So, it must not be the ocde in the PrintPage event?

Private Sub PrintDocument2_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage

Here is the code that I use in the Button_Click event (the end of the code
anyway)

If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked Then

PrintDocument2.DefaultPageSettings.Landscape = False

Else

PrintDocument2.DefaultPageSettings.Landscape = True

End If

PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName ' I set
this to the printer name very early in the program

PrintDialog2.Document = PrintDocument2

PrintDialog2.Document.Print() ' this line works the first time, and errors
the second time. Then I must restart the program.
--
Rick Lederman
Soaring Software Solutions, Inc.
May 21 '06 #4
Rick,

I see you are using a variable iCurrent to keep track of the
record number. I do not see where you reset iCurrent to the begining of the
list when you print the second time.

Ken
-------------------------

"Rick Lederman" wrote:
Ken,

I just took ALL of the code out of the PrintDocument2_PrintPage event and it
feeds a page the first time that it is run and has the error the second
time! So, it must not be the ocde in the PrintPage event?

Private Sub PrintDocument2_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage

Here is the code that I use in the Button_Click event (the end of the code
anyway)

If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked Then

PrintDocument2.DefaultPageSettings.Landscape = False

Else

PrintDocument2.DefaultPageSettings.Landscape = True

End If

PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName ' I set
this to the printer name very early in the program

PrintDialog2.Document = PrintDocument2

PrintDialog2.Document.Print() ' this line works the first time, and errors
the second time. Then I must restart the program.
--
Rick Lederman
Soaring Software Solutions, Inc.

May 21 '06 #5
Ken,

I reset it at the beginning of the CmdPrint_Click event. THat is the button
that I click to do the print job. And, as I said, I deleted all of the code
in the PrintDocument2_PrintPage event and it still fails. Here is all of
the code in the CmdPrint_Click event.

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

lCol = 0

lRow = 0

MyFlags.PrintingEmployees = False

MyFlags.PrintingTools = True

iStart = 0

iCurrent = 0

iEnd = CInt(tdbLabels.RowCount - 1)

If iStart > iEnd Then

MsgBox(MyLabels.IncorrectSequence, MsgBoxStyle.Information, "Sequence
incorrect")

Exit Sub

End If

iCopies = 1

BarcodeProfessional1.AutoSize = True

Select Case cmbBarcodeStyle.SelectedIndex

Case Is = 0

BarcodeProfessional1.Symbology = Symbology.Code39

BarcodeScale = 1

Case Is = 1

BarcodeProfessional1.Symbology = Symbology.Code93

BarcodeScale = 1

Case Is = 2

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.Auto

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 3

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.C12X36

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 4

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.C16X36

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 5

BarcodeProfessional1.Symbology = Symbology.Code128

BarcodeScale = 1

Case Is = 6

BarcodeProfessional1.Symbology = Symbology.Interleaved2of5

BarcodeScale = 1

Case Is = 7

BarcodeProfessional1.Symbology = Symbology.Pdf417

BarcodeScale = 1

End Select

BarcodeProfessional1.DataMatrixModuleSize = 4 ' CInt(txtCellSize.Text) - 10

dBarcodeHeight = CSng(cZero((txtBarcodeHeight.Text) * 100))

dBarcodeWidth = CSng(cZero(txtBarcodeWidth.Text) * 100)

BarcodeProfessional1.BarHeight = dBarcodeHeight

BarcodeProfessional1.DisplayCode = False

dLabelHeight = CSng(txtBarcodeHeight.Text) * 100

dLabelWidth = CSng(txtLabelWidth.Text) * 100

lColumns = CInt(txtNumberOfColumns.Text)

lRows = CInt(txtNumberOfRows.Text)

dLeftMargin = CSng(txtLeftMargin.Text) * 100

dTopMargin = CSng(txtTopMargin.Text) * 100

dDistanceBetweenRows = CSng(txtRowDistance.Text) * 100

dDistanceBetweenColumns = CSng(txtColumnDistance.Text) * 100

If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked Then

PrintDocument2.DefaultPageSettings.Landscape = False

Else

PrintDocument2.DefaultPageSettings.Landscape = True

End If

PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName

PrintDialog2.Document = PrintDocument2

PrintDialog2.Document.Print()

End Sub
--
Rick Lederman
Soaring Software Solutions, Inc.
www.soaringsoftware.com
ri**@soaringsoftware.com

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Rick,

I see you are using a variable iCurrent to keep track of the
record number. I do not see where you reset iCurrent to the begining of
the
list when you print the second time.

Ken
-------------------------

"Rick Lederman" wrote:
Ken,

I just took ALL of the code out of the PrintDocument2_PrintPage event and
it
feeds a page the first time that it is run and has the error the second
time! So, it must not be the ocde in the PrintPage event?

Private Sub PrintDocument2_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument2.PrintPage

Here is the code that I use in the Button_Click event (the end of the
code
anyway)

If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked
Then

PrintDocument2.DefaultPageSettings.Landscape = False

Else

PrintDocument2.DefaultPageSettings.Landscape = True

End If

PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName ' I
set
this to the printer name very early in the program

PrintDialog2.Document = PrintDocument2

PrintDialog2.Document.Print() ' this line works the first time, and
errors
the second time. Then I must restart the program.
--
Rick Lederman
Soaring Software Solutions, Inc.

May 21 '06 #6
Rick,

Instead of PrintDialog2.Document.Print() try printdocument2.print

Ken
--------------------

"Rick Lederman" wrote:
Ken,

I reset it at the beginning of the CmdPrint_Click event. THat is the button
that I click to do the print job. And, as I said, I deleted all of the code
in the PrintDocument2_PrintPage event and it still fails. Here is all of
the code in the CmdPrint_Click event.

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

lCol = 0

lRow = 0

MyFlags.PrintingEmployees = False

MyFlags.PrintingTools = True

iStart = 0

iCurrent = 0

iEnd = CInt(tdbLabels.RowCount - 1)

If iStart > iEnd Then

MsgBox(MyLabels.IncorrectSequence, MsgBoxStyle.Information, "Sequence
incorrect")

Exit Sub

End If

iCopies = 1

BarcodeProfessional1.AutoSize = True

Select Case cmbBarcodeStyle.SelectedIndex

Case Is = 0

BarcodeProfessional1.Symbology = Symbology.Code39

BarcodeScale = 1

Case Is = 1

BarcodeProfessional1.Symbology = Symbology.Code93

BarcodeScale = 1

Case Is = 2

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.Auto

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 3

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.C12X36

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 4

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.C16X36

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 5

BarcodeProfessional1.Symbology = Symbology.Code128

BarcodeScale = 1

Case Is = 6

BarcodeProfessional1.Symbology = Symbology.Interleaved2of5

BarcodeScale = 1

Case Is = 7

BarcodeProfessional1.Symbology = Symbology.Pdf417

BarcodeScale = 1

End Select

BarcodeProfessional1.DataMatrixModuleSize = 4 ' CInt(txtCellSize.Text) - 10

dBarcodeHeight = CSng(cZero((txtBarcodeHeight.Text) * 100))

dBarcodeWidth = CSng(cZero(txtBarcodeWidth.Text) * 100)

BarcodeProfessional1.BarHeight = dBarcodeHeight

BarcodeProfessional1.DisplayCode = False

dLabelHeight = CSng(txtBarcodeHeight.Text) * 100

dLabelWidth = CSng(txtLabelWidth.Text) * 100

lColumns = CInt(txtNumberOfColumns.Text)

lRows = CInt(txtNumberOfRows.Text)

dLeftMargin = CSng(txtLeftMargin.Text) * 100

dTopMargin = CSng(txtTopMargin.Text) * 100

dDistanceBetweenRows = CSng(txtRowDistance.Text) * 100

dDistanceBetweenColumns = CSng(txtColumnDistance.Text) * 100

If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked Then

PrintDocument2.DefaultPageSettings.Landscape = False

Else

PrintDocument2.DefaultPageSettings.Landscape = True

End If

PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName

PrintDialog2.Document = PrintDocument2

PrintDialog2.Document.Print()

End Sub
--
Rick Lederman
Soaring Software Solutions, Inc.
www.soaringsoftware.com
ri**@soaringsoftware.com

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Rick,

I see you are using a variable iCurrent to keep track of the
record number. I do not see where you reset iCurrent to the begining of
the
list when you print the second time.

Ken
-------------------------

"Rick Lederman" wrote:
Ken,

I just took ALL of the code out of the PrintDocument2_PrintPage event and
it
feeds a page the first time that it is run and has the error the second
time! So, it must not be the ocde in the PrintPage event?

Private Sub PrintDocument2_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument2.PrintPage

Here is the code that I use in the Button_Click event (the end of the
code
anyway)

If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked
Then

PrintDocument2.DefaultPageSettings.Landscape = False

Else

PrintDocument2.DefaultPageSettings.Landscape = True

End If

PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName ' I
set
this to the printer name very early in the program

PrintDialog2.Document = PrintDocument2

PrintDialog2.Document.Print() ' this line works the first time, and
errors
the second time. Then I must restart the program.
--
Rick Lederman
Soaring Software Solutions, Inc.


May 21 '06 #7
Again, does not work. That is strange, the first thime that I print it
everything works. Click the print button again and I get the same
"InvalidPrinterException was unhandled" error. Underneigh that it also says
(same as before) " Settings to access printer 'Samsung ML-2250 'are not
valid." ...

--
Rick Lederman
Soaring Software Solutions, Inc.
www.soaringsoftware.com
ri**@soaringsoftware.com

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
Rick,

Instead of PrintDialog2.Document.Print() try printdocument2.print

Ken
--------------------

"Rick Lederman" wrote:
Ken,

I reset it at the beginning of the CmdPrint_Click event. THat is the
button
that I click to do the print job. And, as I said, I deleted all of the
code
in the PrintDocument2_PrintPage event and it still fails. Here is all of
the code in the CmdPrint_Click event.

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

lCol = 0

lRow = 0

MyFlags.PrintingEmployees = False

MyFlags.PrintingTools = True

iStart = 0

iCurrent = 0

iEnd = CInt(tdbLabels.RowCount - 1)

If iStart > iEnd Then

MsgBox(MyLabels.IncorrectSequence, MsgBoxStyle.Information, "Sequence
incorrect")

Exit Sub

End If

iCopies = 1

BarcodeProfessional1.AutoSize = True

Select Case cmbBarcodeStyle.SelectedIndex

Case Is = 0

BarcodeProfessional1.Symbology = Symbology.Code39

BarcodeScale = 1

Case Is = 1

BarcodeProfessional1.Symbology = Symbology.Code93

BarcodeScale = 1

Case Is = 2

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.Auto

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 3

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.C12X36

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 4

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.C16X36

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 5

BarcodeProfessional1.Symbology = Symbology.Code128

BarcodeScale = 1

Case Is = 6

BarcodeProfessional1.Symbology = Symbology.Interleaved2of5

BarcodeScale = 1

Case Is = 7

BarcodeProfessional1.Symbology = Symbology.Pdf417

BarcodeScale = 1

End Select

BarcodeProfessional1.DataMatrixModuleSize = 4 ' CInt(txtCellSize.Text) -
10

dBarcodeHeight = CSng(cZero((txtBarcodeHeight.Text) * 100))

dBarcodeWidth = CSng(cZero(txtBarcodeWidth.Text) * 100)

BarcodeProfessional1.BarHeight = dBarcodeHeight

BarcodeProfessional1.DisplayCode = False

dLabelHeight = CSng(txtBarcodeHeight.Text) * 100

dLabelWidth = CSng(txtLabelWidth.Text) * 100

lColumns = CInt(txtNumberOfColumns.Text)

lRows = CInt(txtNumberOfRows.Text)

dLeftMargin = CSng(txtLeftMargin.Text) * 100

dTopMargin = CSng(txtTopMargin.Text) * 100

dDistanceBetweenRows = CSng(txtRowDistance.Text) * 100

dDistanceBetweenColumns = CSng(txtColumnDistance.Text) * 100

If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked
Then

PrintDocument2.DefaultPageSettings.Landscape = False

Else

PrintDocument2.DefaultPageSettings.Landscape = True

End If

PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName

PrintDialog2.Document = PrintDocument2

PrintDialog2.Document.Print()

End Sub
--
Rick Lederman
Soaring Software Solutions, Inc.
www.soaringsoftware.com
ri**@soaringsoftware.com

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in
message
news:40**********************************@microsof t.com...
> Rick,
>
> I see you are using a variable iCurrent to keep track of the
> record number. I do not see where you reset iCurrent to the begining
> of
> the
> list when you print the second time.
>
> Ken
> -------------------------
>
> "Rick Lederman" wrote:
>
>> Ken,
>>
>> I just took ALL of the code out of the PrintDocument2_PrintPage event
>> and
>> it
>> feeds a page the first time that it is run and has the error the
>> second
>> time! So, it must not be the ocde in the PrintPage event?
>>
>> Private Sub PrintDocument2_PrintPage(ByVal sender As Object, ByVal e
>> As
>> System.Drawing.Printing.PrintPageEventArgs) Handles
>> PrintDocument2.PrintPage
>>
>>
>>
>> Here is the code that I use in the Button_Click event (the end of the
>> code
>> anyway)
>>
>> If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked
>> Then
>>
>> PrintDocument2.DefaultPageSettings.Landscape = False
>>
>> Else
>>
>> PrintDocument2.DefaultPageSettings.Landscape = True
>>
>> End If
>>
>> PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName '
>> I
>> set
>> this to the printer name very early in the program
>>
>> PrintDialog2.Document = PrintDocument2
>>
>> PrintDialog2.Document.Print() ' this line works the first time, and
>> errors
>> the second time. Then I must restart the program.
>>
>>
>> --
>> Rick Lederman
>> Soaring Software Solutions, Inc.
>>
>>
>>


May 21 '06 #8
To test things I put the following into the program

If PrintDialog2.PrinterSettings.IsValid = True Then

PrintDialog2.Document.Print() ' this was already there

End If

And, imagine that the IsValid returns False on the second print job. So the
question remains what makes the PrinterSettings become false after using it
once?

And, during a program run, I set the printer to a different printer, and the
first time that it ran it printed OK, the second time that I tried to print,
IT RETURNED TRUE and ran OK! And it continues to work for the new printer.

So, I change the printer selector back to the original printer. And it
WORKS ... these kinds of problems I really don't need, but for now it is all
WORKING ...

Ken, thanks for your help. I have no idea what was going on within this PC
but simply printing to a different printer then switching back to this
printer seems to have fixed it. The magic of Windows!

--
Rick Lederman
Soaring Software Solutions, Inc.
www.soaringsoftware.com
ri**@soaringsoftware.com

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
Rick,

Instead of PrintDialog2.Document.Print() try printdocument2.print

Ken
--------------------

"Rick Lederman" wrote:
Ken,

I reset it at the beginning of the CmdPrint_Click event. THat is the
button
that I click to do the print job. And, as I said, I deleted all of the
code
in the PrintDocument2_PrintPage event and it still fails. Here is all of
the code in the CmdPrint_Click event.

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

lCol = 0

lRow = 0

MyFlags.PrintingEmployees = False

MyFlags.PrintingTools = True

iStart = 0

iCurrent = 0

iEnd = CInt(tdbLabels.RowCount - 1)

If iStart > iEnd Then

MsgBox(MyLabels.IncorrectSequence, MsgBoxStyle.Information, "Sequence
incorrect")

Exit Sub

End If

iCopies = 1

BarcodeProfessional1.AutoSize = True

Select Case cmbBarcodeStyle.SelectedIndex

Case Is = 0

BarcodeProfessional1.Symbology = Symbology.Code39

BarcodeScale = 1

Case Is = 1

BarcodeProfessional1.Symbology = Symbology.Code93

BarcodeScale = 1

Case Is = 2

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.Auto

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 3

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.C12X36

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 4

BarcodeProfessional1.Symbology = Symbology.DataMatrix

BarcodeProfessional1.DataMatrixFormat = DataMatrixFormat.C16X36

BarcodeScale = CSng(txtCellSize.Text) / 14 * 0.39

Case Is = 5

BarcodeProfessional1.Symbology = Symbology.Code128

BarcodeScale = 1

Case Is = 6

BarcodeProfessional1.Symbology = Symbology.Interleaved2of5

BarcodeScale = 1

Case Is = 7

BarcodeProfessional1.Symbology = Symbology.Pdf417

BarcodeScale = 1

End Select

BarcodeProfessional1.DataMatrixModuleSize = 4 ' CInt(txtCellSize.Text) -
10

dBarcodeHeight = CSng(cZero((txtBarcodeHeight.Text) * 100))

dBarcodeWidth = CSng(cZero(txtBarcodeWidth.Text) * 100)

BarcodeProfessional1.BarHeight = dBarcodeHeight

BarcodeProfessional1.DisplayCode = False

dLabelHeight = CSng(txtBarcodeHeight.Text) * 100

dLabelWidth = CSng(txtLabelWidth.Text) * 100

lColumns = CInt(txtNumberOfColumns.Text)

lRows = CInt(txtNumberOfRows.Text)

dLeftMargin = CSng(txtLeftMargin.Text) * 100

dTopMargin = CSng(txtTopMargin.Text) * 100

dDistanceBetweenRows = CSng(txtRowDistance.Text) * 100

dDistanceBetweenColumns = CSng(txtColumnDistance.Text) * 100

If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked
Then

PrintDocument2.DefaultPageSettings.Landscape = False

Else

PrintDocument2.DefaultPageSettings.Landscape = True

End If

PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName

PrintDialog2.Document = PrintDocument2

PrintDialog2.Document.Print()

End Sub
--
Rick Lederman
Soaring Software Solutions, Inc.
www.soaringsoftware.com
ri**@soaringsoftware.com

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in
message
news:40**********************************@microsof t.com...
> Rick,
>
> I see you are using a variable iCurrent to keep track of the
> record number. I do not see where you reset iCurrent to the begining
> of
> the
> list when you print the second time.
>
> Ken
> -------------------------
>
> "Rick Lederman" wrote:
>
>> Ken,
>>
>> I just took ALL of the code out of the PrintDocument2_PrintPage event
>> and
>> it
>> feeds a page the first time that it is run and has the error the
>> second
>> time! So, it must not be the ocde in the PrintPage event?
>>
>> Private Sub PrintDocument2_PrintPage(ByVal sender As Object, ByVal e
>> As
>> System.Drawing.Printing.PrintPageEventArgs) Handles
>> PrintDocument2.PrintPage
>>
>>
>>
>> Here is the code that I use in the Button_Click event (the end of the
>> code
>> anyway)
>>
>> If chkLandscape.CheckState = System.Windows.Forms.CheckState.Unchecked
>> Then
>>
>> PrintDocument2.DefaultPageSettings.Landscape = False
>>
>> Else
>>
>> PrintDocument2.DefaultPageSettings.Landscape = True
>>
>> End If
>>
>> PrintDialog2.PrinterSettings.PrinterName = sLabelPrinterDeviceName '
>> I
>> set
>> this to the printer name very early in the program
>>
>> PrintDialog2.Document = PrintDocument2
>>
>> PrintDialog2.Document.Print() ' this line works the first time, and
>> errors
>> the second time. Then I must restart the program.
>>
>>
>> --
>> Rick Lederman
>> Soaring Software Solutions, Inc.
>>
>>
>>


May 22 '06 #9

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

Similar topics

5
by: Mr. B | last post by:
This is driving me NUTZ!!! I've been screwing around on this for a week now. And I have tried to find examples similar to what I have (nada). Got lots of streaming a TXT file... bah! I am...
5
by: Mark Preston | last post by:
Admission first - I don't actually have a problem here but have noticed that a lot of people have been asking similar questions and getting very varied answers. What I've done is to sort of...
4
by: Arif | last post by:
I C# code prints very slow as compared to a third party barcode printing software. That software prints approximately 10 labels in 2 seconds while my C# code prints 10 labels in 5 to 6 seconds. And...
6
by: Bill | last post by:
Hi I am trying to get my listbox items to print if they stream past the one page mark. my code is working for one page of information (if the e.hasmorepages) is not there. But I am having...
2
by: Sukh | last post by:
Hi I am stuck with a problem Can anyone help me out from this... I am printing a report on pre-printed continue paper using dot-matrix printer using vb.net. Data is printing on all the...
0
by: Sukh | last post by:
Hi I am stuck with a problem Can anyone help me out from this... I am printing a report on pre-printed continue paper using dot-matrix printer using vb.net. Data is printing on all the...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
10
by: sophie_newbie | last post by:
Hi, I'm trying to write a piece of code that spawns a thread and prints dots every half second until the thread spawned is finished. Code is something like this: import threading class...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.