473,782 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "InvalidPrinter Exception was unhandled" error. The
error happens in the third line below. The details of the error are below
my signature. Help?

PrintDialog1.Pr interSettings.P rinterName = sLabelPrinterDe viceName

PrintDialog1.Do cument = PrintDocument1

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

Any ideas?

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

System.Drawing. Printing.Invali dPrinterExcepti on was unhandled
Message="Settin gs to access printer 'Samsung ML-2250 Series (Copy 1)' are
not valid."
Source="System. Drawing"
StackTrace:
at System.Drawing. Printing.Printe rSettings.GetHd evmodeInternal( )
at System.Drawing. Printing.Printe rSettings.GetHd evmode(PageSett ings
pageSettings)
at System.Drawing. Printing.PrintC ontroller.OnSta rtPrint(PrintDo cument
document, PrintEventArgs e)
at
System.Windows. Forms.PrintCont rollerWithStatu sDialog.OnStart Print(PrintDocu ment
document, PrintEventArgs e)
at System.Drawing. Printing.PrintC ontroller.Print (PrintDocument
document)
at System.Drawing. Printing.PrintD ocument.Print()
at TCMaxLabelMaker .frmMain.cmdPri ntSequence_Clic k(Object sender,
EventArgs e) in C:\VS2005\Copy (15) of
TCMaxLabelMaker \TCMaxLabelMake r\frmMain.vb:li ne 4932
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at TCMaxLabelMaker .My.MyApplicati on.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean checkAptModel)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt, String[] activationCusto mData)
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
May 21 '06 #1
8 2409
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 "InvalidPrinter Exception was unhandled" error. The
error happens in the third line below. The details of the error are below
my signature. Help?

PrintDialog1.Pr interSettings.P rinterName = sLabelPrinterDe viceName

PrintDialog1.Do cument = PrintDocument1

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

Any ideas?

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

System.Drawing. Printing.Invali dPrinterExcepti on was unhandled
Message="Settin gs to access printer 'Samsung ML-2250 Series (Copy 1)' are
not valid."
Source="System. Drawing"
StackTrace:
at System.Drawing. Printing.Printe rSettings.GetHd evmodeInternal( )
at System.Drawing. Printing.Printe rSettings.GetHd evmode(PageSett ings
pageSettings)
at System.Drawing. Printing.PrintC ontroller.OnSta rtPrint(PrintDo cument
document, PrintEventArgs e)
at
System.Windows. Forms.PrintCont rollerWithStatu sDialog.OnStart Print(PrintDocu ment
document, PrintEventArgs e)
at System.Drawing. Printing.PrintC ontroller.Print (PrintDocument
document)
at System.Drawing. Printing.PrintD ocument.Print()
at TCMaxLabelMaker .frmMain.cmdPri ntSequence_Clic k(Object sender,
EventArgs e) in C:\VS2005\Copy (15) of
TCMaxLabelMaker \TCMaxLabelMake r\frmMain.vb:li ne 4932
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at TCMaxLabelMaker .My.MyApplicati on.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean checkAptModel)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt, String[] activationCusto mData)
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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(txtFontSiz e.Text),
FontStyle.Regul ar, GraphicsUnit.Po int)

Dim TextWidth As Single

Dim TextHeight As Single

Dim AdjustedBarcode Scale 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).Valu e)

For iJ = 1 To iCopies

AdjustedBarcode Scale = BarcodeScale

BarcodeProfessi onal1.Code = tdbLabels.Colum ns(0).Text.ToSt ring

Dim BarcodeImage As Image = BarcodeProfessi onal1.GetBarcod eImage()

Dim realBarcodeWidt h As Integer = BarcodeImage.Wi dth * BarcodeScale ' -
BarcodeProfessi onal1.QuietZone Width * 2

Dim realBarcodeHeig ht As Integer = BarcodeImage.He ight * BarcodeScale

If realBarcodeWidt h > (dLabelWidth - dLabelWidth * 0.1) Then

Dim MakeSmaller As Single

MakeSmaller = (dLabelWidth - dLabelWidth * 0.1) / BarcodeImage.Wi dth

AdjustedBarcode Scale = BarcodeScale * MakeSmaller

realBarcodeWidt h = BarcodeImage.Wi dth * AdjustedBarcode Scale

