I have a problem with printing in vb.net when using the printdocument and printpreview controls. When I use printpreview.showdialog the page(s) show up fine but when I click on the print icon the resulted page has dropped down and to the right.
I read of a similar problem where someone suggested that the printpreview control was setting up margins but when I tried to just use printdocument.print it still drops down and to the right.
Here is the code I use:
Any Ideas?Code:Private Sub prdDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prdDocument.PrintPage Dim HeadingFont As New Font(FontFamily.GenericSansSerif, 30, FontStyle.Bold, GraphicsUnit.Pixel) Dim BoldFont As New Font(FontFamily.GenericSansSerif, 20, FontStyle.Bold, GraphicsUnit.Pixel) Dim NormalFont As New Font(FontFamily.GenericSansSerif, 20, FontStyle.Regular, GraphicsUnit.Pixel) Dim MyBrush As New SolidBrush(Color.Black) Dim MyPen As New Pen(Color.Black) Dim Centerformat As New StringFormat Dim Items As New ArrayList Dim MyDivision As CDivision Dim MyTeam As CTeam Dim MyPlayer As CPlayer Dim MyMatch As CMatch Dim X As Integer Dim Y As Integer Dim Count1 As Integer Dim Count2 As Integer Dim Count3 As Integer Dim Count4 As Integer Dim PrintString As String Centerformat.Alignment = StringAlignment.Center MyDivision = clsPrintObject e.Graphics.DrawString("Draw - " & MyDivision.Name, HeadingFont, MyBrush, (e.PageBounds.Width / 2), 75, Centerformat) X = 50 Y = 150 Count3 = Y For Count1 = 1 To clsControl.GetNumberRounds(MyDivision.ID) Items.Clear() clsControl.GetResults(MyDivision.ID, Count1, Items) e.Graphics.DrawString("Round " & Count1 & " - " & Format(Items.Item(0).MatchTime, "h:mm tt"), BoldFont, MyBrush, X, Y) Y = Y + 35 Count2 = 0 For Each MyMatch In Items If MyMatch.Team1 <> 0 Or MyMatch.Team2 <> 0 Then If MyMatch.Team1 <> 0 Then clsControl.GetTeam(MyMatch.Team1, MyTeam) Else MyTeam = New CTeam MyTeam.Name = "Bye" End If PrintString = "Field " & MyMatch.Field & ":" & vbTab & MyTeam.Name If MyMatch.Team2 <> 0 Then clsControl.GetTeam(MyMatch.Team2, MyTeam) Else MyTeam = New CTeam MyTeam.Name = "Bye" End If PrintString = PrintString & " vs " & MyTeam.Name e.Graphics.DrawString(PrintString, NormalFont, MyBrush, X, Y) Y = Y + 35 Count2 = Count2 + 1 End If Next If Count1 Mod 3 = 0 Then X = 50 Y = Count3 + 160 Count3 = Y Else X = X + 380 Y = Y - (35 * Count2) - 35 End If Next If clsPrintCollection.IndexOf(MyDivision) <> clsPrintCollection.Count - 1 Then clsPrintObject = clsPrintCollection.Item(clsPrintCollection.IndexOf(MyDivision) + 1) While clsControl.GetNumberRounds(clsPrintObject.ID) = 0 And clsPrintCollection.IndexOf(clsPrintObject) <> clsPrintCollection.Count - 1 clsPrintObject = clsPrintCollection.Item(clsPrintCollection.IndexOf(clsPrintObject) + 1) End While If clsControl.GetNumberRounds(clsPrintObject.ID) > 0 Then e.HasMorePages = True End If End If End Sub




Reply With Quote