EDN Admin
Well-known member
Private Sub Print_Load(sender As Object, e As System.EventArgs) Handles Me.Load
http://msdn.microsoft.com/en-us/library/office/aa140283(v=office.10).aspx#rtfspec_18
Me.Size = New Size(800, 420)
Me.PrintDialog1.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"
Dim margins As New Printing.Margins(30, 10, 20, 20)
Me.PrintDocument1.DefaultPageSettings.Margins = margins
Dim Header As String = "{rtf1ansideff0"
Dim tabs As String = "tx320tx720tx1400tx2500tx4700"
Dim F As New List(Of String)
F.Add("{f0 Courier new;}")
F.Add("{f1 Courier regular;}")
F.Add("{f2 Times New Roman;}")
F.Add("{f3 arial;}")
F.Add("{f4 freestyle script;}")
F.Add("{f5 Tahoma;}")
F.Add("{f6 Algerian;}")
F.Add("{f7 Verdana;}")
Dim FontTable As String = "{fonttbl"
For Each s As String In F
FontTable &= s
Next
FontTable &= "}"
Dim C As New Dictionary(Of String, String)
C.Add("maroon", "red128green0blue0;") 1
C.Add("green", "red0green128blue0;") 2
C.Add("darkgreen", "red0green100blue0;") 3
C.Add("fuchsia", "red255green0blue255;") 4
C.Add("indigo", "red75green0blue130;") 5
C.Add("violet", "red138green43blue226;") 6
C.Add("blue", "red0green0blue255;") 7
C.Add("red", "red255green0blue0;") 8
C.Add("yellow", "red255green255blue0;") 9
C.Add("black", "red0green0blue0;") 10
C.Add("white", "red255green255blue255;") 11
Dim ColTable As String = "{colortbl;"
For Each s As String In C.Values
ColTable &= s
Next
ColTable &= "}"
Dim colt As New StringBuilder
colt.Clear()
colt.Append(Header & tabs & FontTable & ColTable)
colt.Append("tabtabfs36f6cf1 Current Task Listtabplainbfs32 " & Format(Now, "dd MMM yyyy") & "lineline")
----------------------------------
this is the block I need to ensure
that it is not split by page breaks
For Each r As DataGridViewRow In TaskList.DGV.Rows
With r
colt.Append("b0f1fs20tabcf3")
colt.Append(.Cells("TaskName").Value.ToString)
colt.Append("b0lineplainf2fs24tabcf5")
If .Cells("Enabled").Value.ToString = "True" Then
colt.Append("Enabled")
Else
colt.Append("Disabled")
End If
colt.Append("f2tabcf8")
If .Cells("Active").Value.ToString = "True" Then
colt.Append("Active")
Else
colt.Append("InActive")
End If
colt.Append("plainf2tab")
Dim sd1 As String = "cf1 Last: cf7 No Date Found"
Try
sd1 = "cf1 Last: cf7 " & Format(CDate(.Cells("Last Run").Value.ToString), "dd MMM yyyy HH:mm")
Catch ex As Exception
End Try
colt.Append(sd1)
colt.Append("f2tab")
Dim sd2 As String = "cf1 Next: cf7 No Date Found"
Try
sd2 = "cf1 Next: cf7 " & Format(CDate(.Cells("Next Due").Value.ToString), "dd MMM yyyy HH:mm")
Catch ex As Exception
End Try
colt.Append(sd2)
Dim m As String = .Cells("Missed").Value.ToString
If Not m = Nothing Then m = "plaincf1 Missed: cf7b " & m & "plain"
colt.Append("tabcf1fs20b ")
colt.Append(m)
colt.Append("lineb0cf10 ")
Dim t() As String = Split(Replace(.Cells("Actions").Value.ToString, "", "\"), vbCrLf)
For ii As Integer = 0 To t.Count - 1
If ii = t.Count - 1 Then
colt.Append("tab " & t(ii))
Else
colt.Append("tab " & t(ii) & "line")
End If
Next
colt.Append("line")
End With
Next
----------------------------------
RTB.Rtf = colt.ToString
End Sub
Hi
My first attemp to use RTF. This Sub cycles through a DGV and collects the info for printing. The info makes up groups of data for each of the DGV rows and puts it onto a RichTextBox, from where the printing takes place.
I have tried, with loads of searching to find a way to ensure that a block is not split over pages, but cant find a way to do it. (not that there isnt enough information to help, but that there is so much that I cant find the answer).
The Sub above is the entire data collection/sorting routine, and it works fine and I get the printer output required except that the blocks do get split over pages. What I have been looking for is something (my own words) a keeptogether and keeptogether0 type set of tags to switch on/off a block of text. The blocks of text vary in the number of lines each contains.
From the amount of RTF info I have found, I feel there is a straightforward way to achieve this, if only I could find it!
Any suggestions welcomed?
Regards Les, Livingston, Scotland
View the full article
http://msdn.microsoft.com/en-us/library/office/aa140283(v=office.10).aspx#rtfspec_18
Me.Size = New Size(800, 420)
Me.PrintDialog1.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"
Dim margins As New Printing.Margins(30, 10, 20, 20)
Me.PrintDocument1.DefaultPageSettings.Margins = margins
Dim Header As String = "{rtf1ansideff0"
Dim tabs As String = "tx320tx720tx1400tx2500tx4700"
Dim F As New List(Of String)
F.Add("{f0 Courier new;}")
F.Add("{f1 Courier regular;}")
F.Add("{f2 Times New Roman;}")
F.Add("{f3 arial;}")
F.Add("{f4 freestyle script;}")
F.Add("{f5 Tahoma;}")
F.Add("{f6 Algerian;}")
F.Add("{f7 Verdana;}")
Dim FontTable As String = "{fonttbl"
For Each s As String In F
FontTable &= s
Next
FontTable &= "}"
Dim C As New Dictionary(Of String, String)
C.Add("maroon", "red128green0blue0;") 1
C.Add("green", "red0green128blue0;") 2
C.Add("darkgreen", "red0green100blue0;") 3
C.Add("fuchsia", "red255green0blue255;") 4
C.Add("indigo", "red75green0blue130;") 5
C.Add("violet", "red138green43blue226;") 6
C.Add("blue", "red0green0blue255;") 7
C.Add("red", "red255green0blue0;") 8
C.Add("yellow", "red255green255blue0;") 9
C.Add("black", "red0green0blue0;") 10
C.Add("white", "red255green255blue255;") 11
Dim ColTable As String = "{colortbl;"
For Each s As String In C.Values
ColTable &= s
Next
ColTable &= "}"
Dim colt As New StringBuilder
colt.Clear()
colt.Append(Header & tabs & FontTable & ColTable)
colt.Append("tabtabfs36f6cf1 Current Task Listtabplainbfs32 " & Format(Now, "dd MMM yyyy") & "lineline")
----------------------------------
this is the block I need to ensure
that it is not split by page breaks
For Each r As DataGridViewRow In TaskList.DGV.Rows
With r
colt.Append("b0f1fs20tabcf3")
colt.Append(.Cells("TaskName").Value.ToString)
colt.Append("b0lineplainf2fs24tabcf5")
If .Cells("Enabled").Value.ToString = "True" Then
colt.Append("Enabled")
Else
colt.Append("Disabled")
End If
colt.Append("f2tabcf8")
If .Cells("Active").Value.ToString = "True" Then
colt.Append("Active")
Else
colt.Append("InActive")
End If
colt.Append("plainf2tab")
Dim sd1 As String = "cf1 Last: cf7 No Date Found"
Try
sd1 = "cf1 Last: cf7 " & Format(CDate(.Cells("Last Run").Value.ToString), "dd MMM yyyy HH:mm")
Catch ex As Exception
End Try
colt.Append(sd1)
colt.Append("f2tab")
Dim sd2 As String = "cf1 Next: cf7 No Date Found"
Try
sd2 = "cf1 Next: cf7 " & Format(CDate(.Cells("Next Due").Value.ToString), "dd MMM yyyy HH:mm")
Catch ex As Exception
End Try
colt.Append(sd2)
Dim m As String = .Cells("Missed").Value.ToString
If Not m = Nothing Then m = "plaincf1 Missed: cf7b " & m & "plain"
colt.Append("tabcf1fs20b ")
colt.Append(m)
colt.Append("lineb0cf10 ")
Dim t() As String = Split(Replace(.Cells("Actions").Value.ToString, "", "\"), vbCrLf)
For ii As Integer = 0 To t.Count - 1
If ii = t.Count - 1 Then
colt.Append("tab " & t(ii))
Else
colt.Append("tab " & t(ii) & "line")
End If
Next
colt.Append("line")
End With
Next
----------------------------------
RTB.Rtf = colt.ToString
End Sub
Hi
My first attemp to use RTF. This Sub cycles through a DGV and collects the info for printing. The info makes up groups of data for each of the DGV rows and puts it onto a RichTextBox, from where the printing takes place.
I have tried, with loads of searching to find a way to ensure that a block is not split over pages, but cant find a way to do it. (not that there isnt enough information to help, but that there is so much that I cant find the answer).
The Sub above is the entire data collection/sorting routine, and it works fine and I get the printer output required except that the blocks do get split over pages. What I have been looking for is something (my own words) a keeptogether and keeptogether0 type set of tags to switch on/off a block of text. The blocks of text vary in the number of lines each contains.
From the amount of RTF info I have found, I feel there is a straightforward way to achieve this, if only I could find it!
Any suggestions welcomed?
Regards Les, Livingston, Scotland
View the full article