realBarcodeHeig ht = BarcodeImage.He ight * AdjustedBarcode Scale

End If

lCol = lCol + 1

iCurrent = iI

If lCol > lColumns - 1 Then

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

iY = iY + dDistanceBetwee nRows + dBarcodeHeight

lRow = lRow + 1

lCol = 0

Else

iX = dLeftMargin + dLabelWidth / 2 - realBarcodeWidt h / 2 + lCol *
(dDistanceBetwe enColumns + dLabelWidth)

End If

If lRow > lRows Then

e.HasMorePages = True

Exit For

Else

e.HasMorePages = False

End If

Dim StringSizeTop As SizeF =
e.Graphics.Meas ureString(txtMe ssage.Text.ToSt ring, font)

TextWidth = StringSizeTop.W idth

TextHeight = StringSizeTop.H eight

e.Graphics.Draw String(txtMessa ge.Text.ToStrin g, font, Brushes.Black, New
PointF(dLeftMar gin + dLabelWidth / 2 - TextWidth / 2 + lCol *
(dDistanceBetwe enColumns + dLabelWidth), iY - TextHeight))

sTemp.Remove(0, sTemp.Length)

sTemp.Append(td bLabels.Columns (0).Text.ToStri ng & " " &
tdbLabels.Colum ns(1).Text.ToSt ring)

Dim StringSizeBotto m As SizeF = e.Graphics.Meas ureString(sTemp .ToString,
font)

TextWidth = StringSizeBotto m.Width

TextHeight = StringSizeBotto m.Height

e.Graphics.Draw String(sTemp.To String, font, Brushes.Black, New
PointF(dLeftMar gin + dLabelWidth / 2 - TextWidth / 2 + lCol *
(dDistanceBetwe enColumns + dLabelWidth), iY + realBarcodeHeig ht))

BarcodeProfessi onal1.DrawOnCan vas(e.Graphics, New PointF(iX, iY),
AdjustedBarcode Scale) ' 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.PrintP ageEventArgs) Handles PrintDocument2. PrintPage

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

If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked Then

PrintDocument2. DefaultPageSett ings.Landscape = False

Else

PrintDocument2. DefaultPageSett ings.Landscape = True

End If

PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName ' I set
this to the printer name very early in the program

PrintDialog2.Do cument = PrintDocument2

PrintDialog2.Do cument.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.PrintP ageEventArgs) Handles PrintDocument2. PrintPage

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

If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked Then

PrintDocument2. DefaultPageSett ings.Landscape = False

Else

PrintDocument2. DefaultPageSett ings.Landscape = True

End If

PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName ' I set
this to the printer name very early in the program

PrintDialog2.Do cument = PrintDocument2

PrintDialog2.Do cument.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.EventArg s) Handles cmdPrint.Click

lCol = 0

lRow = 0

MyFlags.Printin gEmployees = False

MyFlags.Printin gTools = True

iStart = 0

iCurrent = 0

iEnd = CInt(tdbLabels. RowCount - 1)

If iStart > iEnd Then

MsgBox(MyLabels .IncorrectSeque nce, MsgBoxStyle.Inf ormation, "Sequence
incorrect")

Exit Sub

End If

iCopies = 1

BarcodeProfessi onal1.AutoSize = True

Select Case cmbBarcodeStyle .SelectedIndex

Case Is = 0

BarcodeProfessi onal1.Symbology = Symbology.Code3 9

BarcodeScale = 1

Case Is = 1

BarcodeProfessi onal1.Symbology = Symbology.Code9 3

BarcodeScale = 1

Case Is = 2

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.Auto

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 3

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C12X36

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 4

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C16X36

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 5

BarcodeProfessi onal1.Symbology = Symbology.Code1 28

BarcodeScale = 1

Case Is = 6

BarcodeProfessi onal1.Symbology = Symbology.Inter leaved2of5

BarcodeScale = 1

Case Is = 7

BarcodeProfessi onal1.Symbology = Symbology.Pdf41 7

BarcodeScale = 1

End Select

BarcodeProfessi onal1.DataMatri xModuleSize = 4 ' CInt(txtCellSiz e.Text) - 10

dBarcodeHeight = CSng(cZero((txt BarcodeHeight.T ext) * 100))

dBarcodeWidth = CSng(cZero(txtB arcodeWidth.Tex t) * 100)

BarcodeProfessi onal1.BarHeight = dBarcodeHeight

BarcodeProfessi onal1.DisplayCo de = False

dLabelHeight = CSng(txtBarcode Height.Text) * 100

dLabelWidth = CSng(txtLabelWi dth.Text) * 100

lColumns = CInt(txtNumberO fColumns.Text)

lRows = CInt(txtNumberO fRows.Text)

dLeftMargin = CSng(txtLeftMar gin.Text) * 100

dTopMargin = CSng(txtTopMarg in.Text) * 100

dDistanceBetwee nRows = CSng(txtRowDist ance.Text) * 100

dDistanceBetwee nColumns = CSng(txtColumnD istance.Text) * 100

If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked Then

PrintDocument2. DefaultPageSett ings.Landscape = False

Else

PrintDocument2. DefaultPageSett ings.Landscape = True

End If

PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName

PrintDialog2.Do cument = PrintDocument2

PrintDialog2.Do cument.Print()

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

"Ken Tucker [MVP]" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:40******** *************** ***********@mic rosoft.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.PrintP ageEventArgs) Handles
PrintDocument2. PrintPage

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

