473,792 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PrintPreview problem

I'm using vb2005.

I wrote a simple app to view and print all the fonts on my pc.To see how the
printout will look without wasting lots of paper, I use PrintPreviewDia log.

The first time I run PrintPreviewDia log, it correctly shows five pages of
printout. If I run it a second time, it only shows three pages, with the
original second page printing over the original first page.
If I run it a third time, only one page shows up, with all the fonts being
printed on that page.

Can anyone see what's wrong. Thanks.
p.s., I'm not sure why when I copy my code all my formatting dissapeared.

'First class
Imports System.Drawing. Printing
Public Class FontDocument
Inherits printdocument
Private m_fontFamilies( ) As FontFamily
Private m_pageNumber As Int32
Private m_offset As Int32
Public Property FontFamilies() As FontFamily()
Get
Return m_fontFamilies
End Get
Set(ByVal value As FontFamily())
m_fontFamilies = value
End Set
End Property
Public Property PageNumber() As Int32
Get
Return m_pageNumber
End Get
Set(ByVal value As Int32)
m_pageNumber = value
End Set
End Property
Public Property Offset() As Int32
Get
Return m_offset
End Get
Set(ByVal value As Int32)
m_offset = value
End Set
End Property
Public Sub FontDocument(By Val fontFamilies() As FontFamily)
Me.m_fontFamili es = fontFamilies
End Sub
End Class

