|
-
Jan 29th, 2013, 05:11 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Center Title when printing
I am printing a listview and in the preview it looks fine. But when it actually prints this is what i get. Attachment 95807
This is the code associated in the print code.
Code:
If title <> "" Then
Dim tFont As New Drawing.Font(lv.Font.FontFamily, CType(lv.Font.Size * 1.5, Single), FontStyle.Bold)
Dim r As New Rectangle(startX + CInt(columnSum / 2) - CInt(e.Graphics.MeasureString(title, tFont).Width / 2), startY + 2, CInt(columnSum / 2), tFont.Height)
e.Graphics.DrawString(title, tFont, Brushes.Black, r)
startY += tFont.Height + 2
End If
Im not sure where i fix it so that the title is centered.
-
Jan 29th, 2013, 05:43 PM
#2
Re: Center Title when printing
Set up a breakpoint where you declare the rectangle and I'm sure you'll find that the x position is off. You'll have to adjust your equation based on what you get when you set up the breakpoint.
-
Jan 29th, 2013, 06:49 PM
#3
Thread Starter
Fanatic Member
Re: Center Title when printing
Whats even weirder is that every copy i print the title moves more to the right..... I don't understand.
-
Jan 29th, 2013, 07:24 PM
#4
Re: Center Title when printing
 Originally Posted by dday9
Set up a breakpoint where you declare the rectangle and I'm sure you'll find that the x position is off. You'll have to adjust your equation based on what you get when you set up the breakpoint.
If this was true (and it isn't) then it should show up in the Print Preview as well. The mystery is how the print position can differ so wildly between preview and actual print and at the moment I've gotta say I have absolutely no idea how that's possible especially since StartX is essentially a constant used for all the subsequent lines too.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 29th, 2013, 07:55 PM
#5
Re: Center Title when printing
Ok I've run this through a few times and I'm getting some very weird things happening on subsequent copies of the same document which don't match the OP's experience at all even without running a title so something is broken somewhere but I can't for the life of me see what at the moment. I just don't understand how you can run the same code with all the values essentially the same (most of them declared in the Sub, after all!) and get totally different results on preview, print, and print 2. I may not sleep tonight!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 30th, 2013, 12:15 AM
#6
Thread Starter
Fanatic Member
Re: Center Title when printing
Thats exacly my issue..... I am with you on not being able to sleep. Driving me nuts.
-
Jan 30th, 2013, 03:41 PM
#7
Re: Center Title when printing
Got it. The column width wasn't being reset so on each pass was increasing, to the point that it eventually was off the page. So if, for example, for the preview column the value was 315, for the actual print it was 630, for the next print it was 915 and so on. As my centring calculation used this value it was skewing further and further off course. The solution ... in listviewprinter.vb ....
vb.net Code:
Private Sub pd_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles pd.BeginPrint
''this removes the printed page margins
pd.OriginAtMargins = True
pd.DefaultPageSettings.Margins = New Drawing.Printing.Margins(location.X, 0, location.Y, 0)
pages = New Dictionary(Of Integer, pageDetails)
Dim maxWidth As Integer = CInt(pd.DefaultPageSettings.PrintableArea.Width) - 40
Dim maxHeight As Integer = CInt(pd.DefaultPageSettings.PrintableArea.Height) - 40
Dim pageCounter As Integer = 0
pages.Add(pageCounter, New pageDetails With {.headerIndices = New List(Of Integer)})
Dim columnCounter As Integer = 0
columnSum = 0 'ADD THIS LINE TO RESET VALUE BEFORE NEW CALCULATION
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 31st, 2013, 12:15 AM
#8
Thread Starter
Fanatic Member
Re: Center Title when printing
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
|