If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
Then

PrintDocument2. DefaultPageSett ings.Landscape = False

Else

PrintDocument2. DefaultPageSett ings.Landscape = True

End If

PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName ' I
set
this to the printer name very early in the program

PrintDialog2.Do cument = PrintDocument2

PrintDialog2.Do cument.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.Do cument.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.EventArg s) Handles cmdPrint.Click

lCol = 0

lRow = 0

MyFlags.Printin gEmployees = False

MyFlags.Printin gTools = True

iStart = 0

iCurrent = 0

iEnd = CInt(tdbLabels. RowCount - 1)

If iStart > iEnd Then

MsgBox(MyLabels .IncorrectSeque nce, MsgBoxStyle.Inf ormation, "Sequence
incorrect")

Exit Sub

End If

iCopies = 1

BarcodeProfessi onal1.AutoSize = True

Select Case cmbBarcodeStyle .SelectedIndex

Case Is = 0

BarcodeProfessi onal1.Symbology = Symbology.Code3 9

BarcodeScale = 1

Case Is = 1

BarcodeProfessi onal1.Symbology = Symbology.Code9 3

BarcodeScale = 1

Case Is = 2

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.Auto

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 3

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C12X36

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 4

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C16X36

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 5

BarcodeProfessi onal1.Symbology = Symbology.Code1 28

BarcodeScale = 1

Case Is = 6

BarcodeProfessi onal1.Symbology = Symbology.Inter leaved2of5

BarcodeScale = 1

Case Is = 7

BarcodeProfessi onal1.Symbology = Symbology.Pdf41 7

BarcodeScale = 1

End Select

BarcodeProfessi onal1.DataMatri xModuleSize = 4 ' CInt(txtCellSiz e.Text) - 10

dBarcodeHeight = CSng(cZero((txt BarcodeHeight.T ext) * 100))

dBarcodeWidth = CSng(cZero(txtB arcodeWidth.Tex t) * 100)

BarcodeProfessi onal1.BarHeight = dBarcodeHeight

BarcodeProfessi onal1.DisplayCo de = False

dLabelHeight = CSng(txtBarcode Height.Text) * 100

dLabelWidth = CSng(txtLabelWi dth.Text) * 100

lColumns = CInt(txtNumberO fColumns.Text)

lRows = CInt(txtNumberO fRows.Text)

dLeftMargin = CSng(txtLeftMar gin.Text) * 100

dTopMargin = CSng(txtTopMarg in.Text) * 100

dDistanceBetwee nRows = CSng(txtRowDist ance.Text) * 100

dDistanceBetwee nColumns = CSng(txtColumnD istance.Text) * 100

If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked Then

PrintDocument2. DefaultPageSett ings.Landscape = False

Else

PrintDocument2. DefaultPageSett ings.Landscape = True

End If

PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName

PrintDialog2.Do cument = PrintDocument2

PrintDialog2.Do cument.Print()

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

"Ken Tucker [MVP]" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:40******** *************** ***********@mic rosoft.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.PrintP ageEventArgs) Handles
PrintDocument2. PrintPage

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