'Second class
Dim PrintDocument1 As FontDocument
Private Sub FontPrinter_Loa d(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
PrintDocument1 = New FontDocument
PrintDocument1. FontFamilies = FontFamily.Fami lies
nudFontSize.Val ue = 10
LoadFontsRichTe xtBox()
End Sub
Private Sub PrintPreviewToo lStripMenuItem_ Click(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
PrintPreviewToo lStripMenuItem. Click
AddHandler PrintDocument1. PrintPage, AddressOf PrintDocument1_ PrintPage
Dim PrintPreviewDia log1 As PrintPreviewDia log = New
System.Windows. Forms.PrintPrev iewDialog
PrintPreviewDia log1.Document = PrintDocument1
PrintDocument1. PageNumber = 0
PrintDocument1. Offset = 0
PrintPreviewDia log1.ShowDialog ()
End Sub
Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object, ByVal ev
As System.Drawing. Printing.PrintP ageEventArgs)
Dim fnt As Font
Dim linesPerPage As Integer = 0
Dim yPos As Integer = ev.MarginBounds .Top
Dim count As Integer = 0
Dim leftMargin As Integer = ev.MarginBounds .Left
Dim topMargin As Integer = ev.MarginBounds .Top
Dim line As String = Nothing
Dim fntFamily As FontFamily
If sender Is Nothing OrElse ev Is Nothing Then
Return
End If
Dim fntDoc As FontDocument = CType(sender, FontDocument)
fntDoc.PageNumb er += 1
While yPos < ev.MarginBounds .Bottom And fntDoc.Offset <
fntDoc.FontFami lies.Length
fntFamily = fntDoc.FontFami lies(fntDoc.Off set)
Try
fnt = New Font(fntFamily, nudFontSize.Val ue, FontStyle.Regul ar)
ev.Graphics.Dra wString(fntFami ly.Name, fnt, Brushes.Black, 150, yPos)
yPos += fnt.Height

If yPos > ev.MarginBounds .Bottom Then
ev.HasMorePages = True
Return
Else
ev.HasMorePages = False
End If
Catch ex As Exception
Finally
fntDoc.Offset += 1
End Try
End While
ev.HasMorePages = False
End Sub
Mar 21 '06 #1
5 1389
Hi Chuck. At first sight, it would seem a good idea to add

yPos = ev.MarginBounds .Top
fntDoc.Offset = 0
fntDoc.PageNumb er = 0

[and any other var needing reset]

after

Dim fntDoc As FontDocument = CType(sender, FontDocument)

(where you could actually use a DirectCast instead of ctype. You migh
want to to place a MsgBox(ex.Messa ge, MsgBoxStyle.Inf ormation) in
the catch clause)....
-tom

Chuck Gantz ha scritto:
I'm using vb2005.

I wrote a simple app to view and print all the fonts on my pc.To see how the
printout will look without wasting lots of paper, I use PrintPreviewDia log.

The first time I run PrintPreviewDia log, it correctly shows five pages of
printout. If I run it a second time, it only shows three pages, with the
original second page printing over the original first page.
If I run it a third time, only one page shows up, with all the fonts being
printed on that page.

Can anyone see what's wrong. Thanks.
p.s., I'm not sure why when I copy my code all my formatting dissapeared.

'First class
Imports System.Drawing. Printing
Public Class FontDocument
Inherits printdocument
Private m_fontFamilies( ) As FontFamily
Private m_pageNumber As Int32
Private m_offset As Int32
Public Property FontFamilies() As FontFamily()
Get
Return m_fontFamilies
End Get
Set(ByVal value As FontFamily())
m_fontFamilies = value
End Set
End Property
Public Property PageNumber() As Int32
Get
Return m_pageNumber
End Get
Set(ByVal value As Int32)
m_pageNumber = value
End Set
End Property
Public Property Offset() As Int32
Get
Return m_offset
End Get
Set(ByVal value As Int32)
m_offset = value
End Set
End Property
Public Sub FontDocument(By Val fontFamilies() As FontFamily)
Me.m_fontFamili es = fontFamilies
End Sub
End Class

'Second class
Dim PrintDocument1 As FontDocument
Private Sub FontPrinter_Loa d(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
PrintDocument1 = New FontDocument
PrintDocument1. FontFamilies = FontFamily.Fami lies
nudFontSize.Val ue = 10
LoadFontsRichTe xtBox()
End Sub
Private Sub PrintPreviewToo lStripMenuItem_ Click(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
PrintPreviewToo lStripMenuItem. Click
AddHandler PrintDocument1. PrintPage, AddressOf PrintDocument1_ PrintPage
Dim PrintPreviewDia log1 As PrintPreviewDia log = New
System.Windows. Forms.PrintPrev iewDialog
PrintPreviewDia log1.Document = PrintDocument1
PrintDocument1. PageNumber = 0
PrintDocument1. Offset = 0
PrintPreviewDia log1.ShowDialog ()
End Sub
Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object, ByVal ev
As System.Drawing. Printing.PrintP ageEventArgs)
Dim fnt As Font
Dim linesPerPage As Integer = 0
Dim yPos As Integer = ev.MarginBounds .Top
Dim count As Integer = 0
Dim leftMargin As Integer = ev.MarginBounds .Left
Dim topMargin As Integer = ev.MarginBounds .Top
Dim line As String = Nothing
Dim fntFamily As FontFamily
If sender Is Nothing OrElse ev Is Nothing Then
Return
End If
Dim fntDoc As FontDocument = CType(sender, FontDocument)
fntDoc.PageNumb er += 1
While yPos < ev.MarginBounds .Bottom And fntDoc.Offset <
fntDoc.FontFami lies.Length
fntFamily = fntDoc.FontFami lies(fntDoc.Off set)
Try
fnt = New Font(fntFamily, nudFontSize.Val ue, FontStyle.Regul ar)
ev.Graphics.Dra wString(fntFami ly.Name, fnt, Brushes.Black, 150, yPos)
yPos += fnt.Height

If yPos > ev.MarginBounds .Bottom Then
ev.HasMorePages = True
Return
Else
ev.HasMorePages = False
End If
Catch ex As Exception
Finally
fntDoc.Offset += 1
End Try
End While
ev.HasMorePages = False
End Sub


Mar 21 '06 #2
Hi Tom,

Thanks for the reply.

The lines
yPos = ev.MarginBounds .Top
fntDoc.Offset = 0
fntDoc.PageNumb er = 0

actually are in the program. (It would be nice if the formatting would have
copied over so that my code could be read a little easier). The offset and
PageNumber variables can't be set in PrintDocument1_ PrintPage since they
change for each line of text and page.

Also, I don't use a messageBox in the catch clause because the code doesn't
reach there for an actual error. Some font families don't have a regular
font style. When that happens the line
fnt = New Font(fntFamily, nudFontSize.Val ue, FontStyle.Regul ar)

throws an exception. The catch clause keeps the program from ending because
of that exception.

Chuck

<to************ **@uniroma1.it> wrote in message
news:11******** *************@j 33g2000cwa.goog legroups.com...
Hi Chuck. At first sight, it would seem a good idea to add

yPos = ev.MarginBounds .Top
fntDoc.Offset = 0
fntDoc.PageNumb er = 0

[and any other var needing reset]

after

Dim fntDoc As FontDocument = CType(sender, FontDocument)

(where you could actually use a DirectCast instead of ctype. You migh
want to to place a MsgBox(ex.Messa ge, MsgBoxStyle.Inf ormation) in
the catch clause)....
-tom

Chuck Gantz ha scritto:
I'm using vb2005.

I wrote a simple app to view and print all the fonts on my pc.To see how
the
printout will look without wasting lots of paper, I use
PrintPreviewDia log.

The first time I run PrintPreviewDia log, it correctly shows five pages of
printout. If I run it a second time, it only shows three pages, with the
original second page printing over the original first page.
If I run it a third time, only one page shows up, with all the fonts
being
printed on that page.

Can anyone see what's wrong. Thanks.
p.s., I'm not sure why when I copy my code all my formatting dissapeared.

'First class
Imports System.Drawing. Printing
Public Class FontDocument
Inherits printdocument
Private m_fontFamilies( ) As FontFamily
Private m_pageNumber As Int32
Private m_offset As Int32
Public Property FontFamilies() As FontFamily()
Get
Return m_fontFamilies
End Get
Set(ByVal value As FontFamily())
m_fontFamilies = value
End Set
End Property
Public Property PageNumber() As Int32
Get
Return m_pageNumber
End Get
Set(ByVal value As Int32)
m_pageNumber = value
End Set
End Property
Public Property Offset() As Int32
Get
Return m_offset
End Get
Set(ByVal value As Int32)
m_offset = value
End Set
End Property
Public Sub FontDocument(By Val fontFamilies() As FontFamily)
Me.m_fontFamili es = fontFamilies
End Sub
End Class

'Second class
Dim PrintDocument1 As FontDocument
Private Sub FontPrinter_Loa d(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
PrintDocument1 = New FontDocument
PrintDocument1. FontFamilies = FontFamily.Fami lies
nudFontSize.Val ue = 10
LoadFontsRichTe xtBox()
End Sub
Private Sub PrintPreviewToo lStripMenuItem_ Click(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
PrintPreviewToo lStripMenuItem. Click
AddHandler PrintDocument1. PrintPage, AddressOf PrintDocument1_ PrintPage
Dim PrintPreviewDia log1 As PrintPreviewDia log = New
System.Windows. Forms.PrintPrev iewDialog
PrintPreviewDia log1.Document = PrintDocument1
PrintDocument1. PageNumber = 0
PrintDocument1. Offset = 0
PrintPreviewDia log1.ShowDialog ()
End Sub
Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object, ByVal
ev
As System.Drawing. Printing.PrintP ageEventArgs)
Dim fnt As Font
Dim linesPerPage As Integer = 0
Dim yPos As Integer = ev.MarginBounds .Top
Dim count As Integer = 0
Dim leftMargin As Integer = ev.MarginBounds .Left
Dim topMargin As Integer = ev.MarginBounds .Top
Dim line As String = Nothing
Dim fntFamily As FontFamily
If sender Is Nothing OrElse ev Is Nothing Then
Return
End If
Dim fntDoc As FontDocument = CType(sender, FontDocument)
fntDoc.PageNumb er += 1
While yPos < ev.MarginBounds .Bottom And fntDoc.Offset <
fntDoc.FontFami lies.Length
fntFamily = fntDoc.FontFami lies(fntDoc.Off set)
Try
fnt = New Font(fntFamily, nudFontSize.Val ue, FontStyle.Regul ar)
ev.Graphics.Dra wString(fntFami ly.Name, fnt, Brushes.Black, 150, yPos)
yPos += fnt.Height

If yPos > ev.MarginBounds .Bottom Then
ev.HasMorePages = True
Return
Else
ev.HasMorePages = False
End If
Catch ex As Exception
Finally
fntDoc.Offset += 1
End Try
End While
ev.HasMorePages = False
End Sub

Mar 21 '06 #3
Yes it's actually uncomfortable to read, but gets better in the editor
:) I have good new. I think I located your problem. You are attacching
multiple handlers ...

Replace this part:

'Second class
Dim PrintDocument1 As FontDocument
Private Sub FontPrinter_Loa d(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
PrintDocument1 = New FontDocument
AddHandler PrintDocument1. PrintPage, AddressOf
PrintDocument1_ PrintPage
PrintDocument1. FontFamilies = FontFamily.Fami lies
nudFontSize.Val ue = 10
LoadFontsRichTe xtBox()
End Sub

Private Sub PrintPreviewToo lStripMenuItem_ Click(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles Button1.Click '
PrintPreviewToo lStripMenuItem. Click
Dim PrintPreviewDia log1 As PrintPreviewDia log = New
System.Windows. Forms.PrintPrev iewDialog
PrintPreviewDia log1.Document = PrintDocument1
PrintDocument1. PageNumber = 0
PrintDocument1. Offset = 0
PrintPreviewDia log1.ShowDialog ()
End Sub

Dim nudFontSize As Single

'nudFontSize.Va lue

Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object,
ByVal ev As System.Drawing. Printing.PrintP ageEventArgs)

Dim fnt As Font
Dim linesPerPage As Integer = 0
Dim yPos As Integer = ev.MarginBounds .Top
Dim count As Integer = 0
Dim leftMargin As Integer = ev.MarginBounds .Left
Dim topMargin As Integer = ev.MarginBounds .Top
Dim line As String = Nothing
Dim fntFamily As FontFamily
Dim fntDoc As FontDocument = DirectCast(send er, FontDocument)
fntDoc.PageNumb er += 1

If fntDoc.FontFami lies.Length = 0 Then ev.Cancel = True

While yPos < ev.MarginBounds .Bottom AndAlso fntDoc.Offset <
fntDoc.FontFami lies.Length - 1

fntFamily = fntDoc.FontFami lies(fntDoc.Off set)
Try
fnt = New Font(fntFamily, nudFontSize.Val ue,
FontStyle.Regul ar)
Catch ex As Exception
'MsgBox(ex.Mess age) I see :)
End Try

ev.Graphics.Dra wString(fntFami ly.Name.Substri ng(0, 2), fnt,
Brushes.Black, 150, yPos)
If yPos > ev.MarginBounds .Bottom Then
ev.HasMorePages = True
Exit Sub
Else
ev.HasMorePages = False
End If
yPos += fnt.Height
fntDoc.Offset += 1

End While
ev.HasMorePages = False

End Sub


Chuck Gantz ha scritto:
Hi Tom,

Thanks for the reply.

The lines
yPos = ev.MarginBounds .Top
fntDoc.Offset = 0
fntDoc.PageNumb er = 0

actually are in the program. (It would be nice if the formatting would have
copied over so that my code could be read a little easier). The offset and
PageNumber variables can't be set in PrintDocument1_ PrintPage since they
change for each line of text and page.

Also, I don't use a messageBox in the catch clause because the code doesn't
reach there for an actual error. Some font families don't have a regular
font style. When that happens the line
fnt = New Font(fntFamily, nudFontSize.Val ue, FontStyle.Regul ar)

throws an exception. The catch clause keeps the program from ending because
of that exception.

Chuck

<to************ **@uniroma1.it> wrote in message
news:11******** *************@j 33g2000cwa.goog legroups.com...
Hi Chuck. At first sight, it would seem a good idea to add

yPos = ev.MarginBounds .Top
fntDoc.Offset = 0
fntDoc.PageNumb er = 0

[and any other var needing reset]

after

Dim fntDoc As FontDocument = CType(sender, FontDocument)

(where you could actually use a DirectCast instead of ctype. You migh
want to to place a MsgBox(ex.Messa ge, MsgBoxStyle.Inf ormation) in
the catch clause)....
-tom

Chuck Gantz ha scritto:
I'm using vb2005.

I wrote a simple app to view and print all the fonts on my pc.To see how
the
printout will look without wasting lots of paper, I use
PrintPreviewDia log.

The first time I run PrintPreviewDia log, it correctly shows five pages of
printout. If I run it a second time, it only shows three pages, with the
original second page printing over the original first page.
If I run it a third time, only one page shows up, with all the fonts
being
printed on that page.

Can anyone see what's wrong. Thanks.
p.s., I'm not sure why when I copy my code all my formatting dissapeared.

'First class
Imports System.Drawing. Printing
Public Class FontDocument
Inherits printdocument
Private m_fontFamilies( ) As FontFamily
Private m_pageNumber As Int32
Private m_offset As Int32
Public Property FontFamilies() As FontFamily()
Get
Return m_fontFamilies
End Get
Set(ByVal value As FontFamily())
m_fontFamilies = value
End Set
End Property
Public Property PageNumber() As Int32
Get
Return m_pageNumber
End Get
Set(ByVal value As Int32)
m_pageNumber = value
End Set
End Property
Public Property Offset() As Int32
Get
Return m_offset
End Get
Set(ByVal value As Int32)
m_offset = value
End Set
End Property
Public Sub FontDocument(By Val fontFamilies() As FontFamily)
Me.m_fontFamili es = fontFamilies
End Sub
End Class

'Second class
Dim PrintDocument1 As FontDocument
Private Sub FontPrinter_Loa d(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
PrintDocument1 = New FontDocument
PrintDocument1. FontFamilies = FontFamily.Fami lies
nudFontSize.Val ue = 10
LoadFontsRichTe xtBox()
End Sub
Private Sub PrintPreviewToo lStripMenuItem_ Click(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
PrintPreviewToo lStripMenuItem. Click
AddHandler PrintDocument1. PrintPage, AddressOf PrintDocument1_ PrintPage
Dim PrintPreviewDia log1 As PrintPreviewDia log = New
System.Windows. Forms.PrintPrev iewDialog
PrintPreviewDia log1.Document = PrintDocument1
PrintDocument1. PageNumber = 0
PrintDocument1. Offset = 0
PrintPreviewDia log1.ShowDialog ()
End Sub
Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object, ByVal
ev
As System.Drawing. Printing.PrintP ageEventArgs)
Dim fnt As Font
Dim linesPerPage As Integer = 0
Dim yPos As Integer = ev.MarginBounds .Top
Dim count As Integer = 0
Dim leftMargin As Integer = ev.MarginBounds .Left
Dim topMargin As Integer = ev.MarginBounds .Top
Dim line As String = Nothing
Dim fntFamily As FontFamily
If sender Is Nothing OrElse ev Is Nothing Then
Return
End If
Dim fntDoc As FontDocument = CType(sender, FontDocument)
fntDoc.PageNumb er += 1
While yPos < ev.MarginBounds .Bottom And fntDoc.Offset <
fntDoc.FontFami lies.Length
fntFamily = fntDoc.FontFami lies(fntDoc.Off set)
Try
fnt = New Font(fntFamily, nudFontSize.Val ue, FontStyle.Regul ar)
ev.Graphics.Dra wString(fntFami ly.Name, fnt, Brushes.Black, 150, yPos)
yPos += fnt.Height

If yPos > ev.MarginBounds .Bottom Then
ev.HasMorePages = True
Return
Else
ev.HasMorePages = False
End If
Catch ex As Exception
Finally
fntDoc.Offset += 1
End Try
End While
ev.HasMorePages = False
End Sub


Mar 22 '06 #4
You're right. I moved the line AddHandler PrintDocument1. PrintPage,
AddressOf PrintDocument1_ PrintPage from the menu item handler to the form
load handler so that PrintDocument1_ PrintPage is only added once. That took
care of the problem.

I always thought it didn't matter how many times a handler was added. I
guess I was wrong.

Thanks

Chuck

<to************ **@uniroma1.it> wrote in message
news:11******** **************@ v46g2000cwv.goo glegroups.com.. .
Yes it's actually uncomfortable to read, but gets better in the editor
:) I have good new. I think I located your problem. You are attacching
multiple handlers ...

Replace this part:

'Second class
Dim PrintDocument1 As FontDocument
Private Sub FontPrinter_Loa d(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
PrintDocument1 = New FontDocument
AddHandler PrintDocument1. PrintPage, AddressOf
PrintDocument1_ PrintPage
PrintDocument1. FontFamilies = FontFamily.Fami lies
nudFontSize.Val ue = 10
LoadFontsRichTe xtBox()
End Sub

Private Sub PrintPreviewToo lStripMenuItem_ Click(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles Button1.Click '
PrintPreviewToo lStripMenuItem. Click
Dim PrintPreviewDia log1 As PrintPreviewDia log = New
System.Windows. Forms.PrintPrev iewDialog
PrintPreviewDia log1.Document = PrintDocument1
PrintDocument1. PageNumber = 0
PrintDocument1. Offset = 0
PrintPreviewDia log1.ShowDialog ()
End Sub

Dim nudFontSize As Single

'nudFontSize.Va lue

Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object,
ByVal ev As System.Drawing. Printing.PrintP ageEventArgs)

Dim fnt As Font
Dim linesPerPage As Integer = 0
Dim yPos As Integer = ev.MarginBounds .Top
Dim count As Integer = 0
Dim leftMargin As Integer = ev.MarginBounds .Left
Dim topMargin As Integer = ev.MarginBounds .Top
Dim line As String = Nothing
Dim fntFamily As FontFamily
Dim fntDoc As FontDocument = DirectCast(send er, FontDocument)
fntDoc.PageNumb er += 1

If fntDoc.FontFami lies.Length = 0 Then ev.Cancel = True

While yPos < ev.MarginBounds .Bottom AndAlso fntDoc.Offset <
fntDoc.FontFami lies.Length - 1

fntFamily = fntDoc.FontFami lies(fntDoc.Off set)
Try
fnt = New Font(fntFamily, nudFontSize.Val ue,
FontStyle.Regul ar)
Catch ex As Exception
'MsgBox(ex.Mess age) I see :)
End Try

ev.Graphics.Dra wString(fntFami ly.Name.Substri ng(0, 2), fnt,
Brushes.Black, 150, yPos)
If yPos > ev.MarginBounds .Bottom Then
ev.HasMorePages = True
Exit Sub
Else
ev.HasMorePages = False
End If
yPos += fnt.Height
fntDoc.Offset += 1

End While
ev.HasMorePages = False

End Sub


Chuck Gantz ha scritto:
Hi Tom,

Thanks for the reply.

The lines
yPos = ev.MarginBounds .Top
fntDoc.Offset = 0
fntDoc.PageNumb er = 0

actually are in the program. (It would be nice if the formatting would
have
copied over so that my code could be read a little easier). The offset
and
PageNumber variables can't be set in PrintDocument1_ PrintPage since they
change for each line of text and page.

Also, I don't use a messageBox in the catch clause because the code
doesn't
reach there for an actual error. Some font families don't have a regular
font style. When that happens the line
fnt = New Font(fntFamily, nudFontSize.Val ue, FontStyle.Regul ar)

throws an exception. The catch clause keeps the program from ending
because
of that exception.

Chuck

<to************ **@uniroma1.it> wrote in message
news:11******** *************@j 33g2000cwa.goog legroups.com...
> Hi Chuck. At first sight, it would seem a good idea to add
>
> yPos = ev.MarginBounds .Top
> fntDoc.Offset = 0
> fntDoc.PageNumb er = 0
>
> [and any other var needing reset]
>
> after
>
> Dim fntDoc As FontDocument = CType(sender, FontDocument)
>
> (where you could actually use a DirectCast instead of ctype. You migh
> want to to place a MsgBox(ex.Messa ge, MsgBoxStyle.Inf ormation) in
> the catch clause)....
>
>
> -tom
>
> Chuck Gantz ha scritto:
>
>> I'm using vb2005.
>>
>> I wrote a simple app to view and print all the fonts on my pc.To see
>> how
>> the
>> printout will look without wasting lots of paper, I use
>> PrintPreviewDia log.
>>
>> The first time I run PrintPreviewDia log, it correctly shows five pages
>> of
>> printout. If I run it a second time, it only shows three pages, with
>> the
>> original second page printing over the original first page.
>> If I run it a third time, only one page shows up, with all the fonts
>> being
>> printed on that page.
>>
>> Can anyone see what's wrong. Thanks.
>> p.s., I'm not sure why when I copy my code all my formatting
>> dissapeared.
>>
>> 'First class
>> Imports System.Drawing. Printing
>> Public Class FontDocument
>> Inherits printdocument
>> Private m_fontFamilies( ) As FontFamily
>> Private m_pageNumber As Int32
>> Private m_offset As Int32
>> Public Property FontFamilies() As FontFamily()
>> Get
>> Return m_fontFamilies
>> End Get
>> Set(ByVal value As FontFamily())
>> m_fontFamilies = value
>> End Set
>> End Property
>> Public Property PageNumber() As Int32
>> Get
>> Return m_pageNumber
>> End Get
>> Set(ByVal value As Int32)
>> m_pageNumber = value
>> End Set
>> End Property
>> Public Property Offset() As Int32
>> Get
>> Return m_offset
>> End Get
>> Set(ByVal value As Int32)
>> m_offset = value
>> End Set
>> End Property
>> Public Sub FontDocument(By Val fontFamilies() As FontFamily)
>> Me.m_fontFamili es = fontFamilies
>> End Sub
>> End Class
>>
>> 'Second class
>> Dim PrintDocument1 As FontDocument
>> Private Sub FontPrinter_Loa d(ByVal sender As System.Object, ByVal e As
>> System.EventArg s) Handles MyBase.Load
>> PrintDocument1 = New FontDocument
>> PrintDocument1. FontFamilies = FontFamily.Fami lies
>> nudFontSize.Val ue = 10
>> LoadFontsRichTe xtBox()
>> End Sub
>> Private Sub PrintPreviewToo lStripMenuItem_ Click(ByVal sender As
>> System.Object, ByVal e As System.EventArg s) Handles
>> PrintPreviewToo lStripMenuItem. Click
>> AddHandler PrintDocument1. PrintPage, AddressOf
>> PrintDocument1_ PrintPage
>> Dim PrintPreviewDia log1 As PrintPreviewDia log = New
>> System.Windows. Forms.PrintPrev iewDialog
>> PrintPreviewDia log1.Document = PrintDocument1
>> PrintDocument1. PageNumber = 0
>> PrintDocument1. Offset = 0
>> PrintPreviewDia log1.ShowDialog ()
>> End Sub
>> Private Sub PrintDocument1_ PrintPage(ByVal sender As System.Object,
>> ByVal
>> ev
>> As System.Drawing. Printing.PrintP ageEventArgs)
>> Dim fnt As Font
>> Dim linesPerPage As Integer = 0
>> Dim yPos As Integer = ev.MarginBounds .Top
>> Dim count As Integer = 0
>> Dim leftMargin As Integer = ev.MarginBounds .Left
>> Dim topMargin As Integer = ev.MarginBounds .Top
>> Dim line As String = Nothing
>> Dim fntFamily As FontFamily
>> If sender Is Nothing OrElse ev Is Nothing Then
>> Return
>> End If
>> Dim fntDoc As FontDocument = CType(sender, FontDocument)
>> fntDoc.PageNumb er += 1
>> While yPos < ev.MarginBounds .Bottom And fntDoc.Offset <
>> fntDoc.FontFami lies.Length
>> fntFamily = fntDoc.FontFami lies(fntDoc.Off set)
>> Try
>> fnt = New Font(fntFamily, nudFontSize.Val ue, FontStyle.Regul ar)
>> ev.Graphics.Dra wString(fntFami ly.Name, fnt, Brushes.Black, 150, yPos)
>> yPos += fnt.Height
>>
>> If yPos > ev.MarginBounds .Bottom Then
>> ev.HasMorePages = True
>> Return
>> Else
>> ev.HasMorePages = False
>> End If
>> Catch ex As Exception
>> Finally
>> fntDoc.Offset += 1
>> End Try
>> End While
>> ev.HasMorePages = False
>> End Sub
>

Mar 22 '06 #5
ah, you surely have already adjusted it, but just in case...

fntFamily.Name. Substring(0, 2) should be in fntFamily.Name and
Handles Button1.Click should be (in your code)
PrintPreviewToo lStripMenuItem. Click
Dim nudFontSize As Single, 'nudFontSize.Va lue should be removed

I just forget to remove these part I added to play with your code.

[actually I would also simplify it a little bit, and I will try to dig
more on the interesting question of the "unsupporte d" Regular style. If
the try catch could be replaced with a "if then" it would be much
better, as I can see the try catch is slowing down the procedure...let
me know if you find out a way to detect that]

Mar 22 '06 #6

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

Similar topics

1
2025
by: LARB | last post by:
Good morning, I have a print routine where I use a "printpreview dialog' control. The text is perfect BUT when I then print the job all the text is completely crazy, a bit like "wingdings".
1
2020
by: Randy | last post by:
Hello, I'm trying to print a simple string using the PrintPreviewDialog. I get the string to show up in the PrintPreview dialog, but when I click the Printer icon, it just prints a blank page. There's something I'm doing wrong. Can someone give me some code to print a simple string in the PrintPreview dialog box? Thanks
11
2368
by: Adam Right | last post by:
Hi, I am using .Net Framework 2.0 final, and i use .Net printing library to print a document. I use printPreview dialog to print the document but after preview was shown, when i press the "print" button, i cannot print the document although there is some words on the preview. So, is there a bug in the preview? Thanks...
9
3809
by: Adam Right | last post by:
Hi, I am using .Net Framework 2.0 final, and i use .Net printing library to print a document. I use printPreview dialog to print the document but after preview was shown, when i press the "print" button, i cannot print the document although there is some words on the preview. So, is there a bug in the preview? Thanks...
5
1608
by: Arno R | last post by:
Hi all, I am using the DetectIdleTime code from MS to shut down an app when not in use for a certain time. http://support.microsoft.com/?kbid=210297 I use a hidden form FrmDetectIdeTime with a timer event running the code. But with some reports after having a printpreview on screen the form gets focus? When I use code from a menubar like DoCmd.PrintOut , , , , 2, False DoCmd.Close the form gets printed (only a tiny label...
0
1005
by: james | last post by:
While trying to help another programmer on MSDN's Visual Basic 2005 Express Edition forum, he (and I ) ran into a strange problem with the PrintPreview Control in VB2005. If you load a document ( text file in this case) that has more than 12 pages ( I tried with a 50 page document too), instead of being able to see all 12+ pages in the Preview Window, all you see are Blank Pages!! But, preview a document with less than that, it will show...
0
1927
by: Joxie | last post by:
Hi, All! Recently I'm using ultrawebgrid for my projects... While I try Ultragrid (for windows application) I could call printpreview as ultragrid function, but while I'm using Ultrawebgrid (for asp.net/web application) I can't find the printpreview... So, the question is: Is there a way for me to use printpreview for Ultrawebgrid (just like when I'm using UltraGrid)? Note: 1. UltraGrid & UltraWebGrid are components from Infragistics.
6
1483
by: Stuart Nathan | last post by:
Can someone tell me how to remove a previously loaded PrintDocument in a PrintPreview control, so that I can display a nedw one?
2
2110
by: eBob.com | last post by:
I have a print application modeled on a program which I found via this newsgroup. (I still have comments in German in it!) The model uses ExtendedPrintPreviewDialog but I don't seem to have that so I am using PrintPreviewDialog. It prints fine. But the PrintPreview dialog shows only one blank page. Before I resort to posting code, is there some simple and/or common mistake I could have made which would explain why PrintPreview shows...
0
1116
by: vench | last post by:
Hi! I have a vb.net project that uses mozilla activeX control, there is no problem in navigating or loading the url in the control, the problem that I have encountered is when printpreview using the code axWebbrowser1.exeWB(MOZILLACONTROLLib.OLECMDID.OLECMDID_PRINTPREVIEW, MOZILLACONTROLLib.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER) I get an innerException error something on reflection... I don't know how to fix it... thanks....
0
9670
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10430
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
10211
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
10000
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
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5436
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.