Nov 21st, 2003, 06:45 AM
#1
Thread Starter
Frenzied Member
Print MSFlexgrid Aligned [RESOLVED]
Im having a spot of bother printing my flexgrid.
I use the following code (copied from here somewhere)
VB Code:
Dim strRowText As String
With ResGrid
For i = 0 To .Rows - 1
strRowText = ""
strRowText = strRowText & .TextMatrix(i, 0) & vbTab & vbTab
For j = 1 To .Cols - 1
strRowText = strRowText & .TextMatrix(i, j) & vbTab
Next j
Printer.Print vbTab & vbTab & strRowText
Next i
End With
This prints out a nice grid until one of the row headers is too long.
How can I align this properly?
Attached Images
Last edited by agmorgan; Nov 28th, 2003 at 04:53 AM .
Nov 21st, 2003, 07:31 AM
#2
for that you need to either print each cell individually (using the printers CurrentX and CurrentY to specify the current position), or make the text in the left hand column the same printed width by adding spaces (which I'm afraid isn't accurate - as all character sizes vary)
Nov 22nd, 2003, 07:06 PM
#3
Addicted Member
Printer.CurrentX = 115 - Printer.TextWidth("1.114,55")
Printer.CurrentY = 50
Printer.Print "1.114,55"
prints 1.114,55 from right to left starting at point 115
Nov 27th, 2003, 09:01 AM
#4
Thread Starter
Frenzied Member
CurrentX doesn't seem to work because I want to set it
differently for each word on the same line.
I was under the impression that Printer.Print couldn't be
used to print part of a line at a time
The answer appears to be in this post.
http://www.vbforums.com/showthread.p...threadid=61145
Using commas for separate print zones or Tab(n) to separate.
I'm having a mind block on how to implement it though!
Nov 27th, 2003, 09:33 AM
#5
Thread Starter
Frenzied Member
I decided on a workaround that was simpler to implement.
I put in an If statement to see if the header was longer than a Tab.
VB Code:
Dim strRowText As String
With ResGrid
For i = 0 To .Rows - 1
strRowText = ""
'Row header. ie device name
If TextWidth(ResGrid.TextMatrix(i, 0)) < 600 Then
strRowText = strRowText & .TextMatrix(i, 0) & vbTab & vbTab
Else
strRowText = strRowText & .TextMatrix(i, 0) & vbTab
End If
'Numbers in table
For j = 1 To .Cols - 1
strRowText = strRowText & .TextMatrix(i, j) & vbTab
Next j
Printer.Print vbTab & vbTab & strRowText
Next i
End With
Im fairly certain that it will work in this application as the length of the header is restricted elsewhere.
Not as robust as I would like though.
Nov 27th, 2003, 02:10 PM
#6
Addicted Member
Sub CabeçalhoMapa(Grelha As MSFlexGrid)
Dim Abcissa As Integer
Abcissa = 15
Printer.ScaleMode = vbMillimeters
Printer.Line (1, 1 + Abcissa)-(Printer.ScaleWidth, 7 + Abcissa), vbBlue, BF
With Printer
.FontSize = 14
.FontBold = True
.ForeColor = vbBlue
.CurrentX = 1
.CurrentY = 1
Printer.Print "CDCA - NATAÇÃO"
.ForeColor = vbWhite
.FontSize = 10
.CurrentX = 2
.CurrentY = 1 + Abcissa
SetBkMode Printer.hdc, TRANSPARENT
Printer.Print Grelha.TextMatrix(0, 0)
.CurrentX = 70
.CurrentY = 1 + Abcissa
SetBkMode Printer.hdc, TRANSPARENT
Printer.Print Grelha.TextMatrix(0, 1)
.CurrentX = 115 - Printer.TextWidth(Grelha.TextMatrix(0, 2))
.CurrentY = 1 + Abcissa
SetBkMode Printer.hdc, TRANSPARENT
Printer.Print Grelha.TextMatrix(0, 2)
.CurrentX = 135 - Printer.TextWidth(Grelha.TextMatrix(0, 3))
.CurrentY = 1 + Abcissa
SetBkMode Printer.hdc, TRANSPARENT
Printer.Print Grelha.TextMatrix(0, 3)
.CurrentX = 155 - Printer.TextWidth(Grelha.TextMatrix(0, 4))
.CurrentY = 1 + Abcissa
SetBkMode Printer.hdc, TRANSPARENT
Printer.Print Grelha.TextMatrix(0, 4)
.CurrentX = 175 - Printer.TextWidth(Grelha.TextMatrix(0, 5))
.CurrentY = 1 + Abcissa
SetBkMode Printer.hdc, TRANSPARENT
Printer.Print Grelha.TextMatrix(0, 5)
.CurrentX = 195 - Printer.TextWidth(Grelha.TextMatrix(0, 6))
.CurrentY = 1 + Abcissa
SetBkMode Printer.hdc, TRANSPARENT
Printer.Print Grelha.TextMatrix(0, 6)
End With
End Sub
As you can see, CurrentX can be assigned more then once for a single line.
Best regards
Nov 28th, 2003, 04:52 AM
#7
Thread Starter
Frenzied Member
Suddenly it all becomes clear!
Thanks!
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width