If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
Then

PrintDocument2. DefaultPageSett ings.Landscape = False

Else

PrintDocument2. DefaultPageSett ings.Landscape = True

End If

PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName ' I
set
this to the printer name very early in the program

PrintDialog2.Do cument = PrintDocument2

PrintDialog2.Do cument.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
"InvalidPrinter Exception 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**@soaringsof tware.com

"Ken Tucker [MVP]" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
Rick,

Instead of PrintDialog2.Do cument.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.EventArg s) Handles cmdPrint.Click

lCol = 0

lRow = 0

MyFlags.Printin gEmployees = False

MyFlags.Printin gTools = True

iStart = 0

iCurrent = 0

iEnd = CInt(tdbLabels. RowCount - 1)

If iStart > iEnd Then

MsgBox(MyLabels .IncorrectSeque nce, MsgBoxStyle.Inf ormation, "Sequence
incorrect")

Exit Sub

End If

iCopies = 1

BarcodeProfessi onal1.AutoSize = True

Select Case cmbBarcodeStyle .SelectedIndex

Case Is = 0

BarcodeProfessi onal1.Symbology = Symbology.Code3 9

BarcodeScale = 1

Case Is = 1

BarcodeProfessi onal1.Symbology = Symbology.Code9 3

BarcodeScale = 1

Case Is = 2

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.Auto

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 3

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C12X36

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 4

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C16X36

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 5

BarcodeProfessi onal1.Symbology = Symbology.Code1 28

BarcodeScale = 1

Case Is = 6

BarcodeProfessi onal1.Symbology = Symbology.Inter leaved2of5

BarcodeScale = 1

Case Is = 7

BarcodeProfessi onal1.Symbology = Symbology.Pdf41 7

BarcodeScale = 1

End Select

BarcodeProfessi onal1.DataMatri xModuleSize = 4 ' CInt(txtCellSiz e.Text) -
10

dBarcodeHeight = CSng(cZero((txt BarcodeHeight.T ext) * 100))

dBarcodeWidth = CSng(cZero(txtB arcodeWidth.Tex t) * 100)

BarcodeProfessi onal1.BarHeight = dBarcodeHeight

BarcodeProfessi onal1.DisplayCo de = False

dLabelHeight = CSng(txtBarcode Height.Text) * 100

dLabelWidth = CSng(txtLabelWi dth.Text) * 100

lColumns = CInt(txtNumberO fColumns.Text)

lRows = CInt(txtNumberO fRows.Text)

dLeftMargin = CSng(txtLeftMar gin.Text) * 100

dTopMargin = CSng(txtTopMarg in.Text) * 100

dDistanceBetwee nRows = CSng(txtRowDist ance.Text) * 100

dDistanceBetwee nColumns = CSng(txtColumnD istance.Text) * 100

If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
Then

PrintDocument2. DefaultPageSett ings.Landscape = False

Else

PrintDocument2. DefaultPageSett ings.Landscape = True

End If

PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName

PrintDialog2.Do cument = PrintDocument2

PrintDialog2.Do cument.Print()

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

"Ken Tucker [MVP]" <Ke**********@d iscussions.micr osoft.com> wrote in
message
news:40******** *************** ***********@mic rosoft.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.PrintP ageEventArgs) Handles
>> PrintDocument2. PrintPage
>>
>>
>>
>> Here is the code that I use in the Button_Click event (the end of the
>> code
>> anyway)
>>
>> If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
>> Then
>>
>> PrintDocument2. DefaultPageSett ings.Landscape = False
>>
>> Else
>>
>> PrintDocument2. DefaultPageSett ings.Landscape = True
>>
>> End If
>>
>> PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName '
>> I
>> set
>> this to the printer name very early in the program
>>
>> PrintDialog2.Do cument = PrintDocument2
>>
>> PrintDialog2.Do cument.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.Pr interSettings.I sValid = True Then

PrintDialog2.Do cument.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**@soaringsof tware.com

"Ken Tucker [MVP]" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
Rick,

Instead of PrintDialog2.Do cument.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.EventArg s) Handles cmdPrint.Click

lCol = 0

lRow = 0

MyFlags.Printin gEmployees = False

MyFlags.Printin gTools = True

iStart = 0

