|
-
May 17th, 2012, 01:25 AM
#1
printing many columns
i have a printing code which prints a listview however if a listview contains many columns it cuts the columns and will not print all the columns needed.
what will i do???
please help me.... i badly needed experts helps.....
thanks a lot...
*codeadik
-
May 17th, 2012, 01:55 AM
#2
Re: printing many columns
-
May 17th, 2012, 02:20 AM
#3
Re: printing many columns
this is the code, , im still a beginner, please help me...
Code:
Static LastIndex As Integer = 0
Static CurrentPage As Integer = 0
Dim DpiGraphics As Graphics = Me.CreateGraphics
Dim DpiX As Integer = DpiGraphics.DpiX
Dim DpiY As Integer = DpiGraphics.DpiY
DpiGraphics.Dispose()
Dim X, Y As Integer
Dim ImageWidth As Integer
Dim TextRect As Rectangle = Rectangle.Empty
Dim TextLeftPad As Single = CSng(4 * (DpiX / 96)) '4 pixel pad on the left.
Dim ColumnHeaderHeight As Single = CSng(ListView1.Font.Height + (10 * (DpiX / 96))) '5 pixel pad on the top an bottom
Dim StringFormat As New StringFormat
Dim PageNumberWidth As Single = e.Graphics.MeasureString(CStr(CurrentPage), ListView1.Font).Width
Dim rectDraw As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)
Dim strFormat As New StringFormat()
StringFormat.FormatFlags = StringFormatFlags.NoWrap
StringFormat.Trimming = StringTrimming.EllipsisCharacter
StringFormat.LineAlignment = StringAlignment.Center
CurrentPage += 1
X = CInt(e.MarginBounds.X)
Y = CInt(e.MarginBounds.Y)
For ColumnIndex As Integer = 0 To ListView1.Columns.Count - 1
TextRect.X = X
TextRect.Y = Y
TextRect.Width = ListView1.Columns(ColumnIndex).Width
TextRect.Height = ColumnHeaderHeight
e.Graphics.FillRectangle(Brushes.LightGray, TextRect)
e.Graphics.DrawRectangle(Pens.DarkGray, TextRect)
TextRect.X += TextLeftPad
TextRect.Width -= TextLeftPad
e.Graphics.DrawString(ListView1.Columns(ColumnIndex).Text, ListView1.Font, Brushes.Black, TextRect, StringFormat)
X += TextRect.Width + TextLeftPad
Next
Y += ColumnHeaderHeight
For i = LastIndex To ListView1.Items.Count - 1
With ListView1.Items(i)
'Start the x at the pages left margin.
X = CInt(e.MarginBounds.X)
If Y + .Bounds.Height > e.MarginBounds.Bottom Then
LastIndex = i - 1
e.HasMorePages = True
StringFormat.Dispose()
e.Graphics.DrawString(CStr(CurrentPage), ListView1.Font, Brushes.Black, (e.PageBounds.Width - PageNumberWidth) / 2, e.PageBounds.Bottom - ListView1.Font.Height * 2)
Exit Sub
End If
ImageWidth = 0
If ListView1.SmallImageList IsNot Nothing Then
If Not String.IsNullOrEmpty(.ImageKey) Then
e.Graphics.DrawImage(ListView1.SmallImageList.Images(.ImageKey), X, Y)
ElseIf .ImageIndex >= 0 Then
e.Graphics.DrawImage(ListView1.SmallImageList.Images(.ImageIndex), X, Y)
End If
ImageWidth = ListView1.SmallImageList.ImageSize.Width
End If
For ColumnIndex As Integer = 0 To ListView1.Columns.Count - 1
TextRect.X = X
TextRect.Y = Y
TextRect.Width = ListView1.Columns(ColumnIndex).Width
TextRect.Height = .Bounds.Height
If ListView1.GridLines Then
e.Graphics.DrawRectangle(Pens.DarkGray, TextRect)
End If
If ColumnIndex = 0 Then TextRect.X += ImageWidth
TextRect.X += TextLeftPad
TextRect.Width -= TextLeftPad
If ColumnIndex < .SubItems.Count Then
'This item has at least the same number of
'subitems as the current column index.
e.Graphics.DrawString(.SubItems(ColumnIndex).Text, ListView1.Font, Brushes.Black, TextRect, StringFormat)
End If
X += TextRect.Width + TextLeftPad
Next
Y += .Bounds.Height
End With
Next
e.Graphics.DrawString(CStr(CurrentPage), ListView1.Font, Brushes.Black, (e.PageBounds.Width - PageNumberWidth) / 2, e.PageBounds.Bottom - ListView1.Font.Height * 2)
StringFormat.Dispose()
LastIndex = 0
CurrentPage = 0
Last edited by GremlinSA; May 17th, 2012 at 04:01 AM.
Reason: added code tags
-
May 20th, 2012, 09:36 PM
#4
Re: printing many columns
Is anyone out there knows dis??? please please please... i need ur help...
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
|