471,089 Members | 1,682 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 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 2207
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Mark Preston | last post: by
4 posts views Thread by Arif | last post: by
6 posts views Thread by Bill | last post: by
2 posts views Thread by Sukh | last post: by
reply views Thread by Sukh | last post: by
10 posts views Thread by sophie_newbie | last post: by
18 posts views Thread by Brett | last post: by

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.