iCurrent = 0

iEnd = CInt(tdbLabels. RowCount - 1)

If iStart > iEnd Then

MsgBox(MyLabels .IncorrectSeque nce, MsgBoxStyle.Inf ormation, "Sequence
incorrect")

Exit Sub

End If

iCopies = 1

BarcodeProfessi onal1.AutoSize = True

Select Case cmbBarcodeStyle .SelectedIndex

Case Is = 0

BarcodeProfessi onal1.Symbology = Symbology.Code3 9

BarcodeScale = 1

Case Is = 1

BarcodeProfessi onal1.Symbology = Symbology.Code9 3

BarcodeScale = 1

Case Is = 2

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.Auto

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 3

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C12X36

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 4

BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C16X36

BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

Case Is = 5

BarcodeProfessi onal1.Symbology = Symbology.Code1 28

BarcodeScale = 1

Case Is = 6

BarcodeProfessi onal1.Symbology = Symbology.Inter leaved2of5

BarcodeScale = 1

Case Is = 7

BarcodeProfessi onal1.Symbology = Symbology.Pdf41 7

BarcodeScale = 1

End Select

BarcodeProfessi onal1.DataMatri xModuleSize = 4 ' CInt(txtCellSiz e.Text) -
10

dBarcodeHeight = CSng(cZero((txt BarcodeHeight.T ext) * 100))

dBarcodeWidth = CSng(cZero(txtB arcodeWidth.Tex t) * 100)

BarcodeProfessi onal1.BarHeight = dBarcodeHeight

BarcodeProfessi onal1.DisplayCo de = False

dLabelHeight = CSng(txtBarcode Height.Text) * 100

dLabelWidth = CSng(txtLabelWi dth.Text) * 100

lColumns = CInt(txtNumberO fColumns.Text)

lRows = CInt(txtNumberO fRows.Text)

dLeftMargin = CSng(txtLeftMar gin.Text) * 100

dTopMargin = CSng(txtTopMarg in.Text) * 100

dDistanceBetwee nRows = CSng(txtRowDist ance.Text) * 100

dDistanceBetwee nColumns = CSng(txtColumnD istance.Text) * 100

If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
Then

PrintDocument2. DefaultPageSett ings.Landscape = False

Else

PrintDocument2. DefaultPageSett ings.Landscape = True

End If

PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName

PrintDialog2.Do cument = PrintDocument2

PrintDialog2.Do cument.Print()

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

"Ken Tucker [MVP]" <Ke**********@d iscussions.micr osoft.com> wrote in
message
news:40******** *************** ***********@mic rosoft.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.PrintP ageEventArgs) Handles
>> PrintDocument2. PrintPage
>>
>>
>>
>> Here is the code that I use in the Button_Click event (the end of the
>> code
>> anyway)
>>
>> If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
>> Then
>>
>> PrintDocument2. DefaultPageSett ings.Landscape = False
>>
>> Else
>>
>> PrintDocument2. DefaultPageSett ings.Landscape = True
>>
>> End If
>>
>> PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName '
>> I
>> set
>> this to the printer name very early in the program
>>
>> PrintDialog2.Do cument = PrintDocument2
>>
>> PrintDialog2.Do cument.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
2163
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 really stuck here (probably the ol' Not seeing the tree cause of the forest thingy). But I just can not get this to work. The following is my Test example code. Just needs a Button1 on a blank Form. Add in PrintDocument1, PrintPreviewDialog1,...
5
2227
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 "compile the questions" into a theoretical problem to see what people think should be done to solve it. Maybe it will be a worthwhile discussion, but more importantly maybe it will find out the very best way to sort this kind of problem out so that...
4
9352
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 this differences increases with the increase number of labels. The code is as follwods: Here rdr = OleDbDataReader Font is Times New Roman, 12pt
6
482
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 trouble getting it to print on multiple pages. The second page will not print at all. Thanks in advance
2
2541
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 locations. But After printing first page it increase paper 3cm vertically/Height so on second
0
1130
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 locations. But After printing first page it increase paper 3cm vertically/Height so on second
8
5912
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 clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
10
2116
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 MyThread ( threading.Thread ): def run ( self ): myLongCommand()...
18
11316
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 classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I move the page to the web server, I get the error "Settings to access printer...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.